Search in sources :

Example 11 with ApiMethodConfig

use of com.google.api.server.spi.config.model.ApiMethodConfig 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 12 with ApiMethodConfig

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

the class ApiConfigAnnotationReaderTest method testMethodAuthDefaults.

@Test
public void testMethodAuthDefaults() throws Exception {
    // Default.
    @Api
    final class Test1 {

        @SuppressWarnings("unused")
        public void method() {
        }
    }
    ApiConfig config = createConfig(Test1.class);
    annotationReader.loadEndpointMethods(serviceContext, Test1.class, config.getApiClassConfig().getMethods());
    ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Test1.class.getMethod("method")));
    validateMethodForAuth(methodConfig, DEFAULT_SCOPES, DEFAULT_AUDIENCES, DEFAULT_CLIENTIDS, DEFAULT_AUTH_LEVEL);
    // Method explicitly set scopes, etc. empty.
    @Api
    final class Test2 {

        @SuppressWarnings("unused")
        @ApiMethod(scopes = {}, audiences = {}, clientIds = {})
        public void method() {
        }
    }
    config = createConfig(Test2.class);
    annotationReader.loadEndpointMethods(serviceContext, Test2.class, config.getApiClassConfig().getMethods());
    methodConfig = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Test2.class.getMethod("method")));
    String[] empty = {};
    validateMethodForAuth(methodConfig, empty, empty, empty, DEFAULT_AUTH_LEVEL);
    // Api explicitly set scopes, etc. empty.
    @Api(scopes = {}, audiences = {}, clientIds = {})
    final class Test3 {

        @SuppressWarnings("unused")
        public void method() {
        }
    }
    config = createConfig(Test3.class);
    annotationReader.loadEndpointClass(serviceContext, Test3.class, config);
    annotationReader.loadEndpointMethods(serviceContext, Test3.class, config.getApiClassConfig().getMethods());
    methodConfig = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Test3.class.getMethod("method")));
    validateMethodForAuth(methodConfig, empty, empty, empty, DEFAULT_AUTH_LEVEL);
    // Method explicitly set scopes, etc. empty and overwrite Api.
    @Api(scopes = { "s0", "s1 s2" }, audiences = { "a0", "a1" }, clientIds = { "c0", "c1" })
    final class Test4 {

        @SuppressWarnings("unused")
        @ApiMethod(scopes = {}, audiences = {}, clientIds = {})
        public void method() {
        }
    }
    config = createConfig(Test4.class);
    annotationReader.loadEndpointClass(serviceContext, Test4.class, config);
    annotationReader.loadEndpointMethods(serviceContext, Test4.class, config.getApiClassConfig().getMethods());
    methodConfig = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Test4.class.getMethod("method")));
    validateMethodForAuth(methodConfig, empty, empty, empty, DEFAULT_AUTH_LEVEL);
}
Also used : 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 13 with ApiMethodConfig

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

the class ApiConfigAnnotationReaderTest method testParameterAnnotations_javax.

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

        @SuppressWarnings("unused")
        public void method(@javax.inject.Named("foo") @javax.annotation.Nullable 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, null, int.class, null, int.class);
}
Also used : 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) Test(org.junit.Test)

Example 14 with ApiMethodConfig

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

the class ApiConfigAnnotationReaderTest method testParameterDescription.

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

        public void foo(@Description("desc") String param) {
        }
    }
    ApiConfig config = createConfig(TestParameterDescription.class);
    annotationReader.loadEndpointMethods(serviceContext, TestParameterDescription.class, config.getApiClassConfig().getMethods());
    ApiMethodConfig methodConfig = Iterables.getOnlyElement(config.getApiClassConfig().getMethods().values());
    ApiParameterConfig parameterConfig = Iterables.getOnlyElement(methodConfig.getParameterConfigs());
    assertEquals("desc", parameterConfig.getDescription());
}
Also used : ApiParameterConfig(com.google.api.server.spi.config.model.ApiParameterConfig) ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) Description(com.google.api.server.spi.config.Description) 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 15 with ApiMethodConfig

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

the class ApiConfigAnnotationReaderTest method implValidTestDefaultValuedParameter.

private <T> String implValidTestDefaultValuedParameter(Class<? extends DefaultValuedEndpoint<T>> clazz) throws Exception {
    ApiConfig config = createConfig(clazz);
    annotationReader.loadEndpointClass(serviceContext, clazz, config);
    annotationReader.loadEndpointMethods(serviceContext, clazz, config.getApiClassConfig().getMethods());
    ApiMethodConfig method = Iterables.getOnlyElement(config.getApiClassConfig().getMethods().values());
    String defaultValue = method.getParameterConfigs().get(0).getDefaultValue();
    assertNotNull(defaultValue);
    return defaultValue;
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) ApiConfig(com.google.api.server.spi.config.model.ApiConfig)

Aggregations

ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)54 Test (org.junit.Test)37 ApiConfig (com.google.api.server.spi.config.model.ApiConfig)26 EndpointMethod (com.google.api.server.spi.EndpointMethod)16 SimpleLevelOverridingInheritedApi (com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi)10 Api (com.google.api.server.spi.config.Api)8 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)8 User (com.google.api.server.spi.auth.common.User)5 PassAuthenticator (com.google.api.server.spi.testing.PassAuthenticator)5 PassPeerAuthenticator (com.google.api.server.spi.testing.PassPeerAuthenticator)5 ApiParameterConfig (com.google.api.server.spi.config.model.ApiParameterConfig)4 ApiAuthConfig (com.google.api.server.spi.config.model.ApiAuthConfig)3 ApiCacheControlConfig (com.google.api.server.spi.config.model.ApiCacheControlConfig)3 ApiFrontendLimitsConfig (com.google.api.server.spi.config.model.ApiFrontendLimitsConfig)3 Attribute (com.google.api.server.spi.request.Attribute)3 Named (com.google.api.server.spi.config.Named)2 ApiSerializationConfig (com.google.api.server.spi.config.model.ApiSerializationConfig)2 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)2 FailAuthenticator (com.google.api.server.spi.testing.FailAuthenticator)2 FailPeerAuthenticator (com.google.api.server.spi.testing.FailPeerAuthenticator)2