use of com.sun.jersey.spi.container.ContainerRequest 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");
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("https://localhost:8443/orcid-api-web/v2.0/" + hashedOrcid + "/works", data.getUrl());
assertEquals("blah", data.getUserAgent());
assertEquals("application/xml", data.getContentType());
}
use of com.sun.jersey.spi.container.ContainerRequest 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");
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("Public API user", data.getClientDetailsString());
assertEquals("37.14.150.0", data.getIpAddress());
assertEquals(Integer.valueOf(200), data.getResponseCode());
assertEquals("https://localhost:8443/orcid-api-web/v2.0/" + hashedOrcid + "/works", data.getUrl());
assertEquals("blah", data.getUserAgent());
assertEquals("application/xml", data.getContentType());
}
use of com.sun.jersey.spi.container.ContainerRequest in project ORCID-Source by ORCID.
the class TokenTargetFilterTest method tokenUsedOnTheRightUserTest.
@Test
public void tokenUsedOnTheRightUserTest() {
setUpSecurityContext(ORCID1, CLIENT_ID, ScopePathType.READ_LIMITED);
ContainerRequest request = Mockito.mock(ContainerRequest.class);
Mockito.when(request.getPath()).thenReturn("http://api.test.orcid.org/v2.0/" + ORCID1);
TokenTargetFilter filter = new TokenTargetFilter();
filter.filter(request);
}
use of com.sun.jersey.spi.container.ContainerRequest in project ORCID-Source by ORCID.
the class TokenTargetFilterTest method readPublicTokenTest.
@Test
public void readPublicTokenTest() {
setUpSecurityContext(null, CLIENT_ID, ScopePathType.READ_PUBLIC);
ContainerRequest request = Mockito.mock(ContainerRequest.class);
Mockito.when(request.getPath()).thenReturn("http://api.test.orcid.org/v2.0/" + ORCID2);
TokenTargetFilter filter = new TokenTargetFilter();
filter.filter(request);
}
use of com.sun.jersey.spi.container.ContainerRequest in project ORCID-Source by ORCID.
the class ApiVersionCheckFilterTest method api1_2VersionTest.
@Test
public void api1_2VersionTest() {
WebApplication webApp = Mockito.mock(WebApplication.class, Mockito.RETURNS_MOCKS);
URI baseUri = URI.create("http://localhost:8443/orcid-api-web/");
URI requestUri = URI.create("http://localhost:8443/orcid-api-web/v1.2/0000-0001-7510-9252/activities");
InBoundHeaders headers = new InBoundHeaders();
ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[0]);
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "POST", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
filter.filter(containerRequest);
} catch (Exception e) {
fail();
}
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "PUT", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
filter.filter(containerRequest);
} catch (Exception e) {
fail();
}
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "DELETE", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
filter.filter(containerRequest);
} catch (Exception e) {
fail();
}
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "GET", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
filter.filter(containerRequest);
} catch (Exception e) {
fail();
}
}
Aggregations