@Test public void testOutput() throws ParseException { List<MetricName> inputMetricNames = new ArrayList<MetricName>() {{ add(new MetricName("foo", false)); add(new MetricName("bar", false)); }}; String output = handler.getSerializedJSON(inputMetricNames); JSONParser jsonParser = new JSONParser(); JSONArray tokenInfos = (JSONArray) jsonParser.parse(output); Assert.assertEquals("Unexpected result size", 2, tokenInfos.size()); Set<String> expectedOutputSet = new HashSet<String>(); for (MetricName metricName : inputMetricNames) { expectedOutputSet.add(metricName.getName() + "|" + metricName.isCompleteName()); } Set<String> outputSet = new HashSet<String>(); for (int i = 0; i< inputMetricNames.size(); i++) { JSONObject object = (JSONObject) tokenInfos.get(i); Iterator it = object.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); outputSet.add(entry.getKey() + "|" + entry.getValue()); } } Assert.assertEquals("Unexpected size", expectedOutputSet.size(), outputSet.size()); Assert.assertTrue("Output contains no more elements than expected", expectedOutputSet.containsAll(outputSet)); Assert.assertTrue("Output contains no less elements than expected", outputSet.containsAll(expectedOutputSet)); }
public String getSerializedJSON(final List<MetricName> metricNames) { ArrayNode tokenInfoArrayNode = JsonNodeFactory.instance.arrayNode(); for (MetricName metricName : metricNames) { ObjectNode metricNameInfoNode = JsonNodeFactory.instance.objectNode(); metricNameInfoNode.put(metricName.getName(), JsonNodeFactory.instance.booleanNode(metricName.isCompleteName())); tokenInfoArrayNode.add(metricNameInfoNode); } return tokenInfoArrayNode.toString(); }
HttpMetricNamesHandler implements HttpRequestHandler { public String getSerializedJSON(final List<MetricName> metricNames) { ArrayNode tokenInfoArrayNode = JsonNodeFactory.instance.arrayNode(); for (MetricName metricName : metricNames) { ObjectNode metricNameInfoNode = JsonNodeFactory.instance.objectNode(); metricNameInfoNode.put(metricName.getName(), JsonNodeFactory.instance.booleanNode(metricName.isCompleteName())); tokenInfoArrayNode.add(metricNameInfoNode); } return tokenInfoArrayNode.toString(); } }
HttpMetricNamesHandler implements HttpRequestHandler { public String getSerializedJSON(final List<MetricName> metricNames) { ArrayNode tokenInfoArrayNode = JsonNodeFactory.instance.arrayNode(); for (MetricName metricName : metricNames) { ObjectNode metricNameInfoNode = JsonNodeFactory.instance.objectNode(); metricNameInfoNode.put(metricName.getName(), JsonNodeFactory.instance.booleanNode(metricName.isCompleteName())); tokenInfoArrayNode.add(metricNameInfoNode); } return tokenInfoArrayNode.toString(); } HttpMetricNamesHandler();  HttpMetricNamesHandler(DiscoveryIO discoveryHandle); }
HttpMetricNamesHandler implements HttpRequestHandler { public String getSerializedJSON(final List<MetricName> metricNames) { ArrayNode tokenInfoArrayNode = JsonNodeFactory.instance.arrayNode(); for (MetricName metricName : metricNames) { ObjectNode metricNameInfoNode = JsonNodeFactory.instance.objectNode(); metricNameInfoNode.put(metricName.getName(), JsonNodeFactory.instance.booleanNode(metricName.isCompleteName())); tokenInfoArrayNode.add(metricNameInfoNode); } return tokenInfoArrayNode.toString(); } HttpMetricNamesHandler();  HttpMetricNamesHandler(DiscoveryIO discoveryHandle); @Override void handle(ChannelHandlerContext ctx, FullHttpRequest request); String getSerializedJSON(final List<MetricName> metricNames); }
HttpMetricNamesHandler implements HttpRequestHandler { public String getSerializedJSON(final List<MetricName> metricNames) { ArrayNode tokenInfoArrayNode = JsonNodeFactory.instance.arrayNode(); for (MetricName metricName : metricNames) { ObjectNode metricNameInfoNode = JsonNodeFactory.instance.objectNode(); metricNameInfoNode.put(metricName.getName(), JsonNodeFactory.instance.booleanNode(metricName.isCompleteName())); tokenInfoArrayNode.add(metricNameInfoNode); } return tokenInfoArrayNode.toString(); } HttpMetricNamesHandler();  HttpMetricNamesHandler(DiscoveryIO discoveryHandle); @Override void handle(ChannelHandlerContext ctx, FullHttpRequest request); String getSerializedJSON(final List<MetricName> metricNames); static boolean EXP_TOKEN_SEARCH_IMPROVEMENTS; }