DynamicEndpointUriResolver implements EndpointUriResolver { public String resolveEndpointUri(Message message, String defaultUri) { Map<String, Object> headers = message.getHeaders(); String requestUri; if (headers.containsKey(ENDPOINT_URI_HEADER_NAME)) { requestUri = headers.get(ENDPOINT_URI_HEADER_NAME).toString(); } else if (StringUtils.hasText(defaultUri)) { requestUri = defaultUri; } else { requestUri = defaultEndpointUri; } if (requestUri == null) { throw new CitrusRuntimeException("Unable to resolve dynamic endpoint uri! Neither header entry '" + ENDPOINT_URI_HEADER_NAME + "' nor default endpoint uri is set"); } requestUri = appendRequestPath(requestUri, headers); requestUri = appendQueryParams(requestUri, headers); return requestUri; }  String resolveEndpointUri(Message message, String defaultUri); void setDefaultEndpointUri(String defaultEndpointUri);  }
@Test public void testEndpointMapping() { DynamicEndpointUriResolver endpointUriResolver = new DynamicEndpointUriResolver(); Message testMessage; testMessage = createTestMessage() .setHeader(EndpointUriResolver.ENDPOINT_URI_HEADER_NAME, "http: Assert.assertEquals(endpointUriResolver.resolveEndpointUri(testMessage, "http: }
@Test(dataProvider = "endpointPathProvider") public void testEndpointMappingWithPath(String endpointUri, String requestPath, String expected) { DynamicEndpointUriResolver endpointUriResolver = new DynamicEndpointUriResolver(); Message testMessage = createTestMessage() .setHeader(EndpointUriResolver.ENDPOINT_URI_HEADER_NAME, endpointUri) .setHeader(EndpointUriResolver.REQUEST_PATH_HEADER_NAME, requestPath); Assert.assertEquals(endpointUriResolver.resolveEndpointUri(testMessage, "http: }
@Test(dataProvider = "queryParamDataProvider") public void testEndpointMappingWithQueryParams(String endpointUri, String queryParamString, String expected) { DynamicEndpointUriResolver endpointUriResolver = new DynamicEndpointUriResolver(); Message testMessage = createTestMessage() .setHeader(EndpointUriResolver.ENDPOINT_URI_HEADER_NAME, endpointUri) .setHeader(EndpointUriResolver.QUERY_PARAM_HEADER_NAME, queryParamString); Assert.assertEquals(endpointUriResolver.resolveEndpointUri(testMessage, "http: }
@Test public void testResolveException() { DynamicEndpointUriResolver endpointUriResolver = new DynamicEndpointUriResolver(); Message testMessage = createTestMessage(); try { endpointUriResolver.resolveEndpointUri(testMessage, null); } catch (CitrusRuntimeException e) { Assert.assertTrue(e.getMessage().startsWith("Unable to resolve dynamic endpoint uri")); Assert.assertTrue(e.getMessage().contains(EndpointUriResolver.ENDPOINT_URI_HEADER_NAME)); return; } Assert.fail("Missing CitrusRuntimeException caused by unresolvable endpoint uri"); }