Search in sources :

Example 6 with ContainerResponse

use of com.sun.jersey.spi.container.ContainerResponse in project ORCID-Source by ORCID.

the class AnalyticsProcessTest method testAnalyticsProcessForGetRequestWithJsonLdContentTypeHeader.

@Test
public void testAnalyticsProcessForGetRequestWithJsonLdContentTypeHeader() throws InterruptedException {
    Mockito.when(profileEntityCacheManager.retrieve(Mockito.eq("1234-4321-1234-4321"))).thenReturn(getProfileEntity());
    ContainerRequest request = getGetRequestWithJsonLdAcceptHeader();
    ContainerResponse response = getResponse(request);
    AnalyticsProcess process = new AnalyticsProcess();
    process.setRequest(request);
    process.setResponse(response);
    process.setAnalyticsClient(analyticsClient);
    process.setClientDetailsEntityCacheManager(clientDetailsEntityCacheManager);
    process.setProfileEntityCacheManager(profileEntityCacheManager);
    process.setPublicApi(true);
    process.setIp("37.14.150.83");
    process.setScheme("https");
    Thread t = new Thread(process);
    t.start();
    t.join();
    ArgumentCaptor<AnalyticsData> captor = ArgumentCaptor.forClass(AnalyticsData.class);
    Mockito.verify(analyticsClient).sendAnalyticsData(captor.capture());
    AnalyticsData data = captor.getValue();
    assertNotNull(data);
    assertEquals("GET", data.getMethod());
    // default content type
    assertEquals(OrcidApiConstants.JSON_LD, data.getContentType());
}
Also used : ContainerResponse(com.sun.jersey.spi.container.ContainerResponse) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Test(org.junit.Test)

Example 7 with ContainerResponse

use of com.sun.jersey.spi.container.ContainerResponse in project ORCID-Source by ORCID.

the class AnalyticsProcessTest method testAnalyticsProcessForGetRequestWithXmlContentTypeHeader.

@Test
public void testAnalyticsProcessForGetRequestWithXmlContentTypeHeader() throws InterruptedException {
    Mockito.when(profileEntityCacheManager.retrieve(Mockito.eq("1234-4321-1234-4321"))).thenReturn(getProfileEntity());
    ContainerRequest request = getGetRequestWithXmlContentTypeHeader();
    ContainerResponse response = getResponse(request);
    AnalyticsProcess process = new AnalyticsProcess();
    process.setRequest(request);
    process.setResponse(response);
    process.setAnalyticsClient(analyticsClient);
    process.setClientDetailsEntityCacheManager(clientDetailsEntityCacheManager);
    process.setProfileEntityCacheManager(profileEntityCacheManager);
    process.setPublicApi(true);
    process.setIp("37.14.150.83");
    process.setScheme("https");
    Thread t = new Thread(process);
    t.start();
    t.join();
    ArgumentCaptor<AnalyticsData> captor = ArgumentCaptor.forClass(AnalyticsData.class);
    Mockito.verify(analyticsClient).sendAnalyticsData(captor.capture());
    AnalyticsData data = captor.getValue();
    assertNotNull(data);
    // default content type
    assertEquals(OrcidApiConstants.VND_ORCID_XML, data.getContentType());
}
Also used : ContainerResponse(com.sun.jersey.spi.container.ContainerResponse) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Test(org.junit.Test)

Example 8 with ContainerResponse

use of com.sun.jersey.spi.container.ContainerResponse in project commons by twitter.

the class HttpStatsFilterTest method setUp.

@Before
public void setUp() throws Exception {
    clock = new FakeClock();
    request = createMock(HttpServletRequest.class);
    response = createMock(HttpServletResponse.class);
    filterChain = createMock(FilterChain.class);
    filter = new HttpStatsFilter(clock);
    containerRequest = createMock(ContainerRequest.class);
    containerResponse = createMock(ContainerResponse.class);
    injectContextVars();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ContainerResponse(com.sun.jersey.spi.container.ContainerResponse) FakeClock(com.twitter.common.util.testing.FakeClock) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Before(org.junit.Before)

Example 9 with ContainerResponse

use of com.sun.jersey.spi.container.ContainerResponse in project ORCID-Source by ORCID.

the class AnalyticsProcessTest method getResponse.

private ContainerResponse getResponse(ContainerRequest request) {
    ContainerResponse response = new ContainerResponse(new WebApplicationImpl(), request, null);
    response.setStatus(200);
    return response;
}
Also used : ContainerResponse(com.sun.jersey.spi.container.ContainerResponse) WebApplicationImpl(com.sun.jersey.server.impl.application.WebApplicationImpl)

Example 10 with ContainerResponse

use of com.sun.jersey.spi.container.ContainerResponse in project ORCID-Source by ORCID.

the class AnalyticsProcessTest method testAnalyticsProcessForIPv6.

@Test
public void testAnalyticsProcessForIPv6() throws InterruptedException {
    String clientDetailsId = "some-client-details-id";
    Mockito.when(clientDetailsEntityCacheManager.retrieve(Mockito.eq(clientDetailsId))).thenReturn(getPublicClient());
    Mockito.when(profileEntityCacheManager.retrieve(Mockito.eq("1234-4321-1234-4321"))).thenReturn(getProfileEntity());
    ContainerRequest request = getRequest();
    ContainerResponse response = getResponse(request);
    AnalyticsProcess process = new AnalyticsProcess();
    process.setRequest(request);
    process.setResponse(response);
    process.setClientDetailsId(clientDetailsId);
    process.setAnalyticsClient(analyticsClient);
    process.setClientDetailsEntityCacheManager(clientDetailsEntityCacheManager);
    process.setProfileEntityCacheManager(profileEntityCacheManager);
    process.setPublicApi(true);
    process.setIp("0:0:0:0:0:0:0:1");
    process.setScheme("https");
    Thread t = new Thread(process);
    t.start();
    t.join();
    ArgumentCaptor<AnalyticsData> captor = ArgumentCaptor.forClass(AnalyticsData.class);
    Mockito.verify(analyticsClient).sendAnalyticsData(captor.capture());
    AnalyticsData data = captor.getValue();
    assertNotNull(data);
    assertEquals("POST", data.getMethod());
    assertEquals("works", data.getCategory());
    assertEquals("Public API v2.0", data.getApiVersion());
    assertEquals(ClientType.PUBLIC_CLIENT.value() + " | a public client - some-client-details-id", data.getClientDetailsString());
    assertEquals("0:0:0:0:0:0:0:0", data.getIpAddress());
    assertEquals(Integer.valueOf(200), data.getResponseCode());
    assertEquals("blah", data.getUserAgent());
    assertEquals(MediaType.APPLICATION_XML, data.getContentType());
}
Also used : ContainerResponse(com.sun.jersey.spi.container.ContainerResponse) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Test(org.junit.Test)

Aggregations

ContainerResponse (com.sun.jersey.spi.container.ContainerResponse)20 ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)19 Test (org.junit.Test)18 WebApplicationImpl (com.sun.jersey.server.impl.application.WebApplicationImpl)1 FakeClock (com.twitter.common.util.testing.FakeClock)1 FilterChain (javax.servlet.FilterChain)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Before (org.junit.Before)1