Test the ErrorCode after with the new deserialization of the entity.
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@162829 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3adf77e8bd
commit
85bacd7afe
|
@ -1,7 +1,6 @@
|
||||||
package org.gcube.resourcemanagement.manager.io.codeexceptions;
|
package org.gcube.resourcemanagement.manager.io.codeexceptions;
|
||||||
|
|
||||||
import javax.ws.rs.WebApplicationException;
|
import javax.ws.rs.WebApplicationException;
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -48,9 +48,9 @@ public class RMContext {
|
||||||
logger.info("Force URL: " + rrURL);
|
logger.info("Force URL: " + rrURL);
|
||||||
ContextHolder holder = new ContextHolder(json);
|
ContextHolder holder = new ContextHolder(json);
|
||||||
ResponseFromResourceRegistry returned = CreateRequest.fromHolder(holder).forceURL(rrURL).submit();
|
ResponseFromResourceRegistry returned = CreateRequest.fromHolder(holder).forceURL(rrURL).submit();
|
||||||
if (!returned.wasSuccessful()) {
|
/* if (!returned.wasSuccessful()) {
|
||||||
throw new WebCodeException(new RMContextDoesNotExistException("too bad"));
|
throw new WebCodeException(new RMContextDoesNotExistException("too bad"));
|
||||||
}
|
}*/
|
||||||
return this.buildResponse(returned,Status.CREATED,"Context successfully created.","Failed to create the context.");
|
return this.buildResponse(returned,Status.CREATED,"Context successfully created.","Failed to create the context.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,9 +65,9 @@ public class RMContext {
|
||||||
logger.info("Requested to delete context with id {}", uuid);
|
logger.info("Requested to delete context with id {}", uuid);
|
||||||
logger.info("Force URL: " + rrURL);
|
logger.info("Force URL: " + rrURL);
|
||||||
ResponseFromResourceRegistry returned = DeleteRequest.fromUUID(UUID.fromString(uuid)).forceURL(rrURL).submit();
|
ResponseFromResourceRegistry returned = DeleteRequest.fromUUID(UUID.fromString(uuid)).forceURL(rrURL).submit();
|
||||||
if (!returned.wasSuccessful()) {
|
/* if (!returned.wasSuccessful()) {
|
||||||
throw new WebCodeException(new RMContextDoesNotExistException());
|
throw new WebCodeException(new RMContextDoesNotExistException());
|
||||||
}
|
}*/
|
||||||
return this.buildResponse(returned,Status.OK,"Context successfully deleted.","Failed to delete the context.");
|
return this.buildResponse(returned,Status.OK,"Context successfully deleted.","Failed to delete the context.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,9 @@ import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||||
import org.gcube.informationsystem.model.entity.Context;
|
import org.gcube.informationsystem.model.entity.Context;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClient;
|
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClient;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientImpl;
|
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientImpl;
|
||||||
import org.gcube.resourcemanagement.manager.io.codeexceptions.CodeFinder;
|
import org.gcube.resourcemanagement.manager.io.codeexceptions.ErrorCode;
|
||||||
import org.gcube.resourcemanagement.manager.io.codeexceptions.SerializableErrorEntity;
|
import org.gcube.resourcemanagement.manager.io.codeexceptions.SerializableErrorEntity;
|
||||||
|
import org.gcube.resourcemanagement.manager.io.codeexceptions.CodeFinder;
|
||||||
import org.gcube.resourcemanagement.manager.io.codeexceptions.deserializer.ErrorEntityManager;
|
import org.gcube.resourcemanagement.manager.io.codeexceptions.deserializer.ErrorEntityManager;
|
||||||
import org.gcube.resourcemanagement.manager.io.rs.RMCreateContextCode;
|
import org.gcube.resourcemanagement.manager.io.rs.RMCreateContextCode;
|
||||||
import org.gcube.resourcemanagement.manager.io.rs.RMContextDoesNotExistException;
|
import org.gcube.resourcemanagement.manager.io.rs.RMContextDoesNotExistException;
|
||||||
|
@ -40,7 +41,6 @@ import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
import org.junit.runners.BlockJUnit4ClassRunner;
|
||||||
import org.junit.runners.MethodSorters;
|
import org.junit.runners.MethodSorters;
|
||||||
import org.omg.IOP.ExceptionDetailMessage;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -56,23 +56,23 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
public class RMContextTest extends JerseyTest {
|
public class RMContextTest extends JerseyTest {
|
||||||
|
|
||||||
private final static String context1 = "ContextA";
|
private final static String context1 = "ContextA";
|
||||||
|
|
||||||
private final static String context2 = "ContextB";
|
private final static String context2 = "ContextB";
|
||||||
|
|
||||||
private final static String context3 = "ContextC";
|
private final static String context3 = "ContextC";
|
||||||
|
|
||||||
public static final UUID context1UUID = UUID.fromString("5f86dc81-2f59-486b-8aa9-3ab5486313c4");
|
public static final UUID context1UUID = UUID.fromString("5f86dc81-2f59-486b-8aa9-3ab5486313c4");
|
||||||
|
|
||||||
public static final UUID context2UUID = UUID.fromString("6f86dc81-2f59-486b-8aa9-3ab5486313c4");
|
public static final UUID context2UUID = UUID.fromString("6f86dc81-2f59-486b-8aa9-3ab5486313c4");
|
||||||
|
|
||||||
public static final UUID context3UUID = UUID.fromString("7f86dc81-2f59-486b-8aa9-3ab5486313c4");
|
public static final UUID context3UUID = UUID.fromString("7f86dc81-2f59-486b-8aa9-3ab5486313c4");
|
||||||
|
|
||||||
private final static String RR = "http://manuele-registry.dev.d4science.org/resource-registry";
|
private final static String RR = "http://manuele-registry.dev.d4science.org/resource-registry";
|
||||||
|
|
||||||
public static String DEFAULT_TEST_SCOPE ="";
|
public static String DEFAULT_TEST_SCOPE = "";
|
||||||
|
|
||||||
private static boolean skipTest = false;
|
private static boolean skipTest = false;
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(RMContextTest.class);
|
private static final Logger logger = LoggerFactory.getLogger(RMContextTest.class);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -82,9 +82,9 @@ public class RMContextTest extends JerseyTest {
|
||||||
properties.load(input);
|
properties.load(input);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
skipTest = true;
|
skipTest = true;
|
||||||
//throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFAULT_TEST_SCOPE = properties.getProperty("DEFAULT_SCOPE_TOKEN");
|
DEFAULT_TEST_SCOPE = properties.getProperty("DEFAULT_SCOPE_TOKEN");
|
||||||
if (DEFAULT_TEST_SCOPE.isEmpty())
|
if (DEFAULT_TEST_SCOPE.isEmpty())
|
||||||
skipTest = true;
|
skipTest = true;
|
||||||
|
@ -143,9 +143,10 @@ public class RMContextTest extends JerseyTest {
|
||||||
/**
|
/**
|
||||||
* Test method for
|
* Test method for
|
||||||
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(String)}.
|
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(String)}.
|
||||||
* @throws Exception
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test(expected = RMContextDoesNotExistException.class)
|
@Test
|
||||||
public void step1_Create() throws Exception {
|
public void step1_Create() throws Exception {
|
||||||
if (skipTest)
|
if (skipTest)
|
||||||
return;
|
return;
|
||||||
|
@ -155,33 +156,38 @@ public class RMContextTest extends JerseyTest {
|
||||||
Response create = target("context").queryParam(RMContextPath.FORCE_RRURL_PARAM, RR).request()
|
Response create = target("context").queryParam(RMContextPath.FORCE_RRURL_PARAM, RR).request()
|
||||||
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));
|
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));
|
||||||
assertNotNull(create);
|
assertNotNull(create);
|
||||||
logger.info("RM returned status: " + create.getStatusInfo() );
|
logger.info("RM returned status: " + create.getStatusInfo());
|
||||||
if (create.getStatusInfo().getStatusCode() == Status.CREATED.getStatusCode()) {
|
if (create.getStatusInfo().getStatusCode() == Status.CREATED.getStatusCode()) {
|
||||||
String message = create.readEntity(String.class);
|
String message = create.readEntity(String.class);
|
||||||
logger.info("RM says: " + message);
|
logger.info("RM says: " + message);
|
||||||
}else {
|
} else {
|
||||||
assertEquals("Unexpected returned code. Reason: " + create.getStatusInfo().getReasonPhrase(),
|
assertEquals("Unexpected returned code. Reason: " + create.getStatusInfo().getReasonPhrase(),
|
||||||
Status.NOT_ACCEPTABLE.getStatusCode(), create.getStatus());
|
Status.NOT_ACCEPTABLE.getStatusCode(), create.getStatus());
|
||||||
SerializableErrorEntity entity = create.readEntity(SerializableErrorEntity.class);
|
SerializableErrorEntity entity = create.readEntity(SerializableErrorEntity.class);
|
||||||
//try {
|
ErrorEntityManager response = new ErrorEntityManager(entity);
|
||||||
|
if (response.hasException()) {
|
||||||
logger.info("about to load " + entity.getExceptionClass());
|
logger.info("about to load " + entity.getExceptionClass());
|
||||||
ErrorEntityManager response = new ErrorEntityManager(entity);
|
try {
|
||||||
if (response.hasException()) {
|
throw response.getException();
|
||||||
try {
|
} catch (Exception e) {
|
||||||
throw response.getException();
|
// TODO Auto-generated catch block
|
||||||
} catch (Exception e) {
|
e.printStackTrace();
|
||||||
// TODO Auto-generated catch block
|
throw e;
|
||||||
e.printStackTrace();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else if (response.hasErrorCode()) {
|
||||||
|
ErrorCode code = response.getErrorCode();
|
||||||
|
RMCreateContextCode realCode = CodeFinder.findAndConvert(code, RMCreateContextCode.values());
|
||||||
|
assertEquals(RMCreateContextCode.CONTEXT_ALREADY_EXISTS, realCode);
|
||||||
|
} else {
|
||||||
|
assertTrue("Invalid error response returned.", true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
assertFalse("Failed to marshal the context.", false);
|
assertFalse("Failed to marshal the context.", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for
|
* Test method for
|
||||||
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(java.lang.String)}
|
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(java.lang.String)}
|
||||||
|
@ -194,18 +200,22 @@ public class RMContextTest extends JerseyTest {
|
||||||
Context newContext = new ContextImpl(context2, context2UUID);
|
Context newContext = new ContextImpl(context2, context2UUID);
|
||||||
newContext.setParent(new ContextImpl("DoNotExist"));
|
newContext.setParent(new ContextImpl("DoNotExist"));
|
||||||
try {
|
try {
|
||||||
Response create = target(RMContextPath.CONTEXT_ROOT).queryParam(RMContextPath.FORCE_RRURL_PARAM, RR).request()
|
Response create = target(RMContextPath.CONTEXT_ROOT).queryParam(RMContextPath.FORCE_RRURL_PARAM, RR)
|
||||||
|
.request()
|
||||||
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));
|
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));
|
||||||
assertEquals("Unexpected returned code. Reason: " + create.getStatusInfo().getReasonPhrase(),
|
assertEquals("Unexpected returned code. Reason: " + create.getStatusInfo().getReasonPhrase(),
|
||||||
Status.NOT_ACCEPTABLE.getStatusCode(), create.getStatus());
|
Status.NOT_ACCEPTABLE.getStatusCode(), create.getStatus());
|
||||||
SerializableErrorEntity code = create.readEntity(SerializableErrorEntity.class);
|
SerializableErrorEntity code = create.readEntity(SerializableErrorEntity.class);
|
||||||
//RMCreateContextCode realCode = CodeFinder.findAndConvert(code.getErrorCode(), RMCreateContextCode.values());
|
// RMCreateContextCode realCode =
|
||||||
//assertEquals(RMCreateContextCode.CONTEXT_PARENT_DOES_NOT_EXIST, realCode);
|
// CodeFinder.findAndConvert(code.getErrorCode(),
|
||||||
|
// RMCreateContextCode.values());
|
||||||
|
// assertEquals(RMCreateContextCode.CONTEXT_PARENT_DOES_NOT_EXIST,
|
||||||
|
// realCode);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
assertFalse("Failed to marshal the context.", false);
|
assertFalse("Failed to marshal the context.", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for
|
* Test method for
|
||||||
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(java.lang.String)}
|
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(java.lang.String)}
|
||||||
|
@ -220,57 +230,60 @@ public class RMContextTest extends JerseyTest {
|
||||||
Queries queries = new Queries();
|
Queries queries = new Queries();
|
||||||
newContext.setParent(context1UUID);
|
newContext.setParent(context1UUID);
|
||||||
try {
|
try {
|
||||||
Response create = target(RMContextPath.CONTEXT_ROOT).queryParam(RMContextPath.FORCE_RRURL_PARAM, RR).request()
|
Response create = target(RMContextPath.CONTEXT_ROOT).queryParam(RMContextPath.FORCE_RRURL_PARAM, RR)
|
||||||
|
.request()
|
||||||
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));
|
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));
|
||||||
assertNotNull(create);
|
assertNotNull(create);
|
||||||
if (create.getStatusInfo().getStatusCode() == Status.CREATED.getStatusCode()) {
|
if (create.getStatusInfo().getStatusCode() == Status.CREATED.getStatusCode()) {
|
||||||
String message = create.readEntity(String.class);
|
String message = create.readEntity(String.class);
|
||||||
System.out.println("RM says: " + message);
|
System.out.println("RM says: " + message);
|
||||||
}else {
|
} else {
|
||||||
assertEquals("Unexpected returned code. Reason: " + create.getStatusInfo().getReasonPhrase(),
|
assertEquals("Unexpected returned code. Reason: " + create.getStatusInfo().getReasonPhrase(),
|
||||||
Status.NOT_ACCEPTABLE.getStatusCode(), create.getStatus());
|
Status.NOT_ACCEPTABLE.getStatusCode(), create.getStatus());
|
||||||
SerializableErrorEntity code = create.readEntity(SerializableErrorEntity.class);
|
SerializableErrorEntity code = create.readEntity(SerializableErrorEntity.class);
|
||||||
//RMCreateContextCode realCode = CodeFinder.findAndConvert(code.getErrorCode(), RMCreateContextCode.values());
|
// RMCreateContextCode realCode =
|
||||||
//assertEquals(RMCreateContextCode.CONTEXT_ALREADY_EXISTS, realCode);
|
// CodeFinder.findAndConvert(code.getErrorCode(),
|
||||||
|
// RMCreateContextCode.values());
|
||||||
|
// assertEquals(RMCreateContextCode.CONTEXT_ALREADY_EXISTS,
|
||||||
|
// realCode);
|
||||||
}
|
}
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
assertFalse("Failed to marshal the context.", false);
|
assertFalse("Failed to marshal the context.", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for
|
* Test method for
|
||||||
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#delete(String, String)}
|
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#delete(String, String)}
|
||||||
* @throws Exception
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void step4_Delete() throws Exception {
|
public void step4_Delete() throws Exception {
|
||||||
if (skipTest)
|
if (skipTest)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Response delete = target(RMContextPath.CONTEXT_ROOT).path(context2UUID.toString())
|
Response delete = target(RMContextPath.CONTEXT_ROOT).path(context2UUID.toString())
|
||||||
.queryParam(RMContextPath.FORCE_RRURL_PARAM, RR)
|
.queryParam(RMContextPath.FORCE_RRURL_PARAM, RR).request().delete();
|
||||||
.request().delete();
|
assertNotNull(delete);
|
||||||
assertNotNull(delete);
|
if (delete.getStatusInfo().getStatusCode() == Status.OK.getStatusCode()) {
|
||||||
if (delete.getStatusInfo().getStatusCode() == Status.OK.getStatusCode()) {
|
|
||||||
|
} else {
|
||||||
}else {
|
assertEquals("Unexpected returned code. Reason: " + delete.getStatusInfo().getReasonPhrase(),
|
||||||
assertEquals("Unexpected returned code. Reason: " + delete.getStatusInfo().getReasonPhrase(),
|
Status.NOT_ACCEPTABLE.getStatusCode(), delete.getStatus());
|
||||||
Status.NOT_ACCEPTABLE.getStatusCode(), delete.getStatus());
|
SerializableErrorEntity entity = delete.readEntity(SerializableErrorEntity.class);
|
||||||
SerializableErrorEntity entity = delete.readEntity(SerializableErrorEntity.class);
|
ErrorEntityManager response = new ErrorEntityManager(entity);
|
||||||
ErrorEntityManager response = new ErrorEntityManager(entity);
|
if (response.hasException()) {
|
||||||
if (response.hasException()) {
|
try {
|
||||||
try {
|
throw response.getException();
|
||||||
throw response.getException();
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
// TODO Auto-generated catch block
|
||||||
// TODO Auto-generated catch block
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
throw e;
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for
|
* Test method for
|
||||||
|
@ -282,8 +295,7 @@ public class RMContextTest extends JerseyTest {
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
Response delete = target(RMContextPath.CONTEXT_ROOT).path(context1UUID.toString())
|
Response delete = target(RMContextPath.CONTEXT_ROOT).path(context1UUID.toString())
|
||||||
.queryParam(RMContextPath.FORCE_RRURL_PARAM, RR)
|
.queryParam(RMContextPath.FORCE_RRURL_PARAM, RR).request().delete();
|
||||||
.request().delete();
|
|
||||||
assertNotNull(delete);
|
assertNotNull(delete);
|
||||||
assertEquals("Unexpected returned code. Reason: " + delete.getStatusInfo().getReasonPhrase(),
|
assertEquals("Unexpected returned code. Reason: " + delete.getStatusInfo().getReasonPhrase(),
|
||||||
Status.OK.getStatusCode(), delete.getStatus());
|
Status.OK.getStatusCode(), delete.getStatus());
|
||||||
|
|
Loading…
Reference in New Issue