HttpEndpointComponent extends AbstractEndpointComponent { @Override protected Endpoint createEndpoint(String resourcePath, Map<String, String> parameters, TestContext context) { HttpClient client = new HttpClient(); client.getEndpointConfiguration().setRequestUrl(getScheme() + resourcePath + getParameterString(parameters, HttpEndpointConfiguration.class)); if (parameters.containsKey("requestMethod")) { String method = parameters.remove("requestMethod"); client.getEndpointConfiguration().setRequestMethod(HttpMethod.valueOf(method)); } if (parameters.containsKey("errorHandlingStrategy")) { String strategy = parameters.remove("errorHandlingStrategy"); client.getEndpointConfiguration().setErrorHandlingStrategy(ErrorHandlingStrategy.fromName(strategy)); } enrichEndpointConfiguration(client.getEndpointConfiguration(), getEndpointConfigurationParameters(parameters, HttpEndpointConfiguration.class), context); return client; } HttpEndpointComponent();  HttpEndpointComponent(String name);   }
@Test public void testCreateClientEndpoint() throws Exception { HttpEndpointComponent component = new HttpEndpointComponent(); Endpoint endpoint = component.createEndpoint("http: Assert.assertEquals(endpoint.getClass(), HttpClient.class); Assert.assertEquals(((HttpClient)endpoint).getEndpointConfiguration().getRequestUrl(), "http: Assert.assertEquals(((HttpClient) endpoint).getEndpointConfiguration().getRequestMethod(), HttpMethod.POST); Assert.assertEquals(((HttpClient) endpoint).getEndpointConfiguration().getErrorHandlingStrategy(), ErrorHandlingStrategy.PROPAGATE); Assert.assertEquals(((HttpClient) endpoint).getEndpointConfiguration().getTimeout(), 5000L); }
@Test public void testCreateClientEndpointWithParameters() throws Exception { HttpEndpointComponent component = new HttpEndpointComponent(); reset(referenceResolver); when(referenceResolver.isResolvable("myRequestFactory")).thenReturn(true); when(referenceResolver.resolve("myRequestFactory", ClientHttpRequestFactory.class)).thenReturn(requestFactory); Endpoint endpoint = component.createEndpoint("http:localhost:8088?requestMethod=GET&timeout=10000&errorHandlingStrategy=throwsException&requestFactory=myRequestFactory", context); Assert.assertEquals(endpoint.getClass(), HttpClient.class); Assert.assertEquals(((HttpClient)endpoint).getEndpointConfiguration().getRequestUrl(), "http: Assert.assertEquals(((HttpClient) endpoint).getEndpointConfiguration().getRequestMethod(), HttpMethod.GET); Assert.assertEquals(((HttpClient) endpoint).getEndpointConfiguration().getRequestFactory(), requestFactory); Assert.assertEquals(((HttpClient) endpoint).getEndpointConfiguration().getErrorHandlingStrategy(), ErrorHandlingStrategy.THROWS_EXCEPTION); Assert.assertEquals(((HttpClient) endpoint).getEndpointConfiguration().getTimeout(), 10000L); }
@Test public void testCreateClientEndpointWithCustomParameters() throws Exception { HttpEndpointComponent component = new HttpEndpointComponent(); Endpoint endpoint = component.createEndpoint("http: Assert.assertEquals(endpoint.getClass(), HttpClient.class); Assert.assertEquals(((HttpClient)endpoint).getEndpointConfiguration().getRequestUrl(), "http: Assert.assertEquals(((HttpClient) endpoint).getEndpointConfiguration().getRequestMethod(), HttpMethod.DELETE); Assert.assertEquals(((HttpClient) endpoint).getEndpointConfiguration().getTimeout(), 5000L); }