Search in sources :

Example 1 with EndpointsContext

use of com.google.api.server.spi.EndpointsContext in project endpoints-java by cloudendpoints.

the class ExplorerHandlerTest method testHandle.

private void testHandle(String scheme, int port, String expectedLocation) throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setScheme(scheme);
    request.setServerName("localhost");
    request.setServerPort(port);
    request.setRequestURI("/_ah/api/explorer/");
    MockHttpServletResponse response = new MockHttpServletResponse();
    ExplorerHandler handler = new ExplorerHandler();
    EndpointsContext context = new EndpointsContext("GET", "explorer", request, response, true);
    handler.handle(context);
    assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_FOUND);
    assertThat(response.getHeader("Location")).isEqualTo(expectedLocation);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) EndpointsContext(com.google.api.server.spi.EndpointsContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 2 with EndpointsContext

use of com.google.api.server.spi.EndpointsContext in project endpoints-java by cloudendpoints.

the class EndpointsMethodHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    classLoader = EndpointsMethodHandlerTest.class.getClassLoader();
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    context = new EndpointsContext("", "", request, response, true);
    systemService = SystemService.builder().withDefaults(classLoader).addService(TestEndpoint.class, new TestEndpoint()).build();
    typeLoader = new TypeLoader(classLoader);
    apiConfig = new ApiConfig.Factory().create(ServiceContext.create(), typeLoader, TestEndpoint.class);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) EndpointsContext(com.google.api.server.spi.EndpointsContext) TypeLoader(com.google.api.server.spi.TypeLoader) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Before(org.junit.Before)

Example 3 with EndpointsContext

use of com.google.api.server.spi.EndpointsContext in project endpoints-java by cloudendpoints.

the class RestServletRequestParamReaderTest method createReader.

private RestServletRequestParamReader createReader(Map<String, String> rawPathParameters) {
    EndpointsContext endpointsContext = new EndpointsContext("GET", "/", request, new MockHttpServletResponse(), true);
    endpointsContext.setRawPathParameters(rawPathParameters);
    return new RestServletRequestParamReader(endpointMethod, endpointsContext, null, serializationConfig, methodConfig);
}
Also used : EndpointsContext(com.google.api.server.spi.EndpointsContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 4 with EndpointsContext

use of com.google.api.server.spi.EndpointsContext in project endpoints-java by cloudendpoints.

the class ApiProxyHandlerTest method testWithServletPath.

private void testWithServletPath(String servletPath) throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setServerName("localhost");
    request.setServerPort(8080);
    request.setServletPath(servletPath);
    MockHttpServletResponse response = new MockHttpServletResponse();
    ApiProxyHandler handler = new ApiProxyHandler();
    EndpointsContext context = new EndpointsContext("GET", "static/proxy.html", request, response, true);
    handler.handle(context);
    assertThat(response.getContentAsString()).contains("googleapis.server.init()");
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) EndpointsContext(com.google.api.server.spi.EndpointsContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Aggregations

EndpointsContext (com.google.api.server.spi.EndpointsContext)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 TypeLoader (com.google.api.server.spi.TypeLoader)1 Before (org.junit.Before)1