Search in sources :

Example 16 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testServiceWithMergedInheritance.

@Test
public void testServiceWithMergedInheritance() throws Exception {
    ApiConfig config = createConfig(SubclassedEndpoint.class);
    annotationReader.loadEndpointClass(serviceContext, SubclassedEndpoint.class, config);
    annotationReader.loadEndpointMethods(serviceContext, SubclassedEndpoint.class, config.getApiClassConfig().getMethods());
    validateEndpoint1(config, SubclassedEndpoint.class);
}
Also used : ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Test(org.junit.Test)

Example 17 with ApiConfig

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

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

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

the class ApiConfigAnnotationReaderTest method testServiceWithOverridingInterfaceReference.

@Test
public void testServiceWithOverridingInterfaceReference() throws Exception {
    ApiConfig config = createConfig(InterfaceReferenceEndpoint.class);
    annotationReader.loadEndpointClass(serviceContext, InterfaceReferenceEndpoint.class, config);
    assertEquals("interfaceBasedApi", config.getName());
    assertEquals("v2", config.getVersion());
}
Also used : ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Test(org.junit.Test)

Example 20 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testWildcardParameterTypes.

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

        @SuppressWarnings("unused")
        public void foo(Map<String, ? extends Integer> map) {
        }
    }
    try {
        ApiConfig config = createConfig(WildcardEndpoint.class);
        annotationReader.loadEndpointMethods(serviceContext, WildcardEndpoint.class, config.getApiClassConfig().getMethods());
        fail("Config generation for service class with wildcard parameter type should have failed");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : 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) Map(java.util.Map) Test(org.junit.Test)

Aggregations

ApiConfig (com.google.api.server.spi.config.model.ApiConfig)91 Test (org.junit.Test)72 Api (com.google.api.server.spi.config.Api)29 ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)26 SimpleLevelOverridingInheritedApi (com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi)20 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)18 ApiKey (com.google.api.server.spi.config.model.ApiKey)9 Swagger (io.swagger.models.Swagger)8 ApiParameterConfig (com.google.api.server.spi.config.model.ApiParameterConfig)7 TypeLoader (com.google.api.server.spi.TypeLoader)5 ApiConfigLoader (com.google.api.server.spi.config.ApiConfigLoader)4 ApiConfigValidator (com.google.api.server.spi.config.validation.ApiConfigValidator)4 ServiceContext (com.google.api.server.spi.ServiceContext)3 ApiConfigAnnotationReader (com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ApiClass (com.google.api.server.spi.config.ApiClass)2 ApiFrontendLimits (com.google.api.server.spi.config.ApiFrontendLimits)2 ApiReference (com.google.api.server.spi.config.ApiReference)2 Named (com.google.api.server.spi.config.Named)2 ApiAuthConfig (com.google.api.server.spi.config.model.ApiAuthConfig)2