use of com.sun.jersey.client.apache4.ApacheHttpClient4 in project pentaho-kettle by pentaho.
the class RestTest method testCallEndpointWithDeleteVerb.
@Test
public void testCallEndpointWithDeleteVerb() throws KettleException {
MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
headers.add("Content-Type", "application/json");
ClientResponse response = mock(ClientResponse.class);
doReturn(200).when(response).getStatus();
doReturn(headers).when(response).getHeaders();
doReturn("true").when(response).getEntity(String.class);
WebResource.Builder builder = mock(WebResource.Builder.class);
doReturn(response).when(builder).delete(ClientResponse.class);
WebResource resource = mock(WebResource.class);
doReturn(builder).when(resource).getRequestBuilder();
ApacheHttpClient4 client = mock(ApacheHttpClient4.class);
doReturn(resource).when(client).resource(anyString());
mockStatic(ApacheHttpClient4.class);
when(ApacheHttpClient4.create(any())).thenReturn(client);
RestMeta meta = mock(RestMeta.class);
doReturn(false).when(meta).isDetailed();
doReturn(false).when(meta).isUrlInField();
doReturn(false).when(meta).isDynamicMethod();
RowMetaInterface rmi = mock(RowMetaInterface.class);
doReturn(1).when(rmi).size();
RestData data = mock(RestData.class);
DefaultApacheHttpClient4Config config = mock(DefaultApacheHttpClient4Config.class);
doReturn(new HashSet<>()).when(config).getSingletons();
data.method = RestMeta.HTTP_METHOD_DELETE;
data.inputRowMeta = rmi;
data.resultFieldName = "result";
data.resultCodeFieldName = "status";
data.resultHeaderFieldName = "headers";
data.config = config;
Rest rest = mock(Rest.class);
doCallRealMethod().when(rest).callRest(any());
doCallRealMethod().when(rest).searchForHeaders(any());
setInternalState(rest, "meta", meta);
setInternalState(rest, "data", data);
Object[] output = rest.callRest(new Object[] { 0 });
verify(builder, times(1)).delete(ClientResponse.class);
assertEquals("true", output[1]);
assertEquals(200L, output[2]);
assertEquals("{\"Content-Type\":\"application\\/json\"}", output[3]);
}
use of com.sun.jersey.client.apache4.ApacheHttpClient4 in project camunda-bpm-platform by camunda.
the class AbstractWebIntegrationTest method createClient.
public void createClient(String ctxPath) throws Exception {
testProperties = new TestProperties();
APP_BASE_PATH = testProperties.getApplicationPath("/" + ctxPath);
LOGGER.info("Connecting to application " + APP_BASE_PATH);
ClientConfig clientConfig = new DefaultApacheHttpClient4Config();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
client = ApacheHttpClient4.create(clientConfig);
defaultHttpClient = (DefaultHttpClient) client.getClientHandler().getHttpClient();
HttpParams params = defaultHttpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, 3 * 60 * 1000);
HttpConnectionParams.setSoTimeout(params, 10 * 60 * 1000);
}
Aggregations