Move the RMContextTest to the same package of the webapp. This way tests can access protected functionalities.
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@160615 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
ac8d0cf465
commit
4b9abb09f0
|
@ -0,0 +1,103 @@
|
|||
package org.gcube.resourcemanagement.manager.webapp.context;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
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.gcube.informationsystem.model.entity.Context;
|
||||
import org.gcube.resourcemanagement.manager.webapp.rs.RMContext;
|
||||
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 RMContextTest extends JerseyTest {
|
||||
|
||||
private final static String contextName = "firstContext";
|
||||
|
||||
@Override
|
||||
protected Application configure() {
|
||||
return new ResourceConfig(RMContext.class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for marshal/unmarshal contexts.
|
||||
*/
|
||||
@Test
|
||||
public void step0_Context() {
|
||||
Context newContext = new ContextImpl(contextName);
|
||||
//newContext.setParent(new ContextImpl("parent"));
|
||||
try {
|
||||
ISMapper.unmarshal(Context.class, ISMapper.marshal(newContext));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
assertFalse("Failed to unmarshal the context.", false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
public void step1_Create() {
|
||||
Context newContext = new ContextImpl(contextName);
|
||||
try {
|
||||
System.out.print(ISMapper.marshal(newContext));
|
||||
Response create = target("context").request()
|
||||
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));
|
||||
|
||||
assertNotNull(create);
|
||||
//TODO: to restore an expected success when create is fully functional
|
||||
//assertEquals("Unexpected returned code. Reason: " + create.getStatusInfo().getReasonPhrase(),
|
||||
// Status.CREATED.getStatusCode(), create.getStatus());
|
||||
//assertEquals("All good", (String) create.readEntity(String.class));
|
||||
assertEquals("Unexpected returned code. Reason: " + create.getStatusInfo().getReasonPhrase(),
|
||||
Status.BAD_REQUEST.getStatusCode(), create.getStatus());
|
||||
} catch (JsonProcessingException e) {
|
||||
assertFalse("Failed to marshal the context.", false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(java.lang.String)} when the parent does not exist.
|
||||
*/
|
||||
@Test
|
||||
public void step1_CreateWithInvalidParent() {
|
||||
Context newContext = new ContextImpl(contextName);
|
||||
newContext.setParent(new ContextImpl("DoNotExist"));
|
||||
try {
|
||||
Response 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.BAD_REQUEST.getStatusCode(), create.getStatus());
|
||||
} catch (JsonProcessingException e) {
|
||||
assertFalse("Failed to marshal the context.", false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue