NodeUtil { @Deprecated public static void rewriteURI(Node node, String uri) { node.getProperties().add(new Property(APM_ORIGINAL_URI, node.getUri())); node.setUri(uri); }  @Deprecated static boolean isURIRewritten(Node node); @Deprecated static void rewriteURI(Node node, String uri); @Deprecated static boolean isOriginalURI(Node node, String uri); static boolean rewriteURI(Node node); static List<T> findNodes(List<Node> nodes, Class<T> cls); @SuppressWarnings("unchecked") static void findNodes(List<Node> nodes, Class<T> cls, List<T> results);  }
@Test public void testRewriteURI() { Consumer consumer = new Consumer(); consumer.setUri(ORIGINAL_URI); NodeUtil.rewriteURI(consumer, NEW_URI); assertEquals(NEW_URI, consumer.getUri()); }
@Test public void testRewriteURINoTemplate() { Consumer consumer = new Consumer(); consumer.setUri("/anything"); assertFalse(NodeUtil.rewriteURI(consumer)); }
@Test public void testRewriteURITemplateNoQuery1() { Consumer consumer = new Consumer(); consumer.setUri("/service/helloworld"); consumer.getProperties().add(new Property(Constants.PROP_HTTP_URL_TEMPLATE, "/service/{serviceName}")); assertTrue(NodeUtil.rewriteURI(consumer)); assertEquals("/service/{serviceName}", consumer.getUri()); assertTrue(consumer.hasProperty("serviceName")); assertEquals("helloworld", consumer.getProperties("serviceName").iterator().next().getValue()); }
@Test public void testRewriteURITemplateWithSpec() { Consumer consumer = new Consumer(); consumer.setUri("/service/helloworld"); consumer.getProperties().add(new Property(Constants.PROP_HTTP_URL_TEMPLATE, "/service/{serviceName:.+}")); assertTrue(NodeUtil.rewriteURI(consumer)); assertEquals("/service/{serviceName:.+}", consumer.getUri()); assertTrue(consumer.hasProperty("serviceName")); assertEquals("helloworld", consumer.getProperties("serviceName").iterator().next().getValue()); }
@Test public void testRewriteURITemplateWithMultipleSlashes() { Consumer consumer = new Consumer(); consumer.setUri("/download/aa/bb/cc"); consumer.getProperties().add(new Property(Constants.PROP_HTTP_URL_TEMPLATE, "/download/{file:.+}")); assertTrue(NodeUtil.rewriteURI(consumer)); assertEquals("/download/{file:.+}", consumer.getUri()); assertTrue(consumer.hasProperty("file")); assertEquals("aa/bb/cc", consumer.getProperties("file").iterator().next().getValue()); }
@Test public void testRewriteURITemplateNoQuery2() { Consumer consumer = new Consumer(); consumer.setUri("/service/helloworld/123"); consumer.getProperties().add(new Property(Constants.PROP_HTTP_URL_TEMPLATE, "/service/{serviceName}/{num}")); assertTrue(NodeUtil.rewriteURI(consumer)); assertEquals("/service/{serviceName}/{num}", consumer.getUri()); assertTrue(consumer.hasProperty("serviceName")); assertEquals("helloworld", consumer.getProperties("serviceName").iterator().next().getValue()); assertTrue(consumer.hasProperty("num")); assertEquals("123", consumer.getProperties("num").iterator().next().getValue()); }
@Test public void testRewriteURITemplateWithQuery() { Consumer consumer = new Consumer(); consumer.setUri("/service/helloworld"); consumer.getProperties().add(new Property(Constants.PROP_HTTP_QUERY, "param1=fred&param2=joe")); consumer.getProperties().add(new Property(Constants.PROP_HTTP_URL_TEMPLATE, "/service/{serviceName}?{param2}&{param1}")); assertTrue(NodeUtil.rewriteURI(consumer)); assertEquals("/service/{serviceName}", consumer.getUri()); assertTrue(consumer.hasProperty("param1")); assertEquals("fred", consumer.getProperties("param1").iterator().next().getValue()); assertTrue(consumer.hasProperty("param2")); assertEquals("joe", consumer.getProperties("param2").iterator().next().getValue()); }
@Test public void dontFailOnMisconfiguration() { Consumer consumer = new Consumer(); consumer.setUri("/service/helloworld"); consumer.getProperties().add(new Property(Constants.PROP_HTTP_QUERY, "param1=fred&param2=joe")); consumer.getProperties().add(new Property(Constants.PROP_HTTP_URL_TEMPLATE, null)); assertFalse(NodeUtil.rewriteURI(consumer)); }