urn_perun_resource_attribute_def_def_defaultShell extends ResourceAttributesModuleAbstract implements ResourceAttributesModuleImplApi { @Override public Attribute fillAttribute(PerunSessionImpl perunSession, Resource resource, AttributeDefinition attribute) throws WrongAttributeAssignmentException { Attribute atr = new Attribute(attribute); Attribute resourceAttr; try { resourceAttr = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, resource, A_R_shells); } catch (AttributeNotExistsException ex) { throw new InternalErrorException("Attribute with list of shells from resource " + resource.getId() + " could not obtained.", ex); } if (resourceAttr.getValue() == null) { return atr; } else { List<String> shells = (List<String>) resourceAttr.getValue(); if (!shells.isEmpty()) { atr.setValue(shells.get(0)); return atr; } else { return atr; } } }  @Override Attribute fillAttribute(PerunSessionImpl perunSession, Resource resource, AttributeDefinition attribute); @Override void checkAttributeSemantics(PerunSessionImpl perunSession, Resource resource, Attribute attribute); @Override List<String> getDependencies(); @Override AttributeDefinition getAttributeDefinition();  }
@SuppressWarnings("serial") @Test public void fillAttribute() throws Exception { System.out.println("fillAttribute()"); final Attribute attrToReturn = new Attribute(); final String shellName = "mujShell"; attrToReturn.setValue(new ArrayList<String>(){{add(shellName);}}); when(ps.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Resource.class), anyString())).thenReturn(attrToReturn); final Attribute result= defShellAttr.fillAttribute(ps, new Resource(), new AttributeDefinition()); assertEquals("fillAttribute spatne vyplnil value",shellName, result.getValue()); }
@Test public void fillAttributeWithEmptyValue() throws Exception { System.out.println("fillAttributeWithEmptyValue()"); final Attribute attrToReturn = new Attribute(); when(ps.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Resource.class), anyString())).thenReturn(attrToReturn); final Attribute attrResult = defShellAttr.fillAttribute(ps, new Resource(), new Attribute()); assertNull("Atribut.getValue() ma byt null", attrResult.getValue()); }
@Test public void fillAttributeWhichNotExists() throws Exception { System.out.println("fillAttributeWhichNotExists()"); when(ps.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Resource.class), anyString())).thenThrow(new AttributeNotExistsException("neexistuje")); try { defShellAttr.fillAttribute(ps, new Resource(), new AttributeDefinition()); fail(); } catch (InternalErrorException ex) { assertTrue("Mela byt vyhozena vyjimka AttributeNotExistsException", (ex.getCause() instanceof AttributeNotExistsException)); } }