Search in sources :

Example 1 with ContainerResponse

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

the class AnalyticsProcessTest method testAnalyticsProcessForGetRequestWithJsonContentTypeHeader.

@Test
public void testAnalyticsProcessForGetRequestWithJsonContentTypeHeader() throws InterruptedException {
    Mockito.when(profileEntityCacheManager.retrieve(Mockito.eq("1234-4321-1234-4321"))).thenReturn(getProfileEntity());
    ContainerRequest request = getGetRequestWithJsonContentTypeHeader();
    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.ORCID_JSON, data.getContentType());
}
Also used : ContainerResponse(com.sun.jersey.spi.container.ContainerResponse) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Test(org.junit.Test)

Example 2 with ContainerResponse

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

the class AnalyticsProcessTest method testAnalyticsProcessForPostRequestWithUnknownContentTypeHeader.

@Test
public void testAnalyticsProcessForPostRequestWithUnknownContentTypeHeader() throws InterruptedException {
    Mockito.when(profileEntityCacheManager.retrieve(Mockito.eq("1234-4321-1234-4321"))).thenReturn(getProfileEntity());
    ContainerRequest request = getPostRequestWithUnknownContentTypeHeader();
    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("POST", data.getMethod());
    // default content type
    assertEquals("something/weird", data.getContentType());
}
Also used : ContainerResponse(com.sun.jersey.spi.container.ContainerResponse) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Test(org.junit.Test)

Example 3 with ContainerResponse

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

the class AnalyticsProcessTest method testAnalyticsProcessForMemberClient.

@Test
public void testAnalyticsProcessForMemberClient() throws InterruptedException {
    String clientDetailsId = "some-client-details-id";
    Mockito.when(clientDetailsEntityCacheManager.retrieve(Mockito.eq(clientDetailsId))).thenReturn(getMemberClient());
    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(false);
    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("POST", data.getMethod());
    assertEquals("works", data.getCategory());
    assertEquals("Member API v2.0", data.getApiVersion());
    assertEquals(ClientType.CREATOR.value() + " | a member client - some-client-details-id", data.getClientDetailsString());
    assertEquals("37.14.150.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)

Example 4 with ContainerResponse

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

the class AnalyticsProcessTest method testAnalyticsProcessForAnonymous.

@Test
public void testAnalyticsProcessForAnonymous() throws InterruptedException {
    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.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("POST", data.getMethod());
    assertEquals("works", data.getCategory());
    assertEquals("Public API v2.0", data.getApiVersion());
    assertEquals("Unknown", data.getClientDetailsString());
    assertEquals("37.14.150.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)

Example 5 with ContainerResponse

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

the class AnalyticsProcessTest method testAnalyticsProcessForGetRequestWithRdfXmlContentTypeHeader.

@Test
public void testAnalyticsProcessForGetRequestWithRdfXmlContentTypeHeader() throws InterruptedException {
    Mockito.when(profileEntityCacheManager.retrieve(Mockito.eq("1234-4321-1234-4321"))).thenReturn(getProfileEntity());
    ContainerRequest request = getGetRequestWithRdfXmlAcceptHeader();
    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.APPLICATION_RDFXML, 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