Search in sources :

Example 6 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testMethodDescription.

@Test
public void testMethodDescription() throws Exception {
    @Api
    final class MethodDescriptionEndpoint {

        public void noAnnotation() {
        }

        @ApiMethod
        public void noDescription() {
        }

        @ApiMethod(description = "description")
        public void withDescription() {
        }
    }
    ApiConfig config = createConfig(MethodDescriptionEndpoint.class);
    annotationReader.loadEndpointMethods(serviceContext, MethodDescriptionEndpoint.class, config.getApiClassConfig().getMethods());
    ApiMethodConfig method1 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(MethodDescriptionEndpoint.class.getMethod("noAnnotation")));
    assertNull(method1.getDescription());
    ApiMethodConfig method2 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(MethodDescriptionEndpoint.class.getMethod("noDescription")));
    assertNull(method2.getDescription());
    ApiMethodConfig method3 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(MethodDescriptionEndpoint.class.getMethod("withDescription")));
    assertEquals("description", method3.getDescription());
}
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 7 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testServiceWithOverridingInheritance.

@Test
public void testServiceWithOverridingInheritance() throws Exception {
    ApiConfig config = createConfig(SubclassedOverridingEndpoint.class);
    annotationReader.loadEndpointClass(serviceContext, SubclassedOverridingEndpoint.class, config);
    assertEquals("api", config.getName());
    assertEquals("v2", config.getVersion());
    assertEquals("overridden description", config.getDescription());
    assertFalse(config.getIsDefaultVersion());
    assertFalse(config.getIsDiscoverable());
    assertFalse(config.getUseDatastore());
    ApiAuthConfig auth = config.getAuthConfig();
    assertTrue(auth.getAllowCookieAuth());
    ApiFrontendLimitsConfig frontendLimits = config.getFrontendLimitsConfig();
    assertEquals(1, frontendLimits.getUnregisteredUserQps());
    assertEquals(4, frontendLimits.getUnregisteredQps());
    ApiCacheControlConfig cacheControl = config.getCacheControlConfig();
    assertEquals(2, cacheControl.getMaxAge());
    assertEquals(ApiCacheControl.Type.PUBLIC, cacheControl.getType());
    annotationReader.loadEndpointMethods(serviceContext, SubclassedOverridingEndpoint.class, config.getApiClassConfig().getMethods());
    String[] defaultScopes = { "ss0a", "ss1a" };
    String[] defaultAudiences = { "aa0a", "aa1a" };
    String[] defaultClientIds = { "cc0a", "cc1a" };
    assertEquals(8, config.getApiClassConfig().getMethods().size());
    ApiMethodConfig listFoos = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(SubclassedOverridingEndpoint.class.getMethod("listFoos")));
    String[] expectedScopes = { "s0", "s1 s2" };
    String[] expectedAudiences = { "a0", "a1" };
    String[] expectedClientIds = { "c0", "c1" };
    validateMethod(listFoos, "foos.list", "foos", ApiMethod.HttpMethod.GET, expectedScopes, expectedAudiences, expectedClientIds, ImmutableList.of(FailAuthenticator.class), ImmutableList.of(FailPeerAuthenticator.class));
    assertEquals(0, listFoos.getParameterConfigs().size());
    ApiMethodConfig getFoo = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(SubclassedOverridingEndpoint.class.getMethod("getFoo", String.class)));
    validateMethod(getFoo, "foos.get2", "foos/{id}", ApiMethod.HttpMethod.GET, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
    assertEquals(1, getFoo.getParameterConfigs().size());
    validateParameter(getFoo.getParameterConfigs().get(0), "id", false, null, String.class);
    ApiMethodConfig insertFoo = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.class.getMethod("insertFoo", Foo.class)));
    validateMethod(insertFoo, "foos.insert", "foos", ApiMethod.HttpMethod.POST, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
    assertEquals(1, insertFoo.getParameterConfigs().size());
    validateParameter(insertFoo.getParameterConfigs().get(0), null, false, null, Foo.class);
    ApiMethodConfig execute2 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.class.getMethod("execute2", SimpleBean.class)));
    validateMethod(execute2, "foos.execute2", "execute2/{serialized}", ApiMethod.HttpMethod.POST, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
    assertEquals(1, execute2.getParameterConfigs().size());
    validateParameter(execute2.getParameterConfigs().get(0), "serialized", false, null, SimpleBean.class, DumbSerializer2.class, Integer.class);
}
Also used : FailAuthenticator(com.google.api.server.spi.testing.FailAuthenticator) ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) FailPeerAuthenticator(com.google.api.server.spi.testing.FailPeerAuthenticator) ApiFrontendLimitsConfig(com.google.api.server.spi.config.model.ApiFrontendLimitsConfig) PassPeerAuthenticator(com.google.api.server.spi.testing.PassPeerAuthenticator) PassAuthenticator(com.google.api.server.spi.testing.PassAuthenticator) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) ApiCacheControlConfig(com.google.api.server.spi.config.model.ApiCacheControlConfig) ApiAuthConfig(com.google.api.server.spi.config.model.ApiAuthConfig) Test(org.junit.Test)

Example 8 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testSimpleCovarianceEndpoint.

@Test
public void testSimpleCovarianceEndpoint() throws Exception {
    ApiConfig config = createConfig(SimpleCovarianceEndpoint.class);
    annotationReader.loadEndpointMethods(serviceContext, SimpleCovarianceEndpoint.class, config.getApiClassConfig().getMethods());
    ApiMethodConfig method1 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(SimpleCovarianceEndpoint.class.getMethod("foo", String.class)));
    assertEquals("api.foos.fn", method1.getName());
    ApiMethodConfig method2 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(SimpleCovarianceEndpoint.class.getSuperclass().getMethod("foo", Object.class)));
    assertEquals("api.foos.base", method2.getName());
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) SimpleCovarianceEndpoint(com.google.api.server.spi.testing.SimpleCovarianceEndpoint) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Test(org.junit.Test)

Example 9 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testBasicEndpoint.

@Test
public void testBasicEndpoint() throws Exception {
    ApiConfig config = createConfig(Endpoint0.class);
    annotationReader.loadEndpointClass(serviceContext, Endpoint0.class, config);
    assertEquals("api", config.getName());
    assertEquals(0, config.getApiClassConfig().getMethods().size());
    annotationReader.loadEndpointMethods(serviceContext, Endpoint0.class, config.getApiClassConfig().getMethods());
    assertEquals(1, config.getApiClassConfig().getMethods().size());
    ApiMethodConfig method = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint0.class.getMethod("getFoo", String.class)));
    validateMethod(method, "Endpoint0.getFoo", "foo/{id}", ApiMethod.HttpMethod.GET, DEFAULT_SCOPES, DEFAULT_AUDIENCES, DEFAULT_CLIENTIDS, null, null);
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Test(org.junit.Test)

Example 10 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testAbstract.

@Test
public void testAbstract() throws Exception {
    @Api(isAbstract = AnnotationBoolean.TRUE)
    class Test {
    }
    ApiConfig config = createConfig(Test.class);
    annotationReader.loadEndpointClass(serviceContext, Test.class, config);
    assertTrue(config.getIsAbstract());
}
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) 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