Search in sources :

Example 21 with Api

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

the class ApiConfigAnnotationReaderTest method testLevelOverridingWithDefaultOverrides.

@Test
public void testLevelOverridingWithDefaultOverrides() throws Exception {
    @Api(scopes = { "s0c", "s1c" }, audiences = { "a0c", "a1c" }, clientIds = { "c0c", "c1c" }, resource = "resource2", useDatastoreForAdditionalConfig = AnnotationBoolean.TRUE)
    final class Test extends SimpleLevelOverridingInheritedApi {
    }
    ApiConfig config = createConfig(Test.class);
    annotationReader.loadEndpointClass(serviceContext, Test.class, config);
    annotationReader.loadEndpointMethods(serviceContext, Test.class, config.getApiClassConfig().getMethods());
    // All values overridden at a lower level, so nothing should change.
    verifySimpleLevelOverriding(config);
}
Also used : SimpleLevelOverridingInheritedApi(com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi) 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 22 with Api

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

Example 23 with Api

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

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

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

the class ApiConfigValidatorTest method testApiMethodConfigWithApiMethodNameContainingSpecialCharacter.

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

        @ApiMethod(name = "Api.Test#Method")
        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)

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