ElasticConnectionPoolConfigurationPublisher implements ConnectionPoolConfigurationPublisher { JSONObject createJsonFromConfig(ConnectionPoolConfiguration config) throws JSONException { if (config == null) { throw new IllegalArgumentException("Valid ConnectionPoolConfiguration instance is required"); } JSONObject json = new JSONObject(); json.put("ApplicationName", applicationName); json.put("DynomiteClusterName", clusterName); Method[] methods = config.getClass().getMethods(); for (Method method : methods) { if (method.getName().startsWith("get")) { Class<?> ret = method.getReturnType(); if (ret.isPrimitive() || ret == java.lang.String.class) { try { json.put(method.getName().substring(3), method.invoke(config)); } catch (ReflectiveOperationException ex) { } } } } Set<String> jars = new HashSet<String>() {{ add("dyno-core"); add("dyno-contrib"); add("dyno-jedis"); add("dyno-reddison"); }}; json.put("Versions", new JSONObject(getLibraryVersion(this.getClass(), jars))); return json; } ElasticConnectionPoolConfigurationPublisher(String applicationName, String clusterName, String vip,
                                                       ConnectionPoolConfiguration config); @Override void publish();  }
@Test(expected = IllegalArgumentException.class) public void testCreateJsonFromConfigNullConfig() throws JSONException { ElasticConnectionPoolConfigurationPublisher publisher = new ElasticConnectionPoolConfigurationPublisher("ClientApp", "dyno_cluster_1", "unit-test-vip", config); publisher.createJsonFromConfig(null); }
@Test public void testCreateJsonFromConfig() throws JSONException { ElasticConnectionPoolConfigurationPublisher publisher = new ElasticConnectionPoolConfigurationPublisher("ClientApp", "dyno_cluster_1", "unit-test-vip", config); JSONObject json = publisher.createJsonFromConfig(config); assertTrue(json.has("ApplicationName")); assertTrue(json.has("DynomiteClusterName")); assertTrue(json.has("MaxConnsPerHost")); }