Search in sources :

Example 1 with LoadBalancerInterceptor

use of org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor in project spring-cloud-netflix by spring-cloud.

the class RibbonInterceptorTests method testIntercept.

@Test
public void testIntercept() throws Exception {
    RibbonServer server = new RibbonServer("myservice", new Server("myhost", 8080));
    LoadBalancerInterceptor interceptor = new LoadBalancerInterceptor(new MyClient(server));
    given(this.request.getURI()).willReturn(new URL("http://myservice").toURI());
    given(this.execution.execute(isA(HttpRequest.class), isA(byte[].class))).willReturn(this.response);
    ArgumentCaptor<HttpRequestWrapper> argument = ArgumentCaptor.forClass(HttpRequestWrapper.class);
    ClientHttpResponse response = interceptor.intercept(this.request, new byte[0], this.execution);
    assertNotNull("response was null", response);
    verify(this.execution).execute(argument.capture(), isA(byte[].class));
    HttpRequestWrapper wrapper = argument.getValue();
    assertEquals("wrong constructed uri", new URL("http://myhost:8080").toURI(), wrapper.getURI());
}
Also used : HttpRequest(org.springframework.http.HttpRequest) RibbonServer(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer) RibbonServer(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer) Server(com.netflix.loadbalancer.Server) HttpRequestWrapper(org.springframework.http.client.support.HttpRequestWrapper) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) LoadBalancerInterceptor(org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Server (com.netflix.loadbalancer.Server)1 URL (java.net.URL)1 Test (org.junit.Test)1 LoadBalancerInterceptor (org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor)1 RibbonServer (org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer)1 HttpRequest (org.springframework.http.HttpRequest)1 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)1 HttpRequestWrapper (org.springframework.http.client.support.HttpRequestWrapper)1