2021-03-08 09:56:23 +01:00
|
|
|
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;
|
|
|
|
|
2021-03-09 12:58:46 +01:00
|
|
|
public class AddToContextTest extends MultiContextTest {
|
2021-03-08 09:56:23 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCreateEServiceAndRemoveFromContextRequiredFacet() throws Exception {
|
2021-03-08 17:05:56 +01:00
|
|
|
EService eService = ERManagementTest.createEService();
|
2021-03-08 09:56:23 +01:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2021-03-08 17:05:56 +01:00
|
|
|
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedBy = (IsIdentifiedBy<EService, SoftwareFacet>) eService.getConsistsOf(IsIdentifiedBy.class).get(0);
|
2021-03-08 09:56:23 +01:00
|
|
|
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) {
|
2021-03-08 17:05:56 +01:00
|
|
|
ERManagementTest.deleteResource(eService);
|
2021-03-08 09:56:23 +01:00
|
|
|
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) {
|
2021-03-08 17:05:56 +01:00
|
|
|
ERManagementTest.deleteResource(eService);
|
2021-03-08 09:56:23 +01:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
2021-03-08 17:05:56 +01:00
|
|
|
ERManagementTest.deleteResource(eService);
|
2021-03-08 09:56:23 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|