Improve the post test in GXHTTPStringRequest.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/gxREST@178712 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2019-03-28 01:17:37 +00:00
parent 69bac931ec
commit 7993999be2
1 changed files with 12 additions and 13 deletions

View File

@ -24,7 +24,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
/** /**
* Test cases for {@link GXHTTPStringRequest} * Test cases for {@link GXHTTPStringRequest}
* *
* @author Manuele Simi (ISTI-CNR) * @author Manuele Simi (ISTI-CNR)
* *
*/ */
@ -32,14 +32,14 @@ import com.fasterxml.jackson.databind.JsonMappingException;
public class GXHTTPStringRequestTest { public class GXHTTPStringRequestTest {
private GXHTTPStringRequest request; private GXHTTPStringRequest request;
public static String DEFAULT_TEST_SCOPE = ""; public static String DEFAULT_TEST_SCOPE = "";
static String DEFAULT_RM_URL = ""; static String DEFAULT_RM_URL = "";
static String DEFAULT_RR_URL = ""; static String DEFAULT_RR_URL = "";
private static boolean skipTest = false; private static boolean skipTest = false;
static { static {
@ -97,14 +97,13 @@ public class GXHTTPStringRequestTest {
if (skipTest) if (skipTest)
return; return;
request.clear(); request.clear();
String context ="{\"@class\":\"Context\",\"header\":{\"@class\":\"Header\",\"uuid\":\"6f86dc81-2f59-486b-8aa9-3ab5486313c4\",\"creator\":null,\"modifiedBy\":\"gxRestTest\",\"creationTime\":null,\"lastUpdateTime\":null},\"name\":\"gxTest\",\"parent\":null,\"children\":[]}"; String context ="{\"@class\":\"Context\",\"header\":{\"@class\":\"Header\",\"uuid\":\"b252e6ce-8b9a-4142-9bca-3ab5486313c4\",\"creator\":null,\"modifiedBy\":\"gxRestTest\",\"creationTime\":null,\"lastUpdateTime\":null},\"name\":\"gxTest\",\"parent\":null,\"children\":[]}";
Map<String,String> queryParams = new WeakHashMap<>(); Map<String,String> queryParams = new WeakHashMap<>();
queryParams.put("rrURL", DEFAULT_RR_URL); queryParams.put("rrURL", DEFAULT_RR_URL);
try { try {
GXInboundResponse response = request.path("gxrest") GXInboundResponse response = request.path("gxrest")
.header("Another header", "GXHTTPRequestTest") .header("Another header", "GXHTTPRequestTest")
.queryParams(queryParams).post(context); .queryParams(queryParams).post(context);
assertTrue("Unexpected returned code.", response.hasCREATEDCode());
if (response.hasException()) { if (response.hasException()) {
try { try {
throw response.getException(); throw response.getException();
@ -114,15 +113,15 @@ public class GXHTTPStringRequestTest {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} }
} else {
System.out.println("Returned string " + response.getStreamedContentAsString());
} }
assertTrue("Unexpected returned code.", response.hasCREATEDCode());
System.out.println("Returned string " + response.getStreamedContentAsString());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
fail("Failed to send a POST request"); fail("Failed to send a POST request");
} }
} }
@Test(expected=com.fasterxml.jackson.databind.JsonMappingException.class) @Test(expected=com.fasterxml.jackson.databind.JsonMappingException.class)
public void testPostNoBody() throws Exception { public void testPostNoBody() throws Exception {
if (skipTest) if (skipTest)
@ -152,7 +151,7 @@ public class GXHTTPStringRequestTest {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
//fail("Failed to send a POST request"); //fail("Failed to send a POST request");
} }
} }
/** /**
@ -194,7 +193,7 @@ public class GXHTTPStringRequestTest {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
fail("Failed to send a DELETE request"); fail("Failed to send a DELETE request");
} }
} }
/** /**
@ -227,7 +226,7 @@ public class GXHTTPStringRequestTest {
fail("Failed to send a DELETE request"); fail("Failed to send a DELETE request");
} }
} }
/** /**
* Test method for {@link org.gcube.common.gxrest.request.GXHTTPStringRequest#head()}. * Test method for {@link org.gcube.common.gxrest.request.GXHTTPStringRequest#head()}.