Search in sources :

Example 6 with ClientRequestContext

use of javax.ws.rs.client.ClientRequestContext in project robozonky by RoboZonky.

the class AuthenticationFilterTest method wasAuthorizationAdded.

@Test
void wasAuthorizationAdded() throws URISyntaxException {
    final ClientRequestContext crc = mock(ClientRequestContext.class);
    when(crc.getHeaders()).thenReturn(new MultivaluedHashMap<>());
    when(crc.getUri()).thenReturn(new URI("http://somewhere"));
    this.getTestedFilter().filter(crc);
    assertThat(crc.getHeaders()).containsKey("Authorization");
}
Also used : ClientRequestContext(javax.ws.rs.client.ClientRequestContext) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 7 with ClientRequestContext

use of javax.ws.rs.client.ClientRequestContext in project robozonky by RoboZonky.

the class RoboZonkyFilterTest method request.

@Test
void request() throws URISyntaxException {
    final MultivaluedMap<String, Object> map = mock(MultivaluedMap.class);
    final ClientRequestContext ctx = mock(ClientRequestContext.class);
    when(ctx.getHeaders()).thenReturn(map);
    when(ctx.getUri()).thenReturn(new URI("http://localhost"));
    final RoboZonkyFilter filter = new RoboZonkyFilter();
    filter.setQueryParam("something", "value");
    filter.filter(ctx);
    verify(ctx).setUri(new URI("http://localhost?something=value"));
    verify(map).putSingle(eq("User-Agent"), eq(Defaults.ROBOZONKY_USER_AGENT));
}
Also used : ClientRequestContext(javax.ws.rs.client.ClientRequestContext) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 8 with ClientRequestContext

use of javax.ws.rs.client.ClientRequestContext in project robozonky by RoboZonky.

the class AbstractCommonFilterTest method userAgent.

@Test
void userAgent() throws URISyntaxException {
    final MultivaluedMap<String, Object> map = new MultivaluedMapImpl<>();
    final ClientRequestContext ctx = mock(ClientRequestContext.class);
    when(ctx.getUri()).thenReturn(new URI("http://localhost/"));
    when(ctx.getHeaders()).thenReturn(map);
    getTestedFilter().filter(ctx);
    assertThat(map.get("User-Agent").get(0)).isEqualTo(Defaults.ROBOZONKY_USER_AGENT);
}
Also used : ClientRequestContext(javax.ws.rs.client.ClientRequestContext) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 9 with ClientRequestContext

use of javax.ws.rs.client.ClientRequestContext in project dropwizard by dropwizard.

the class ConfiguredGZipEncoderTest method gzipParametersSpec.

@Test
void gzipParametersSpec() throws IOException {
    ClientRequestContext context = mock(ClientRequestContext.class);
    MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
    when(context.getHeaders()).thenReturn(headers);
    headers.put(HttpHeaders.CONTENT_ENCODING, null);
    when(context.hasEntity()).thenReturn(true);
    new ConfiguredGZipEncoder(true).filter(context);
    assertThat(headers.getFirst(HttpHeaders.CONTENT_ENCODING)).hasToString("gzip");
}
Also used : ClientRequestContext(javax.ws.rs.client.ClientRequestContext) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Test(org.junit.jupiter.api.Test)

Example 10 with ClientRequestContext

use of javax.ws.rs.client.ClientRequestContext in project instrumentation-java by census-instrumentation.

the class JaxrsClientExtractorTest method testExtraction.

@Test
public void testExtraction() {
    URI uri = URI.create("https://myhost/resource");
    ClientRequestContext requestContext = mock(ClientRequestContext.class);
    when(requestContext.getUri()).thenReturn(uri);
    when(requestContext.getMethod()).thenReturn("GET");
    when(requestContext.getHeaderString("user-agent")).thenReturn("java/1.8");
    ClientResponseContext responseContext = mock(ClientResponseContext.class);
    when(responseContext.getStatus()).thenReturn(200);
    JaxrsClientExtractor extractor = new JaxrsClientExtractor();
    assertEquals("myhost", extractor.getHost(requestContext));
    assertEquals("GET", extractor.getMethod(requestContext));
    assertEquals("/resource", extractor.getPath(requestContext));
    assertNull(extractor.getRoute(requestContext));
    assertEquals("https://myhost/resource", extractor.getUrl(requestContext));
    assertEquals("java/1.8", extractor.getUserAgent(requestContext));
    assertEquals(200, extractor.getStatusCode(responseContext));
}
Also used : ClientRequestContext(javax.ws.rs.client.ClientRequestContext) URI(java.net.URI) ClientResponseContext(javax.ws.rs.client.ClientResponseContext) Test(org.junit.Test)

Aggregations

ClientRequestContext (javax.ws.rs.client.ClientRequestContext)30 Test (org.junit.Test)15 ClientResponseContext (javax.ws.rs.client.ClientResponseContext)11 Response (javax.ws.rs.core.Response)10 IOException (java.io.IOException)9 ClientRequestFilter (javax.ws.rs.client.ClientRequestFilter)8 ClientResponseFilter (javax.ws.rs.client.ClientResponseFilter)7 WebTarget (javax.ws.rs.client.WebTarget)7 Test (org.junit.jupiter.api.Test)7 URI (java.net.URI)6 Client (javax.ws.rs.client.Client)4 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)4 Message (org.apache.cxf.message.Message)4 MessageImpl (org.apache.cxf.message.MessageImpl)4 JerseyTest (org.glassfish.jersey.test.JerseyTest)4 ProcessingException (javax.ws.rs.ProcessingException)3 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)3 CreateSignatureInterceptor (org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor)3 VerifySignatureFilter (org.apache.cxf.rs.security.httpsignature.filters.VerifySignatureFilter)3 MockAlgorithmProvider (org.apache.cxf.rs.security.httpsignature.provider.MockAlgorithmProvider)3