Search in sources :

Example 1 with HttpResponseFactory

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());
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpResponse(com.mashape.unirest.http.HttpResponse) DefaultHttpResponseFactory(org.apache.http.impl.DefaultHttpResponseFactory) JsonNode(com.mashape.unirest.http.JsonNode) JsonObjectBuilder(javax.json.JsonObjectBuilder) HttpResponseFactory(org.apache.http.HttpResponseFactory) DefaultHttpResponseFactory(org.apache.http.impl.DefaultHttpResponseFactory) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 2 with HttpResponseFactory

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());
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpResponse(com.mashape.unirest.http.HttpResponse) DefaultHttpResponseFactory(org.apache.http.impl.DefaultHttpResponseFactory) JsonNode(com.mashape.unirest.http.JsonNode) JsonObjectBuilder(javax.json.JsonObjectBuilder) HttpResponseFactory(org.apache.http.HttpResponseFactory) DefaultHttpResponseFactory(org.apache.http.impl.DefaultHttpResponseFactory) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 3 with HttpResponseFactory

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());
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpResponse(com.mashape.unirest.http.HttpResponse) DefaultHttpResponseFactory(org.apache.http.impl.DefaultHttpResponseFactory) HttpResponseFactory(org.apache.http.HttpResponseFactory) DefaultHttpResponseFactory(org.apache.http.impl.DefaultHttpResponseFactory) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Aggregations

HttpResponse (com.mashape.unirest.http.HttpResponse)3 HttpResponseFactory (org.apache.http.HttpResponseFactory)3 StringEntity (org.apache.http.entity.StringEntity)3 DefaultHttpResponseFactory (org.apache.http.impl.DefaultHttpResponseFactory)3 BasicStatusLine (org.apache.http.message.BasicStatusLine)3 Test (org.junit.Test)3 JsonNode (com.mashape.unirest.http.JsonNode)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2