use of org.apache.http.HttpResponseFactory in project dataverse by IQSS.
the class DataCaptureModuleUtilTest method testGetScriptFromRequestNotFound.
@Test
public void testGetScriptFromRequestNotFound() throws UnsupportedEncodingException {
System.out.println("getScriptFromRequestNotFound");
HttpResponseFactory factory = new DefaultHttpResponseFactory();
org.apache.http.HttpResponse response = factory.newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_FOUND, null), null);
JsonObjectBuilder jab = Json.createObjectBuilder();
jab.add("userId", 42);
jab.add("datasetIdentifier", "123");
jab.add("script", "#!/bin/sh");
response.setEntity(new StringEntity(jab.build().toString()));
HttpResponse<JsonNode> httpResponse = new HttpResponse<>(response, JsonNode.class);
ScriptRequestResponse result = DataCaptureModuleUtil.getScriptFromRequest(httpResponse);
assertEquals(404, result.getHttpStatusCode());
assertEquals(-1, result.getDatasetId());
assertEquals(-1, result.getUserId());
assertEquals(null, result.getScript());
}
use of org.apache.http.HttpResponseFactory in project dataverse by IQSS.
the class DataCaptureModuleUtilTest method testGetScriptFromRequestOk.
@Test
public void testGetScriptFromRequestOk() throws UnsupportedEncodingException {
System.out.println("getScriptFromRequestOk");
HttpResponseFactory factory = new DefaultHttpResponseFactory();
org.apache.http.HttpResponse response = factory.newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, null), null);
JsonObjectBuilder jab = Json.createObjectBuilder();
jab.add("userId", 42);
jab.add("datasetIdentifier", "123");
jab.add("script", "#!/bin/sh");
response.setEntity(new StringEntity(jab.build().toString()));
HttpResponse<JsonNode> httpResponse = new HttpResponse<>(response, JsonNode.class);
ScriptRequestResponse result = DataCaptureModuleUtil.getScriptFromRequest(httpResponse);
assertEquals(200, result.getHttpStatusCode());
assertEquals("123", result.getDatasetIdentifier());
assertEquals(42, result.getUserId());
assertEquals("#!/bin/sh", result.getScript());
}
use of org.apache.http.HttpResponseFactory in project dataverse by IQSS.
the class DataCaptureModuleUtilTest method testMakeUploadRequest.
@Test
public void testMakeUploadRequest() throws UnsupportedEncodingException {
System.out.println("makeUploadRequest");
HttpResponseFactory factory = new DefaultHttpResponseFactory();
org.apache.http.HttpResponse response = factory.newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, null), null);
response.setEntity(new StringEntity("received"));
HttpResponse<String> httpResponse = new HttpResponse<>(response, String.class);
UploadRequestResponse result = DataCaptureModuleUtil.makeUploadRequest(httpResponse);
assertEquals(200, result.getHttpStatusCode());
assertEquals("received", result.getResponse());
}
Aggregations