Search in sources :

Example 81 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testDeepInheritanceCycleDetection.

@Test
public void testDeepInheritanceCycleDetection() throws Exception {
    // Nest the classes, so Java doesn't get upset about declaration/reference order.
    @ApiReference(Test1.Test2.class)
    @Api(name = "Test1")
    final class Test1 {

        @ApiReference(Test2.Test3.class)
        final class Test2 {

            @ApiReference(Test3.Test4.class)
            @Api(name = "Test3")
            final class Test3 {

                @ApiReference(Test4.Test5.class)
                final class Test4 {

                    @ApiReference(Test5.Test6.class)
                    @Api(name = "Test5")
                    final class Test5 {

                        @ApiReference(Test6.Test7.class)
                        final class Test6 {

                            @ApiReference(Test7.Test8.class)
                            @Api(name = "Test7")
                            final class Test7 {

                                @ApiReference(Test1.class)
                                final class Test8 {
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    try {
        ApiConfig config = createConfig(Test1.class);
        annotationReader.loadEndpointClass(serviceContext, Test1.class, config);
        fail();
    } catch (CyclicApiInheritanceException e) {
    // Expected.
    }
}
Also used : ApiReference(com.google.api.server.spi.config.ApiReference) 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 82 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testReadParametersInApiNamespace.

@Test
public void testReadParametersInApiNamespace() throws Exception {
    @Api
    class ValidNamespaceDefault {
    }
    ApiConfig config = createConfig(ValidNamespaceDefault.class);
    annotationReader.loadEndpointClass(serviceContext, ValidNamespaceDefault.class, config);
    @Api(namespace = @ApiNamespace(ownerDomain = "domain", ownerName = ""))
    class BadNamespaceEmptyName {
    }
    config = createConfig(BadNamespaceEmptyName.class);
    annotationReader.loadEndpointClass(serviceContext, BadNamespaceEmptyName.class, config);
    assertEquals("domain", config.getNamespaceConfig().getOwnerDomain());
    @Api(namespace = @ApiNamespace(ownerDomain = "", ownerName = "name"))
    class BadNamespaceEmptyDomain {
    }
    config = createConfig(BadNamespaceEmptyDomain.class);
    annotationReader.loadEndpointClass(serviceContext, BadNamespaceEmptyDomain.class, config);
    assertEquals("name", config.getNamespaceConfig().getOwnerName());
    @Api(namespace = @ApiNamespace(ownerDomain = "domain", ownerName = "name"))
    class ValidNamespaceEmptyPackage {
    }
    config = createConfig(ValidNamespaceEmptyPackage.class);
    annotationReader.loadEndpointClass(serviceContext, ValidNamespaceEmptyPackage.class, config);
    assertEquals("domain", config.getNamespaceConfig().getOwnerDomain());
    assertEquals("name", config.getNamespaceConfig().getOwnerName());
    @Api(namespace = @ApiNamespace(ownerDomain = "domain", ownerName = "name", packagePath = "package"))
    class ValidNamespaceFullySpecified {
    }
    config = createConfig(ValidNamespaceFullySpecified.class);
    annotationReader.loadEndpointClass(serviceContext, ValidNamespaceFullySpecified.class, config);
    assertEquals("domain", config.getNamespaceConfig().getOwnerDomain());
    assertEquals("name", config.getNamespaceConfig().getOwnerName());
    assertEquals("package", config.getNamespaceConfig().getPackagePath());
}
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) ApiNamespace(com.google.api.server.spi.config.ApiNamespace) Test(org.junit.Test)

Example 83 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testKnownParameterizedType.

@Test
public void testKnownParameterizedType() throws Exception {
    @Api
    class Bar<T1> {

        @SuppressWarnings("unused")
        public void bar(T1 t1) {
        }
    }
    class Foo extends Bar<Integer> {
    }
    ApiConfig config = createConfig(Foo.class);
    annotationReader.loadEndpointMethods(serviceContext, Foo.class, config.getApiClassConfig().getMethods());
    ApiParameterConfig parameter = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Foo.class.getSuperclass().getDeclaredMethod("bar", Object.class))).getParameterConfigs().get(0);
    assertEquals(ApiParameterConfig.Classification.API_PARAMETER, parameter.getClassification());
}
Also used : ApiParameterConfig(com.google.api.server.spi.config.model.ApiParameterConfig) Foo(com.google.api.server.spi.testing.Foo) 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 84 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testFullySpecializedDateEndpoint.

@Test
public void testFullySpecializedDateEndpoint() throws Exception {
    ApiConfig config = createConfig(RestfulResourceEndpointBase.FullySpecializedEndpoint.class);
    annotationReader.loadEndpointMethods(serviceContext, RestfulResourceEndpointBase.FullySpecializedEndpoint.class, config.getApiClassConfig().getMethods());
    assertEquals(6, config.getApiClassConfig().getMethods().size());
}
Also used : RestfulResourceEndpointBase(com.google.api.server.spi.testing.RestfulResourceEndpointBase) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Test(org.junit.Test)

Example 85 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testDeepGenericHierarchySuccessEndpoint.

@Test
public void testDeepGenericHierarchySuccessEndpoint() throws Exception {
    ApiConfig config = createConfig(DeepGenericHierarchySuccessEndpoint.class);
    annotationReader.loadEndpointMethods(serviceContext, DeepGenericHierarchySuccessEndpoint.class, config.getApiClassConfig().getMethods());
    assertEquals(1, config.getApiClassConfig().getMethods().size());
    assertNotNull(config.getApiClassConfig().getMethods().get(methodToEndpointMethod(DeepGenericHierarchySuccessEndpoint.class.getMethod("foo", String.class, Integer.class, Boolean.class))));
}
Also used : DeepGenericHierarchySuccessEndpoint(com.google.api.server.spi.testing.DeepGenericHierarchySuccessEndpoint) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) AnnotationBoolean(com.google.api.server.spi.config.AnnotationBoolean) 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