Search in sources :

Example 6 with Named

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

the class ApiConfigAnnotationReaderTest method testSerializedParameter.

@Test
public void testSerializedParameter() throws Exception {
    @Api
    final class Test {

        @SuppressWarnings("unused")
        public void method(@Named("serialized") TestBean tb) {
        }
    }
    ApiConfig config = createConfig(Test.class);
    annotationReader.loadEndpointClass(serviceContext, Test.class, config);
    annotationReader.loadEndpointMethods(serviceContext, Test.class, config.getApiClassConfig().getMethods());
    ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Test.class.getMethod("method", TestBean.class)));
    validateMethod(methodConfig, "Test.method", "method/{serialized}", ApiMethod.HttpMethod.POST, DEFAULT_SCOPES, DEFAULT_AUDIENCES, DEFAULT_CLIENTIDS, null, null);
    validateParameter(methodConfig.getParameterConfigs().get(0), "serialized", false, null, TestBean.class, TestSerializer.class, String.class);
}
Also used : Named(com.google.api.server.spi.config.Named) 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) Test(org.junit.Test)

Example 7 with Named

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

the class ServletRequestParamReaderTest method testReadCollectionParameters.

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

        @SuppressWarnings("unused")
        public void collection(@Named("collection") Collection<Integer> integers) {
        }
    }
    Method method = Test.class.getDeclaredMethod("collection", Collection.class);
    doTestCollectionParameter("collection", EndpointMethod.create(Test.class, method));
}
Also used : Named(com.google.api.server.spi.config.Named) Test(org.junit.Test) Collection(java.util.Collection) Method(java.lang.reflect.Method) EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Example 8 with Named

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

the class ServletRequestParamReaderTest method testReadMultipleResourcesTest.

@Test
public void testReadMultipleResourcesTest() throws Exception {
    class TestMultipleResources {

        @SuppressWarnings("unused")
        public void foo(@Named("str") String string, @Named("integer_array") Integer[] integers, @Named("integer_collection") Collection<Integer> ints, Request request) {
        }
    }
    String requestString = "{\"str\":\"hello\",\"" + TestEndpoint.NAME_STRING + "\":\"" + VALUE_STRING + "\",\"" + TestEndpoint.NAME_INTEGER + "\":" + VALUE_INTEGER + ",\"integer_array\":[1,2,3]," + "\"integer_collection\":[4,5,6], \"stringValue\":" + "\"321\", \"integerValue\":321}";
    Method method = TestMultipleResources.class.getDeclaredMethod("foo", String.class, Integer[].class, Collection.class, Request.class);
    Object[] params = readParameters(requestString, method);
    assertEquals(4, params.length);
    String string = (String) params[0];
    assertEquals("hello", string);
    Integer[] integers = (Integer[]) params[1];
    assertEquals(3, integers.length);
    assertEquals(1, (int) integers[0]);
    assertEquals(2, (int) integers[1]);
    assertEquals(3, (int) integers[2]);
    @SuppressWarnings("unchecked") Collection<Integer> ints = (Collection<Integer>) params[2];
    assertEquals(3, ints.size());
    Iterator<Integer> iterator = ints.iterator();
    assertEquals(4, (int) iterator.next());
    assertEquals(5, (int) iterator.next());
    assertEquals(6, (int) iterator.next());
    Request request = (Request) params[3];
    assertEquals("321", request.getStringValue());
    assertEquals(321, (int) request.getIntegerValue());
}
Also used : Named(com.google.api.server.spi.config.Named) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(com.google.api.server.spi.testing.TestEndpoint.Request) Collection(java.util.Collection) Method(java.lang.reflect.Method) EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Example 9 with Named

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

the class ServletRequestParamReaderTest method testReadDateCollectionParameters.

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

        @SuppressWarnings("unused")
        public void collection(@Named("collection") Collection<Date> dates) {
        }
    }
    Method method = Test.class.getDeclaredMethod("collection", Collection.class);
    doTestReadCollectionDateParameter("collection", EndpointMethod.create(Test.class, method));
}
Also used : Named(com.google.api.server.spi.config.Named) Test(org.junit.Test) Collection(java.util.Collection) Method(java.lang.reflect.Method) EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Example 10 with Named

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

the class ServletRequestParamReaderTest method testReadNullArray.

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

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