Search in sources :

Example 11 with Named

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

the class ServletRequestParamReaderTest method testReadEnumArrayParameters.

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

        @SuppressWarnings("unused")
        public void array(@Named("array") Outcome[] outcomes) {
        }
    }
    Method method = Test.class.getDeclaredMethod("array", Outcome[].class);
    doTestReadArrayEnumParameter("array", EndpointMethod.create(Test.class, method));
}
Also used : Named(com.google.api.server.spi.config.Named) Test(org.junit.Test) Method(java.lang.reflect.Method) EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Example 12 with Named

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

the class ServletRequestParamReaderTest method testReadNullList.

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

        @SuppressWarnings("unused")
        public void collection(@Nullable @Named("list") List<Integer> integers) {
        }
    }
    Method method = Test.class.getDeclaredMethod("collection", List.class);
    Object[] params = readParameters("{}", method);
    assertEquals(1, params.length);
    @SuppressWarnings("unchecked") List<Integer> integers = (List<Integer>) params[0];
    assertNull(integers);
}
Also used : Named(com.google.api.server.spi.config.Named) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) 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 13 with Named

use of com.google.api.server.spi.config.Named 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 14 with Named

use of com.google.api.server.spi.config.Named 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 15 with Named

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

the class ApiConfigAnnotationReaderTest method testParameterAnnotations.

@Test
public void testParameterAnnotations() throws Exception {
    @Api
    class Endpoint {

        @SuppressWarnings("unused")
        public void method(@Named("foo") @Nullable @DefaultValue("4") int foo) {
        }
    }
    ApiConfig config = createConfig(Endpoint.class);
    annotationReader.loadEndpointClass(serviceContext, Endpoint.class, config);
    annotationReader.loadEndpointMethods(serviceContext, Endpoint.class, config.getApiClassConfig().getMethods());
    ApiMethodConfig methodConfig = Iterables.getOnlyElement(config.getApiClassConfig().getMethods().values());
    ApiParameterConfig parameterConfig = Iterables.getOnlyElement(methodConfig.getParameterConfigs());
    validateParameter(parameterConfig, "foo", true, "4", int.class, null, int.class);
}
Also used : Named(com.google.api.server.spi.config.Named) DefaultValue(com.google.api.server.spi.config.DefaultValue) ApiParameterConfig(com.google.api.server.spi.config.model.ApiParameterConfig) ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) SimpleLevelOverridingApi(com.google.api.server.spi.testing.SimpleLevelOverridingApi) SimpleLevelOverridingInheritedApi(com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi) Api(com.google.api.server.spi.config.Api) Nullable(com.google.api.server.spi.config.Nullable) Test(org.junit.Test)

Aggregations

Named (com.google.api.server.spi.config.Named)15 Test (org.junit.Test)15 EndpointMethod (com.google.api.server.spi.EndpointMethod)13 Method (java.lang.reflect.Method)13 Nullable (com.google.api.server.spi.config.Nullable)5 Collection (java.util.Collection)4 Api (com.google.api.server.spi.config.Api)2 ApiConfig (com.google.api.server.spi.config.model.ApiConfig)2 ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)2 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)2 SimpleLevelOverridingInheritedApi (com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi)2 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 DefaultValue (com.google.api.server.spi.config.DefaultValue)1 ApiParameterConfig (com.google.api.server.spi.config.model.ApiParameterConfig)1 Request (com.google.api.server.spi.testing.TestEndpoint.Request)1 SimpleDate (com.google.api.server.spi.types.SimpleDate)1 Date (java.util.Date)1 Set (java.util.Set)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1