Integrate GXInboundResponse.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@163246 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2018-02-14 05:08:43 +00:00
parent db3d6a3cf7
commit 856b10efa6
1 changed files with 20 additions and 24 deletions

View File

@ -18,8 +18,8 @@ import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry; import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.gxrest.response.inbound.GXInboundResponse; import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
import org.gcube.common.gxrest.response.outbound.CodeFinder;
import org.gcube.common.gxrest.response.outbound.ErrorCode; import org.gcube.common.gxrest.response.outbound.ErrorCode;
import org.gcube.common.gxrest.response.outbound.deserialization.SerializableErrorEntity;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.impl.entity.ContextImpl; import org.gcube.informationsystem.impl.entity.ContextImpl;
import org.gcube.informationsystem.impl.utils.ISMapper; import org.gcube.informationsystem.impl.utils.ISMapper;
@ -199,14 +199,15 @@ public class RMContextTest extends JerseyTest {
Response create = target(RMContextPath.CONTEXT_ROOT).queryParam(RMContextPath.FORCE_RRURL_PARAM, RR) Response create = target(RMContextPath.CONTEXT_ROOT).queryParam(RMContextPath.FORCE_RRURL_PARAM, RR)
.request() .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(), GXInboundResponse response = new GXInboundResponse(create);
Status.NOT_ACCEPTABLE.getStatusCode(), create.getStatus());
SerializableErrorEntity code = create.readEntity(SerializableErrorEntity.class); assertTrue("Unexpected returned code. Reason: " + create.getStatusInfo().getReasonPhrase(),
// RMCreateContextCode realCode = response.hasNOT_ACCEPTABLECode());
// CodeFinder.findAndConvert(code.getErrorCode(), if (response.hasErrorCode()) {
// RMCreateContextCode.values()); RMCreateContextCode realCode = CodeFinder.findAndConvert(response.getErrorCode(),
// assertEquals(RMCreateContextCode.CONTEXT_PARENT_DOES_NOT_EXIST, RMCreateContextCode.values());
// realCode); 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);
} }
@ -230,18 +231,12 @@ public class RMContextTest extends JerseyTest {
.request() .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()) { GXInboundResponse response = new GXInboundResponse(create);
String message = create.readEntity(String.class); if (response.hasCREATEDCode()) {
System.out.println("RM says: " + message); System.out.println("RM says: " + response.getMessage());
} else { } else {
assertEquals("Unexpected returned code. Reason: " + create.getStatusInfo().getReasonPhrase(), assertTrue("Unexpected returned code. Reason: " + response.getHTTPStatus().getReasonPhrase(),
Status.NOT_ACCEPTABLE.getStatusCode(), create.getStatus()); response.hasNOT_ACCEPTABLECode());
SerializableErrorEntity code = create.readEntity(SerializableErrorEntity.class);
// RMCreateContextCode 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);
@ -262,12 +257,12 @@ public class RMContextTest extends JerseyTest {
Response delete = target(RMContextPath.CONTEXT_ROOT).path(context2UUID.toString()) Response delete = target(RMContextPath.CONTEXT_ROOT).path(context2UUID.toString())
.queryParam(RMContextPath.FORCE_RRURL_PARAM, RR).request().delete(); .queryParam(RMContextPath.FORCE_RRURL_PARAM, RR).request().delete();
assertNotNull(delete); assertNotNull(delete);
if (delete.getStatusInfo().getStatusCode() == Status.OK.getStatusCode()) { GXInboundResponse response = new GXInboundResponse(delete);
if (response.hasOKCode()) {
} 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());
GXInboundResponse response = new GXInboundResponse(delete);
if (response.hasException()) { if (response.hasException()) {
try { try {
throw response.getException(); throw response.getException();
@ -292,8 +287,9 @@ public class RMContextTest extends JerseyTest {
Response delete = target(RMContextPath.CONTEXT_ROOT).path(context1UUID.toString()) Response delete = target(RMContextPath.CONTEXT_ROOT).path(context1UUID.toString())
.queryParam(RMContextPath.FORCE_RRURL_PARAM, RR).request().delete(); .queryParam(RMContextPath.FORCE_RRURL_PARAM, RR).request().delete();
assertNotNull(delete); assertNotNull(delete);
assertEquals("Unexpected returned code. Reason: " + delete.getStatusInfo().getReasonPhrase(), GXInboundResponse response = new GXInboundResponse(delete);
Status.OK.getStatusCode(), delete.getStatus()); assertTrue("Unexpected returned code. Reason: " + response.getHTTPStatus().getReasonPhrase(),
response.hasOKCode());
} catch (Exception e) { } catch (Exception e) {
assertFalse("Failed to delete the context.", false); assertFalse("Failed to delete the context.", false);
} }