static void toJson(AddressResolverOptions obj, java.util.Map<String, Object> json) { json.put("cacheMaxTimeToLive", obj.getCacheMaxTimeToLive()); json.put("cacheMinTimeToLive", obj.getCacheMinTimeToLive()); json.put("cacheNegativeTimeToLive", obj.getCacheNegativeTimeToLive()); if (obj.getHostsPath() != null) { json.put("hostsPath", obj.getHostsPath()); } if (obj.getHostsValue() != null) { json.put("hostsValue", java.util.Base64.getEncoder().encodeToString(obj.getHostsValue().getBytes())); } json.put("maxQueries", obj.getMaxQueries()); json.put("ndots", obj.getNdots()); json.put("optResourceEnabled", obj.isOptResourceEnabled()); json.put("queryTimeout", obj.getQueryTimeout()); json.put("rdFlag", obj.getRdFlag()); json.put("rotateServers", obj.isRotateServers()); if (obj.getSearchDomains() != null) { JsonArray array = new JsonArray(); obj.getSearchDomains().forEach(item -> array.add(item)); json.put("searchDomains", array); } if (obj.getServers() != null) { JsonArray array = new JsonArray(); obj.getServers().forEach(item -> array.add(item)); json.put("servers", array); } } }
@Test public void testDefaultJsonOptions() { AddressResolverOptions options = new AddressResolverOptions(new JsonObject()); assertEquals(AddressResolverOptions.DEFAULT_OPT_RESOURCE_ENABLED, options.isOptResourceEnabled()); assertEquals(AddressResolverOptions.DEFAULT_SERVERS, options.getServers()); assertEquals(AddressResolverOptions.DEFAULT_CACHE_MIN_TIME_TO_LIVE, options.getCacheMinTimeToLive()); assertEquals(AddressResolverOptions.DEFAULT_CACHE_MAX_TIME_TO_LIVE, options.getCacheMaxTimeToLive()); assertEquals(AddressResolverOptions.DEFAULT_CACHE_NEGATIVE_TIME_TO_LIVE, options.getCacheNegativeTimeToLive()); assertEquals(AddressResolverOptions.DEFAULT_QUERY_TIMEOUT, options.getQueryTimeout()); assertEquals(AddressResolverOptions.DEFAULT_MAX_QUERIES, options.getMaxQueries()); assertEquals(AddressResolverOptions.DEFAULT_RD_FLAG, options.getRdFlag()); assertEquals(AddressResolverOptions.DEFAULT_SEACH_DOMAINS, options.getSearchDomains()); assertEquals(AddressResolverOptions.DEFAULT_NDOTS, options.getNdots()); }
static void toJson(AddressResolverOptions obj, java.util.Map<String, Object> json) { json.put("cacheMaxTimeToLive", obj.getCacheMaxTimeToLive()); json.put("cacheMinTimeToLive", obj.getCacheMinTimeToLive()); json.put("cacheNegativeTimeToLive", obj.getCacheNegativeTimeToLive()); if (obj.getHostsPath() != null) { json.put("hostsPath", obj.getHostsPath()); } if (obj.getHostsValue() != null) { json.put("hostsValue", java.util.Base64.getEncoder().encodeToString(obj.getHostsValue().getBytes())); } json.put("maxQueries", obj.getMaxQueries()); json.put("ndots", obj.getNdots()); json.put("optResourceEnabled", obj.isOptResourceEnabled()); json.put("queryTimeout", obj.getQueryTimeout()); json.put("rdFlag", obj.getRdFlag()); json.put("rotateServers", obj.isRotateServers()); if (obj.getSearchDomains() != null) { JsonArray array = new JsonArray(); obj.getSearchDomains().forEach(item -> array.add(item)); json.put("searchDomains", array); } if (obj.getServers() != null) { JsonArray array = new JsonArray(); obj.getServers().forEach(item -> array.add(item)); json.put("servers", array); } } }
@Test public void testOptions() { AddressResolverOptions options = new AddressResolverOptions(); assertEquals(AddressResolverOptions.DEFAULT_OPT_RESOURCE_ENABLED, options.isOptResourceEnabled()); assertEquals(AddressResolverOptions.DEFAULT_SERVERS, options.getServers()); assertEquals(AddressResolverOptions.DEFAULT_CACHE_MIN_TIME_TO_LIVE, options.getCacheMinTimeToLive()); assertEquals(optResourceEnabled, options.isOptResourceEnabled()); assertEquals(servers, options.getServers()); assertEquals(minTTL, options.getCacheMinTimeToLive()); options.setSearchDomains(AddressResolverOptions.DEFAULT_SEACH_DOMAINS); assertEquals(optResourceEnabled, copy.isOptResourceEnabled()); assertEquals(servers, copy.getServers()); assertEquals(minTTL, copy.getCacheMinTimeToLive()); assertEquals(searchDomains, copy.getSearchDomains()); assertEquals(optResourceEnabled, jsonCopy.isOptResourceEnabled()); assertEquals(servers, jsonCopy.getServers()); assertEquals(minTTL, jsonCopy.getCacheMinTimeToLive());
@Test public void testDefaultJsonOptions() { AddressResolverOptions options = new AddressResolverOptions(new JsonObject()); assertEquals(AddressResolverOptions.DEFAULT_OPT_RESOURCE_ENABLED, options.isOptResourceEnabled()); assertEquals(AddressResolverOptions.DEFAULT_SERVERS, options.getServers()); assertEquals(AddressResolverOptions.DEFAULT_CACHE_MIN_TIME_TO_LIVE, options.getCacheMinTimeToLive()); assertEquals(AddressResolverOptions.DEFAULT_CACHE_MAX_TIME_TO_LIVE, options.getCacheMaxTimeToLive()); assertEquals(AddressResolverOptions.DEFAULT_CACHE_NEGATIVE_TIME_TO_LIVE, options.getCacheNegativeTimeToLive()); assertEquals(AddressResolverOptions.DEFAULT_QUERY_TIMEOUT, options.getQueryTimeout()); assertEquals(AddressResolverOptions.DEFAULT_MAX_QUERIES, options.getMaxQueries()); assertEquals(AddressResolverOptions.DEFAULT_RD_FLAG, options.getRdFlag()); assertEquals(AddressResolverOptions.DEFAULT_SEACH_DOMAINS, options.getSearchDomains()); assertEquals(AddressResolverOptions.DEFAULT_NDOTS, options.getNdots()); }
@Test public void testOptions() { AddressResolverOptions options = new AddressResolverOptions(); assertEquals(AddressResolverOptions.DEFAULT_OPT_RESOURCE_ENABLED, options.isOptResourceEnabled()); assertEquals(AddressResolverOptions.DEFAULT_SERVERS, options.getServers()); assertEquals(AddressResolverOptions.DEFAULT_CACHE_MIN_TIME_TO_LIVE, options.getCacheMinTimeToLive()); assertEquals(optResourceEnabled, options.isOptResourceEnabled()); assertEquals(servers, options.getServers()); assertEquals(minTTL, options.getCacheMinTimeToLive()); options.setSearchDomains(AddressResolverOptions.DEFAULT_SEACH_DOMAINS); assertEquals(optResourceEnabled, copy.isOptResourceEnabled()); assertEquals(servers, copy.getServers()); assertEquals(minTTL, copy.getCacheMinTimeToLive()); assertEquals(searchDomains, copy.getSearchDomains()); assertEquals(optResourceEnabled, jsonCopy.isOptResourceEnabled()); assertEquals(servers, jsonCopy.getServers()); assertEquals(minTTL, jsonCopy.getCacheMinTimeToLive());