J4pClient extends J4pClientBuilderFactory { public <RESP extends J4pResponse<REQ>, REQ extends J4pRequest> RESP execute(REQ pRequest) throws J4pException { return this.<RESP, REQ>execute(pRequest,null,null); } J4pClient(String pJ4pServerUrl);  J4pClient(String pJ4pServerUrl, HttpClient pHttpClient);  J4pClient(String pJ4pServerUrl, HttpClient pHttpClient,J4pTargetConfig pTargetConfig);  J4pClient(String pJ4pServerUrl, HttpClient pHttpClient,J4pTargetConfig pTargetConfig,J4pResponseExtractor pExtractor); RESP execute(REQ pRequest); RESP execute(REQ pRequest,
                                                                     Map<J4pQueryParameter,String> pProcessingOptions); RESP execute(REQ pRequest,String pMethod); RESP execute(REQ pRequest,String pMethod,
                                                                     Map<J4pQueryParameter,String> pProcessingOptions); RESP execute(REQ pRequest,String pMethod,
                                                                     Map<J4pQueryParameter,String> pProcessingOptions,
                                                                     J4pResponseExtractor pExtractor); List<RESP> execute(List<REQ> pRequests); List<RESP> execute(List<REQ> pRequests,Map<J4pQueryParameter,String> pProcessingOptions); List<RESP> execute(List<REQ> pRequests,
                                                                                      Map<J4pQueryParameter,String> pProcessingOptions,
                                                                                      J4pResponseExtractor pResponseExtractor); List<R> execute(T ... pRequests); HttpClient getHttpClient(); URI getUri();  }
@Test public void simple() throws MalformedObjectNameException, J4pException, IOException { HttpClient client = prepareMocks("utf-8",MEMORY_RESPONSE); J4pClient j4p = new J4pClient(TEST_URL,client); J4pReadResponse resp = j4p.execute(TEST_REQUEST); assertEquals(((Map) resp.getValue()).get("max"), 530186240L); }
@Test(expectedExceptions = J4pException.class,expectedExceptionsMessageRegExp = ".*JSONArray.*") public void invalidArrayResponse() throws MalformedObjectNameException, J4pException, IOException { HttpClient client = prepareMocks(null,ARRAY_RESPONSE); J4pClient j4p = new J4pClient(TEST_URL,client); Map<J4pQueryParameter,String> opts = new HashMap<J4pQueryParameter, String>();; opts.put(J4pQueryParameter.IGNORE_ERRORS,"true"); j4p.execute(TEST_REQUEST, opts); }
@Test(expectedExceptions = J4pException.class,expectedExceptionsMessageRegExp = ".*reading.*response.*") public void throwIOExceptionWhenParsingAnswer() throws IOException, J4pException { HttpClient client = createMock(HttpClient.class); HttpResponse response = createMock(HttpResponse.class); HttpEntity entity = createMock(HttpEntity.class); expect(client.execute(EasyMock.<HttpUriRequest>anyObject())).andReturn(response); expect(response.getEntity()).andReturn(entity); expect(entity.getContentEncoding()).andReturn(null); expect(entity.isStreaming()).andReturn(false); expect(entity.getContent()).andThrow(new IOException()); replay(client, entity, response); J4pClient j4p = new J4pClient(TEST_URL,client); j4p.execute(TEST_REQUEST); }
@Test(expectedExceptions = J4pException.class,expectedExceptionsMessageRegExp = ".*Invalid.*bulk.*") public void invalidBulkRequestResponse() throws IOException, J4pException { HttpClient client = prepareMocks(null,MEMORY_RESPONSE); J4pClient j4p = new J4pClient(TEST_URL,client); j4p.execute(TEST_REQUEST,TEST_REQUEST_2); }
@Test(expectedExceptions = J4pRemoteException.class,expectedExceptionsMessageRegExp = ".*Invalid.*") public void noStatus() throws IOException, J4pException { HttpClient client = prepareMocks(null,EMPTY_RESPONSE); J4pClient j4p = new J4pClient(TEST_URL,client); j4p.execute(TEST_REQUEST); }
@Test(expectedExceptions = J4pRemoteException.class) public void remoteExceptionErrorValue() throws IOException, J4pException { HttpClient client = prepareMocks("utf-8", ERROR_VALUE_RESPONSE); J4pClient j4p = new J4pClient(TEST_URL,client); Map<J4pQueryParameter, String> options = Maps.newHashMap(); options.put(J4pQueryParameter.SERIALIZE_EXCEPTION, "true"); options.put(J4pQueryParameter.INCLUDE_STACKTRACE, "false"); try { j4p.execute(TEST_REQUEST, options); } catch (J4pRemoteException e) { assertEquals(e.getErrorValue().toJSONString(), "{\"test\":\"ok\"}"); throw e; } fail("No exception was thrown"); }