Exposing AddToContext APi refs #5701

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@134114 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-11-14 11:02:51 +00:00
parent 631e030dae
commit b40503fa33
3 changed files with 33 additions and 6 deletions

View File

@ -237,14 +237,14 @@ public class EntityManager {
@POST @POST
@Path("add/" + EntityPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}") @Path(EntityPath.ADD_PATH_PART + "/" + EntityPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
public boolean addResourceToContext(String uuid) throws ResourceNotFoundException, public boolean addResourceToContext(String uuid) throws ResourceNotFoundException,
ContextNotFoundException, ResourceRegistryException { ContextNotFoundException, ResourceRegistryException {
return entityManager.addResourceToContext(UUID.fromString(uuid)); return entityManager.addResourceToContext(UUID.fromString(uuid));
} }
@POST @POST
@Path("add/" + EntityPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}") @Path(EntityPath.ADD_PATH_PART + "/" + EntityPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}")
public boolean addFacetToContext(String uuid) throws FacetNotFoundException, public boolean addFacetToContext(String uuid) throws FacetNotFoundException,
ContextNotFoundException, ResourceRegistryException { ContextNotFoundException, ResourceRegistryException {
return entityManager.addFacetToContext(UUID.fromString(uuid)); return entityManager.addFacetToContext(UUID.fromString(uuid));

View File

@ -100,6 +100,11 @@ public class EntityManagementImplTest {
logger.debug("Created : {}", json); logger.debug("Created : {}", json);
eService = Entities.unmarshal(EService.class, json); eService = Entities.unmarshal(EService.class, json);
logger.debug("Unmarshalled {} {}", EService.NAME, eService); logger.debug("Unmarshalled {} {}", EService.NAME, eService);
boolean deleted = entityManagementImpl.deleteResource(eService.getHeader().getUUID());
Assert.assertTrue(deleted);
} }

View File

@ -43,6 +43,7 @@ import org.gcube.informationsystem.model.relation.isrelatedto.Hosts;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.ResourceNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.ResourceNotFoundException;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -154,14 +155,35 @@ public class MultiContextTest {
ScopeProvider.instance.set("/gcube/devNext/NextNext"); ScopeProvider.instance.set("/gcube/devNext/NextNext");
entityManagementImpl.addResourceToContext(hostingNode.getHeader().getUUID()); UUID uuid = hostingNode.getHeader().getUUID();
boolean addedToContext = entityManagementImpl.addResourceToContext(uuid);
Assert.assertTrue(addedToContext);
String hnString = entityManagementImpl.readResource(uuid);
HostingNode readHN = Entities.unmarshal(HostingNode.class, hnString);
Assert.assertTrue(readHN.getHeader().getUUID().compareTo(uuid)==0);
UUID eServiceUUID = eService.getHeader().getUUID();
try {
entityManagementImpl.readResource(eServiceUUID);
}catch(ResourceNotFoundException e){
logger.debug("Resource with {} Not Found as Expected", uuid.toString());
}
boolean deleted = entityManagementImpl.deleteResource(uuid);
Assert.assertTrue(deleted);
deleted = entityManagementImpl.deleteResource(eService.getHeader().getUUID());
Assert.assertTrue(deleted);
} }
@Test //@Test
public void addTest() throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException{ public void addTest() throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException{
ScopeProvider.instance.set("/gcube/devNext/NextNext"); ScopeProvider.instance.set("/gcube/devNext/NextNext");
entityManagementImpl.addResourceToContext(UUID.fromString("75583599-c082-4b89-84ab-125e64d768c4")); entityManagementImpl.addResourceToContext(UUID.fromString(""));
} }
} }