JestClientFactory { public JestClient getObject() { JestHttpClient client = new JestHttpClient(); if (httpClientConfig == null) { log.debug("There is no configuration to create http client. Going to create simple client with default values"); httpClientConfig = new HttpClientConfig.Builder("http: } client.setRequestCompressionEnabled(httpClientConfig.isRequestCompressionEnabled()); client.setServers(httpClientConfig.getServerList()); final HttpClientConnectionManager connectionManager = getConnectionManager(); final NHttpClientConnectionManager asyncConnectionManager = getAsyncConnectionManager(); client.setHttpClient(createHttpClient(connectionManager)); client.setAsyncClient(createAsyncHttpClient(asyncConnectionManager)); Gson gson = httpClientConfig.getGson(); if (gson == null) { log.info("Using default GSON instance"); } else { log.info("Using custom GSON instance"); client.setGson(gson); } if (httpClientConfig.isDiscoveryEnabled()) { log.info("Node Discovery enabled..."); if (!Strings.isNullOrEmpty(httpClientConfig.getDiscoveryFilter())) { log.info("Node Discovery filtering nodes on \"{}\"", httpClientConfig.getDiscoveryFilter()); } NodeChecker nodeChecker = createNodeChecker(client, httpClientConfig); client.setNodeChecker(nodeChecker); nodeChecker.startAsync(); nodeChecker.awaitRunning(); } else { log.info("Node Discovery disabled..."); } if (httpClientConfig.getMaxConnectionIdleTime() > 0) { log.info("Idle connection reaping enabled..."); IdleConnectionReaper reaper = new IdleConnectionReaper(httpClientConfig, new HttpReapableConnectionManager(connectionManager, asyncConnectionManager)); client.setIdleConnectionReaper(reaper); reaper.startAsync(); reaper.awaitRunning(); } else { log.info("Idle connection reaping disabled..."); } Set<HttpHost> preemptiveAuthTargetHosts = httpClientConfig.getPreemptiveAuthTargetHosts(); if (!preemptiveAuthTargetHosts.isEmpty()) { log.info("Authentication cache set for preemptive authentication"); client.setHttpClientContextTemplate(createPreemptiveAuthContext(preemptiveAuthTargetHosts)); } client.setElasticsearchVersion(httpClientConfig.getElasticsearchVersion()); return client; }  JestClient getObject(); void setHttpClientConfig(HttpClientConfig httpClientConfig);  }
@Test public void clientCreationWithNullClientConfig() { JestClientFactory factory = new JestClientFactory(); JestHttpClient jestClient = (JestHttpClient) factory.getObject(); assertTrue(jestClient != null); assertNotNull(jestClient.getAsyncClient()); assertEquals(jestClient.getServerPoolSize(), 1); assertEquals("server list should contain localhost:9200", "http: }