EndpointUtil { public static EndpointRef getSourceEndpoint(Trace fragment) { Node rootNode = fragment.getNodes().isEmpty() ? null : fragment.getNodes().get(0); if (rootNode == null) { return null; } return new EndpointRef(rootNode.getUri(), rootNode.getOperation(), fragment.initialFragment() && rootNode instanceof Producer); }  static String encodeEndpoint(String uri, String operation); static String decodeEndpointURI(String endpoint); static String decodeEndpointOperation(String endpoint, boolean stripped); static String encodeClientURI(String uri); static String decodeClientURI(String clientUri); static EndpointRef getSourceEndpoint(Trace fragment);  }
@Test public void testGetSourceEndpointConsumer() { Trace trace = new Trace(); trace.setTraceId("1"); trace.setFragmentId(trace.getTraceId()); Consumer consumer = new Consumer(); consumer.setUri(URI); consumer.setOperation(OPERATION); trace.getNodes().add(consumer); EndpointRef ep = EndpointUtil.getSourceEndpoint(trace); assertNotNull(ep); assertEquals(new EndpointRef(URI, OPERATION, false), ep); }
@Test public void testGetSourceEndpointClientProducer() { Trace trace = new Trace(); trace.setTraceId("1"); trace.setFragmentId(trace.getTraceId()); Producer producer = new Producer(); producer.setUri(URI); producer.setOperation(OPERATION); trace.getNodes().add(producer); EndpointRef ep = EndpointUtil.getSourceEndpoint(trace); assertNotNull(ep); assertEquals(new EndpointRef(URI, OPERATION, true), ep); }
@Test public void testGetSourceEndpointNotClientComponentProducer() { Trace trace = new Trace(); trace.setTraceId("1"); trace.setFragmentId(trace.getTraceId()); Component component = new Component(); component.setUri(URI); component.setOperation(OPERATION); trace.getNodes().add(component); Producer producer = new Producer(); producer.setUri("otheruri"); producer.setOperation("otherop"); component.getNodes().add(producer); EndpointRef ep = EndpointUtil.getSourceEndpoint(trace); assertNotNull(ep); assertEquals(new EndpointRef(URI, OPERATION, false), ep); }