Search in sources :

Example 36 with ContainerRequest

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

the class AnalyticsProcessTest method testAnalyticsProcessForPublicClient.

@Test
public void testAnalyticsProcessForPublicClient() 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("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(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("https://localhost:8443/orcid-api-web/v2.0/" + hashedOrcid + "/works", data.getUrl());
    assertEquals("blah", data.getUserAgent());
    assertEquals("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 37 with ContainerRequest

use of com.sun.jersey.spi.container.ContainerRequest 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");
    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("https://localhost:8443/orcid-api-web/v2.0/" + hashedOrcid + "/works", data.getUrl());
    assertEquals("blah", data.getUserAgent());
    assertEquals("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 38 with ContainerRequest

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

the class APIEndpointParserTest method testAPIEndpointParserWithApiVersionWithoutOrcid.

@Test
public void testAPIEndpointParserWithApiVersionWithoutOrcid() {
    ContainerRequest request = getRequest("https://localhost:8443/orcid-api-web/v1.2/orcid-profile");
    APIEndpointParser parser = new APIEndpointParser(request);
    assertEquals("v1.2", parser.getApiVersion());
    assertEquals("orcid-profile", parser.getCategory());
    assertNull(parser.getOrcidId());
}
Also used : ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Test(org.junit.Test)

Example 39 with ContainerRequest

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

the class APIEndpointParserTest method testAPIEndpointParserNoCategoryV1.

@Test
public void testAPIEndpointParserNoCategoryV1() {
    ContainerRequest request = getRequest("https://localhost:8443/orcid-api-web/v1.2/1234-4321-1234-4321");
    APIEndpointParser parser = new APIEndpointParser(request);
    assertEquals("v1.2", parser.getApiVersion());
    assertEquals("orcid-bio", parser.getCategory());
    assertEquals("1234-4321-1234-4321", parser.getOrcidId());
}
Also used : ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Test(org.junit.Test)

Example 40 with ContainerRequest

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

the class AnalyticsProcessTest method getRequest.

private ContainerRequest getRequest() {
    InBoundHeaders headers = new InBoundHeaders();
    headers.add(HttpHeaders.CONTENT_TYPE, "application/xml");
    headers.add(HttpHeaders.USER_AGENT, "blah");
    return new ContainerRequest(new WebApplicationImpl(), "POST", URI.create("https://localhost:8443/orcid-api-web/"), URI.create("https://localhost:8443/orcid-api-web/v2.0/1234-4321-1234-4321/works"), headers, null);
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) WebApplicationImpl(com.sun.jersey.server.impl.application.WebApplicationImpl) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest)

Aggregations

ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)43 Test (org.junit.Test)37 InBoundHeaders (com.sun.jersey.core.header.InBoundHeaders)16 WebApplication (com.sun.jersey.spi.container.WebApplication)10 ByteArrayInputStream (java.io.ByteArrayInputStream)10 URI (java.net.URI)9 OrcidBadRequestException (org.orcid.core.exception.OrcidBadRequestException)9 SimbaCredentials (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials)6 ContainerResponse (com.sun.jersey.spi.container.ContainerResponse)5 THttpClient (org.apache.thrift.transport.THttpClient)5 Client (org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client)5 RequestData (org.simbasecurity.api.service.thrift.RequestData)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 XForwardFilter (org.neo4j.server.web.XForwardFilter)4 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)4 ContainerRequestBuilderForTests (org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests)4 ActionDescriptorBuilderForTests (org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests)4 Before (org.junit.Before)3 SimbaCredentialsBuilderForTests (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests)3