package org.gcube.informationsystem.resourceregistry.instances.multicontext; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.gcube.informationsystem.resourceregistry.instances.ERManagementTest; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement; import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet; import org.gcube.resourcemanagement.model.reference.entities.resources.EService; import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; import org.junit.Test; public class AddToContextTest extends MultiContextTest { @Test public void testCreateEServiceAndRemoveFromContextRequiredFacet() throws Exception { EService eService = ERManagementTest.createEService(); @SuppressWarnings("unchecked") IsIdentifiedBy isIdentifiedBy = (IsIdentifiedBy) eService.getConsistsOf(IsIdentifiedBy.class).get(0); ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement(); consistsOfManagement.setElementType(IsIdentifiedBy.NAME); consistsOfManagement.setUUID(isIdentifiedBy.getHeader().getUUID()); try { consistsOfManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID()); throw new Exception("You should not be able to delete a mandatory ConsistsOf"); }catch (SchemaViolationException e) { // As expected }catch (Exception e) { ERManagementTest.deleteResource(eService); throw e; } SoftwareFacet softwareFacet = isIdentifiedBy.getTarget(); FacetManagement facetManagement = new FacetManagement(); facetManagement.setElementType(SoftwareFacet.NAME); facetManagement.setUUID(softwareFacet.getHeader().getUUID()); try { facetManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID()); throw new Exception("You should not be able to delete a mandatory Facet"); }catch (SchemaViolationException e) { // As expected }catch (Exception e) { ERManagementTest.deleteResource(eService); throw e; } ERManagementTest.deleteResource(eService); } }