Search in sources :

Example 46 with Api

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

the class ApiConfigAnnotationReaderTest method testFrontendLimitsRulesNotDuplicatedInInheritance.

@Test
public void testFrontendLimitsRulesNotDuplicatedInInheritance() throws Exception {
    @Api(frontendLimits = @ApiFrontendLimits(rules = { @ApiFrontendLimitRule(match = "test", qps = 1) }))
    class Test {
    }
    final class Child extends Test {
    }
    ApiConfig config = createConfig(Child.class);
    annotationReader.loadEndpointClass(serviceContext, Child.class, config);
    assertEquals(1, config.getFrontendLimitsConfig().getRules().size());
}
Also used : Test(org.junit.Test) ApiFrontendLimits(com.google.api.server.spi.config.ApiFrontendLimits) 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 47 with Api

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

the class ApiConfigAnnotationReaderTest method testParameterAnnotations.

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

        @SuppressWarnings("unused")
        public void method(@Named("foo") @Nullable @DefaultValue("4") 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, "4", int.class, null, int.class);
}
Also used : Named(com.google.api.server.spi.config.Named) DefaultValue(com.google.api.server.spi.config.DefaultValue) 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) Nullable(com.google.api.server.spi.config.Nullable) Test(org.junit.Test)

Example 48 with Api

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

the class ApiConfigAnnotationReaderTest method testGenericParameterTypes.

@Test
public void testGenericParameterTypes() throws Exception {
    @Api
    final class Test<T> {

        @SuppressWarnings("unused")
        public void setT(T t) {
        }
    }
    ApiConfig config = createConfig(Test.class);
    annotationReader.loadEndpointMethods(serviceContext, Test.class, config.getApiClassConfig().getMethods());
    ApiParameterConfig parameter = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Test.class.getDeclaredMethod("setT", Object.class))).getParameterConfigs().get(0);
    assertEquals(ApiParameterConfig.Classification.UNKNOWN, parameter.getClassification());
}
Also used : ApiParameterConfig(com.google.api.server.spi.config.model.ApiParameterConfig) 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 49 with Api

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

the class ApiConfigAnnotationReaderTest method testParameterAnnotations_none.

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

        @SuppressWarnings("unused")
        public void method(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, null, false, 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 50 with Api

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

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