Search in sources :

Example 21 with EndpointMethod

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

the class ServletRequestParamReaderTest method testCachedNamesAreUsed.

@Test
public void testCachedNamesAreUsed() throws Exception {
    class Test {

        @SuppressWarnings("unused")
        public void foo(@Named("foo1") String f1, @Nullable @Named("foo2") String f2, @Named("foo3") String f3) {
        }
    }
    Method method = Test.class.getDeclaredMethod("foo", String.class, String.class, String.class);
    EndpointMethod endpointMethod = EndpointMethod.create(method.getDeclaringClass(), method);
    endpointMethod.setParameterNames(ImmutableList.of("name1", "name2", "name3"));
    String requestString = "{\"name1\":\"v1\", \"foo2\":\"v2\", \"name3\":\"v3\"}";
    Object[] params = readParameters(requestString, endpointMethod);
    assertEquals(3, params.length);
    assertEquals("v1", params[0]);
    assertNull(params[1]);
    assertEquals("v3", params[2]);
}
Also used : Named(com.google.api.server.spi.config.Named) EndpointMethod(com.google.api.server.spi.EndpointMethod) Method(java.lang.reflect.Method) EndpointMethod(com.google.api.server.spi.EndpointMethod) Nullable(com.google.api.server.spi.config.Nullable) Test(org.junit.Test)

Example 22 with EndpointMethod

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

the class ServletRequestParamReaderTest method testNamesAreCached.

@Test
public void testNamesAreCached() throws Exception {
    class Test {

        @SuppressWarnings("unused")
        public void foo(@Nullable @Named("foo1") String f1, @Nullable @Named("foo2") String f2, @Nullable @Named("foo3") String f3) {
        }
    }
    Method method = Test.class.getDeclaredMethod("foo", String.class, String.class, String.class);
    EndpointMethod endpointMethod = EndpointMethod.create(method.getDeclaringClass(), method);
    readParameters("{}", endpointMethod);
    List<String> parameterNames = endpointMethod.getParameterNames();
    assertEquals(3, parameterNames.size());
    assertEquals("foo1", parameterNames.get(0));
    assertEquals("foo2", parameterNames.get(1));
    assertEquals("foo3", parameterNames.get(2));
}
Also used : Named(com.google.api.server.spi.config.Named) EndpointMethod(com.google.api.server.spi.EndpointMethod) Method(java.lang.reflect.Method) EndpointMethod(com.google.api.server.spi.EndpointMethod) Nullable(com.google.api.server.spi.config.Nullable) Test(org.junit.Test)

Example 23 with EndpointMethod

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

the class EndpointsMethodHandlerTest method createTestHandler.

private TestMethodHandler createTestHandler(String methodName, Object expectedResponse, Object... params) throws Exception {
    EndpointMethod method = systemService.resolveService("TestEndpoint", methodName);
    ApiMethodConfig methodConfig = new ApiMethodConfig(method, typeLoader, apiConfig.getApiClassConfig());
    return new TestMethodHandler(ServletInitializationParameters.builder().build(), method, methodConfig, systemService, expectedResponse, params);
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) EndpointMethod(com.google.api.server.spi.EndpointMethod)

Example 24 with EndpointMethod

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

the class ApiAnnotationConfigTest method testSetScopesIfSpecified_empty.

@Test
public void testSetScopesIfSpecified_empty() throws Exception {
    String[] empty = {};
    annotationConfig.setScopesIfSpecified(empty);
    EndpointMethod method = getResultNoParamsMethod();
    ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(method);
    assertEquals(toScopeExpression(), methodConfig.getScopeExpression());
    String[] scopes = { "bleh", "more bleh" };
    annotationConfig.setScopesIfSpecified(scopes);
    annotationConfig.setScopesIfSpecified(empty);
    assertEquals(toScopeExpression(), config.getScopeExpression());
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Example 25 with EndpointMethod

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

the class ApiAnnotationConfigTest method testSetClientIdsIfSpecified_empty.

@Test
public void testSetClientIdsIfSpecified_empty() throws Exception {
    String[] empty = {};
    annotationConfig.setClientIdsIfSpecified(empty);
    EndpointMethod method = getResultNoParamsMethod();
    ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(method);
    assertEquals(Collections.emptyList(), methodConfig.getClientIds());
    String[] clientIds = { "bleh", "more bleh" };
    annotationConfig.setClientIdsIfSpecified(clientIds);
    annotationConfig.setClientIdsIfSpecified(empty);
    assertEquals(Collections.emptyList(), config.getClientIds());
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Aggregations

EndpointMethod (com.google.api.server.spi.EndpointMethod)26 ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)14 Test (org.junit.Test)14 Method (java.lang.reflect.Method)6 Annotation (java.lang.annotation.Annotation)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Named (com.google.api.server.spi.config.Named)2 Nullable (com.google.api.server.spi.config.Nullable)2 ApiParameterConfig (com.google.api.server.spi.config.model.ApiParameterConfig)2 BadRequestException (com.google.api.server.spi.response.BadRequestException)2 TypeToken (com.google.common.reflect.TypeToken)2 Map (java.util.Map)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 MethodHierarchyReader (com.google.api.server.spi.MethodHierarchyReader)1 TypeLoader (com.google.api.server.spi.TypeLoader)1 EndpointsAuthenticator (com.google.api.server.spi.auth.EndpointsAuthenticator)1 EndpointsPeerAuthenticator (com.google.api.server.spi.auth.EndpointsPeerAuthenticator)1 User (com.google.api.server.spi.auth.common.User)1 Authenticator (com.google.api.server.spi.config.Authenticator)1