Add tests based on the Jersey Test Framework for Context methods. Simple container seems a good compromise for testing the methods.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@158849 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2017-11-28 04:06:10 +00:00
parent 362743bed2
commit 77831c3367
5 changed files with 77 additions and 5 deletions

View File

@ -0,0 +1,7 @@
/**
* Extensions/abstraction over the gCube resource model.
*
* @author Manuele Simi (ISTI - CNR)
*
*/
package org.gcube.resourcemanagement.manager.io.extendedmodel;

View File

@ -130,10 +130,14 @@
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- Test Dependency -->
<dependency>
<groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry-context-client</artifactId>
<version>1.0.0-SNAPSHOT</version>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.26</version>
<scope>runtime</scope>
</dependency>
<!-- Test Dependency -->
@ -147,7 +151,7 @@
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-simple</artifactId>
<version>2.17</version>
<version>2.26</version>
<scope>test</scope>
</dependency>

View File

@ -31,7 +31,7 @@ public class Context {
{
logger.info("Requested to create context {} with json {}",
org.gcube.informationsystem.model.entity.Context.NAME, json);
String response = "";
String response = "All good";
//TODO
return Response.status(Status.CREATED).entity(response).
type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();

View File

@ -1,4 +1,6 @@
/**
* Signatures of the REST methods for the Resource Manager webapp.
*
* @author Manuele Simi (ISTI - CNR)
*
*/

View File

@ -0,0 +1,59 @@
package org.gcube.resourcemanagement.manager.webapp.rs;
import static org.junit.Assert.*;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.gcube.informationsystem.impl.entity.ContextImpl;
import org.gcube.informationsystem.impl.utils.ISMapper;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.MethodSorters;
import com.fasterxml.jackson.core.JsonProcessingException;
/**
* Test cases for the Context methods.
*
* @author Manuele Simi (ISTI-CNR)*
*/
@RunWith(BlockJUnit4ClassRunner.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ContextTest extends JerseyTest {
private final static String contextName = "firstContext";
@Override
protected Application configure() {
return new ResourceConfig(Context.class);
}
/**
* Test method for
* {@link org.gcube.resourcemanagement.manager.webapp.rs.Context#create(java.lang.String)}.
*/
@Test
public void step1_Create() {
org.gcube.informationsystem.model.entity.Context newContext = new ContextImpl();
newContext.setName(contextName);
Response create;
try {
create = target("context").request()
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));
assertEquals("Unexpected returned code. Reason: " + create.getStatusInfo().getReasonPhrase(),
Status.CREATED.getStatusCode(), create.getStatus());
assertEquals("All good", (String) create.readEntity(String.class));
} catch (JsonProcessingException e) {
assertFalse("Failed to marshal the context.", false);
}
}
}