urn_perun_resource_attribute_def_def_shells extends ResourceAttributesModuleAbstract implements ResourceAttributesModuleImplApi { @Override public void checkAttributeSemantics(PerunSessionImpl perunSession, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException { List<String> shells = attribute.valueAsList(); if (shells == null) { throw new WrongReferenceAttributeValueException(attribute, null, resource, null, "Attribute cannot be null."); } Facility facility = perunSession.getPerunBl().getResourcesManagerBl().getFacility(perunSession, resource); Attribute allShellsPerFacility; try { allShellsPerFacility = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, facility, A_F_shells); } catch (AttributeNotExistsException ex) { throw new InternalErrorException("Attribute with list of shells from facility " + facility.getId() +" could not obtained.",ex); } if (allShellsPerFacility.getValue() == null) { throw new WrongReferenceAttributeValueException(attribute, allShellsPerFacility, resource, null, facility, null, "Attribute with list of shells from facility cannot be null."); } if (!(allShellsPerFacility.valueAsList()).containsAll(shells)) { throw new WrongReferenceAttributeValueException(attribute, allShellsPerFacility, resource, null, facility, null, "Some shells from specified resource are not at home facility " + facility.getId()); } }  @Override Attribute fillAttribute(PerunSessionImpl perunSession, Resource resource, AttributeDefinition attribute); @Override void checkAttributeSyntax(PerunSessionImpl perunSession, Resource resource, Attribute attribute); @Override void checkAttributeSemantics(PerunSessionImpl perunSession, Resource resource, Attribute attribute); @Override List<String> getDependencies(); @Override AttributeDefinition getAttributeDefinition();  }
@Test public void testCheckAttributeSemantics() throws Exception { System.out.println("testCheckAttributeSemantics()"); Attribute attributeToCheck = new Attribute(); attributeToCheck.setValue(new ArrayList<String>() {{add("/bin/bash");}}); when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Facility.class), anyString())).thenReturn(listOfShells); classInstance.checkAttributeSemantics(session, new Resource(), attributeToCheck); }
@Test(expected= WrongReferenceAttributeValueException.class) public void testCheckAttributeSemanticsEmptyAttribute() throws Exception { System.out.println("testCheckAttributeSemanticsEmptyAttribute()"); Attribute attributeToCheck = new Attribute(); classInstance.checkAttributeSemantics(session, new Resource(), attributeToCheck); fail("Attribute without value has not thrown WrongAttributeSemanticsException."); }
@Test(expected=WrongReferenceAttributeValueException.class) public void testCheckAttributeSemanticsUnknownShell() throws Exception { System.out.println("testCheckAttributeSemanticsUnknownShell()"); Attribute attributeToCheck = new Attribute(); attributeToCheck.setValue(new ArrayList<String>() {{add("/bin/bash"); add("/hypershell");}}); when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Facility.class), anyString())).thenReturn(listOfShells); classInstance.checkAttributeSemantics(session, new Resource(), attributeToCheck); fail("Unknown shell at facility was approved"); }