use of com.sun.jersey.spi.container.ContainerResponse in project ORCID-Source by ORCID.
the class AnalyticsProcessTest method testAnalyticsProcessForPublicClientWithAmpersand.
@Test
public void testAnalyticsProcessForPublicClientWithAmpersand() throws InterruptedException {
String clientDetailsId = "some-client-details-id";
Mockito.when(clientDetailsEntityCacheManager.retrieve(Mockito.eq(clientDetailsId))).thenReturn(getPublicClientWithAmpersand());
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("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(ClientType.PUBLIC_CLIENT.value() + " | a public + 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());
}
use of com.sun.jersey.spi.container.ContainerResponse in project ORCID-Source by ORCID.
the class AnalyticsProcessTest method testAnalyticsProcessForGetRequestWithXmlAcceptHeader.
@Test
public void testAnalyticsProcessForGetRequestWithXmlAcceptHeader() throws InterruptedException {
Mockito.when(profileEntityCacheManager.retrieve(Mockito.eq("1234-4321-1234-4321"))).thenReturn(getProfileEntity());
ContainerRequest request = getGetRequestWithXmlAcceptHeader();
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(MediaType.APPLICATION_XML, data.getContentType());
}
use of com.sun.jersey.spi.container.ContainerResponse in project ORCID-Source by ORCID.
the class AnalyticsProcessTest method testAnalyticsProcessForNoSpecifiedCategory.
@Test
public void testAnalyticsProcessForNoSpecifiedCategory() throws InterruptedException {
Mockito.when(profileEntityCacheManager.retrieve(Mockito.eq("1234-4321-1234-4321"))).thenReturn(getProfileEntity());
ContainerRequest request = getRequestWithNoCategory();
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("record", 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());
}
use of com.sun.jersey.spi.container.ContainerResponse in project ORCID-Source by ORCID.
the class AnalyticsProcessTest method testAnalyticsProcessForGetRequestWithUnknownAcceptHeader.
@Test
public void testAnalyticsProcessForGetRequestWithUnknownAcceptHeader() throws InterruptedException {
Mockito.when(profileEntityCacheManager.retrieve(Mockito.eq("1234-4321-1234-4321"))).thenReturn(getProfileEntity());
ContainerRequest request = getGetRequestWithUnknownAcceptHeader();
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("something/weird", data.getContentType());
}
use of com.sun.jersey.spi.container.ContainerResponse in project ORCID-Source by ORCID.
the class AnalyticsProcessTest method testAnalyticsProcessWithNoContentType.
@Test
public void testAnalyticsProcessWithNoContentType() throws InterruptedException {
Mockito.when(profileEntityCacheManager.retrieve(Mockito.eq("1234-4321-1234-4321"))).thenReturn(getProfileEntity());
ContainerRequest request = getRequestWithNoContentType();
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());
assertNotNull(data.getContentType());
// default content type
assertEquals("default", data.getContentType());
}
Aggregations