Search in sources :

Example 1 with WebApplication

use of com.sun.jersey.spi.container.WebApplication 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();
    }
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) WebApplication(com.sun.jersey.spi.container.WebApplication) URI(java.net.URI) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) Test(org.junit.Test)

Example 2 with WebApplication

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

the class ApiVersionCheckFilterTest method api2_0_rc4VersionTest.

@Test
public void api2_0_rc4VersionTest() {
    MockHttpServletRequest mockReq = new MockHttpServletRequest();
    mockReq.setAttribute("X-Forwarded-Proto", "https");
    OrcidHttpServletRequestWrapper requestWrapper = new OrcidHttpServletRequestWrapper(mockReq);
    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/v2.0_rc4/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 = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "PUT", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "DELETE", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "GET", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) WebApplication(com.sun.jersey.spi.container.WebApplication) URI(java.net.URI) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) Test(org.junit.Test)

Example 3 with WebApplication

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

the class ApiVersionCheckFilterTest method apiOauthTokenTest.

@Test
public void apiOauthTokenTest() {
    MockHttpServletRequest mockReq = new MockHttpServletRequest();
    mockReq.setAttribute("X-Forwarded-Proto", "https");
    OrcidHttpServletRequestWrapper requestWrapper = new OrcidHttpServletRequestWrapper(mockReq);
    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/oauth/token");
    InBoundHeaders headers = new InBoundHeaders();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[0]);
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "POST", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) WebApplication(com.sun.jersey.spi.container.WebApplication) URI(java.net.URI) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) Test(org.junit.Test)

Example 4 with WebApplication

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

the class ApiVersionCheckFilterTest method api2_0VersionTest.

@Test
public void api2_0VersionTest() {
    MockHttpServletRequest mockReq = new MockHttpServletRequest();
    mockReq.setAttribute("X-Forwarded-Proto", "https");
    OrcidHttpServletRequestWrapper requestWrapper = new OrcidHttpServletRequestWrapper(mockReq);
    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/v2.0/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 = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "PUT", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "DELETE", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "GET", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) WebApplication(com.sun.jersey.spi.container.WebApplication) URI(java.net.URI) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) Test(org.junit.Test)

Example 5 with WebApplication

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

the class ApiVersionCheckFilterTest method api2_0_rc2VersionTest.

@Test
public void api2_0_rc2VersionTest() {
    MockHttpServletRequest mockReq = new MockHttpServletRequest();
    mockReq.setAttribute("X-Forwarded-Proto", "https");
    OrcidHttpServletRequestWrapper requestWrapper = new OrcidHttpServletRequestWrapper(mockReq);
    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/v2.0_rc2/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 = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "PUT", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "DELETE", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "GET", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) WebApplication(com.sun.jersey.spi.container.WebApplication) URI(java.net.URI) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) Test(org.junit.Test)

Aggregations

WebApplication (com.sun.jersey.spi.container.WebApplication)11 InBoundHeaders (com.sun.jersey.core.header.InBoundHeaders)10 ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)10 ByteArrayInputStream (java.io.ByteArrayInputStream)10 URI (java.net.URI)9 Test (org.junit.Test)9 OrcidBadRequestException (org.orcid.core.exception.OrcidBadRequestException)9 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 AnnisRunnerException (annis.AnnisRunnerException)1 MultipleIniWebEnvironment (annis.security.MultipleIniWebEnvironment)1 PackagesResourceConfig (com.sun.jersey.api.core.PackagesResourceConfig)1 ResourceConfig (com.sun.jersey.api.core.ResourceConfig)1 IoCComponentProviderFactory (com.sun.jersey.core.spi.component.ioc.IoCComponentProviderFactory)1 ServletContainer (com.sun.jersey.spi.container.servlet.ServletContainer)1 SpringComponentProviderFactory (com.sun.jersey.spi.spring.container.SpringComponentProviderFactory)1 InetSocketAddress (java.net.InetSocketAddress)1 DispatcherType (javax.servlet.DispatcherType)1 EnvironmentLoaderListener (org.apache.shiro.web.env.EnvironmentLoaderListener)1 Server (org.eclipse.jetty.server.Server)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1