Search in sources :

Example 51 with Api

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

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

the class ApiConfigValidatorTest method testApiMethodConfigWithApiMethodNameContainingStartingDot.

@Test
public void testApiMethodConfigWithApiMethodNameContainingStartingDot() throws Exception {
    @Api(name = "testApi", version = "v1", resource = "bar")
    final class Test {

        @ApiMethod(name = ".Api.TestMethod")
        public void test() {
        }
    }
    ApiConfig config = configLoader.loadConfiguration(ServiceContext.create(), Test.class);
    try {
        validator.validate(config);
        fail("Expected InvalidMethodNameException.");
    } catch (InvalidMethodNameException expected) {
    }
}
Also used : ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Example 53 with Api

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

the class ApiConfigValidatorTest method testInconsistentApiWideConfig.

@Test
public void testInconsistentApiWideConfig() throws Exception {
    @Api(name = "testApi", version = "v1", resource = "foo")
    final class Test1 {
    }
    ApiConfig config1 = configLoader.loadConfiguration(ServiceContext.create(), Test1.class);
    @Api(name = "testApi", version = "v1", resource = "bar")
    final class Test2 {
    }
    ApiConfig config2 = configLoader.loadConfiguration(ServiceContext.create(), Test2.class);
    try {
        validator.validate(Lists.newArrayList(config1, config2));
        fail("Expected InconsistentApiConfigurationException.");
    } catch (InconsistentApiConfigurationException expected) {
    }
}
Also used : ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Example 54 with Api

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

the class ApiConfigValidatorTest method testDifferentApisWithSameApiWideConfig.

@Test
public void testDifferentApisWithSameApiWideConfig() throws Exception {
    @Api(name = "testApi", version = "v1", resource = "foo")
    final class Test1 {
    }
    ApiConfig config1 = configLoader.loadConfiguration(ServiceContext.create(), Test1.class);
    @Api(name = "testApi", version = "v1", resource = "foo")
    @ApiClass(resource = "bar")
    final class Test2 {
    }
    ApiConfig config2 = configLoader.loadConfiguration(ServiceContext.create(), Test2.class);
    validator.validate(Lists.newArrayList(config1, config2));
}
Also used : ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Api(com.google.api.server.spi.config.Api) ApiClass(com.google.api.server.spi.config.ApiClass) Test(org.junit.Test)

Example 55 with Api

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

the class ApiConfigValidatorTest method testNonuniqueRestSignatures_multiClass.

@Test
public void testNonuniqueRestSignatures_multiClass() throws Exception {
    @Api
    class Foo {

        @ApiMethod(path = "path")
        public void foo() {
        }
    }
    ApiConfig config1 = configLoader.loadConfiguration(ServiceContext.create(), Foo.class);
    @Api
    class Bar {

        @ApiMethod(path = "path")
        public void bar() {
        }
    }
    ApiConfig config2 = configLoader.loadConfiguration(ServiceContext.create(), Bar.class);
    try {
        validator.validate(Lists.newArrayList(config1, config2));
        fail();
    } catch (DuplicateRestPathException expected) {
    }
}
Also used : ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Aggregations

Api (com.google.api.server.spi.config.Api)56 Test (org.junit.Test)55 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)45 ApiConfig (com.google.api.server.spi.config.model.ApiConfig)29 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)27 SimpleLevelOverridingInheritedApi (com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi)18 JsonNode (com.fasterxml.jackson.databind.JsonNode)16 Named (javax.inject.Named)15 ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)8 ApiParameterConfig (com.google.api.server.spi.config.model.ApiParameterConfig)7 DefaultValueSerializer (com.google.api.server.spi.testing.DefaultValueSerializer)4 Collection (java.util.Collection)4 Foo (com.google.api.server.spi.testing.Foo)3 List (java.util.List)3 TypeLoader (com.google.api.server.spi.TypeLoader)2 ApiFrontendLimits (com.google.api.server.spi.config.ApiFrontendLimits)2 Named (com.google.api.server.spi.config.Named)2 ApiKey (com.google.api.server.spi.config.model.ApiKey)2 ApiConfigValidator (com.google.api.server.spi.config.validation.ApiConfigValidator)2 Date (java.util.Date)2