Search in sources :

Example 76 with ApiConfig

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

the class JsonConfigWriterTest method writeConfigOrderIsPreserved.

@Test
public void writeConfigOrderIsPreserved() throws Exception {
    @Api(name = "onetoday", description = "OneToday API")
    final class OneToday {
    }
    @Api(name = "onetodayadmin", description = "One Today Admin API")
    final class OneTodayAdmin {
    }
    ApiConfigValidator validator = Mockito.mock(ApiConfigValidator.class);
    TypeLoader typeLoader = new TypeLoader();
    JsonConfigWriter writer = new JsonConfigWriter(new TypeLoader(JsonConfigWriter.class.getClassLoader()), validator);
    ApiConfig oneToday = new ApiConfig.Factory().create(serviceContext, typeLoader, OneToday.class);
    ApiConfig oneTodayAdmin = new ApiConfig.Factory().create(serviceContext, typeLoader, OneTodayAdmin.class);
    oneToday.setName("onetoday");
    oneToday.setVersion("v1");
    oneTodayAdmin.setName("onetodayadmin");
    oneTodayAdmin.setVersion("v1");
    Map<ApiKey, String> configs = writer.writeConfig(Lists.newArrayList(oneToday, oneTodayAdmin));
    Iterator<ApiKey> iterator = configs.keySet().iterator();
    assertEquals(new ApiKey("onetoday", "v1", "https://myapp.appspot.com/_ah/api"), iterator.next());
    assertEquals(new ApiKey("onetodayadmin", "v1", "https://myapp.appspot.com/_ah/api"), iterator.next());
}
Also used : ApiKey(com.google.api.server.spi.config.model.ApiKey) ApiConfigValidator(com.google.api.server.spi.config.validation.ApiConfigValidator) TypeLoader(com.google.api.server.spi.TypeLoader) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Example 77 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testEndpointWithBridgeMethods.

@Test
public void testEndpointWithBridgeMethods() throws Exception {
    ApiConfig config = createConfig(BridgeInheritanceEndpoint.class);
    annotationReader.loadEndpointClass(serviceContext, BridgeInheritanceEndpoint.class, config);
    annotationReader.loadEndpointMethods(serviceContext, BridgeInheritanceEndpoint.class, config.getApiClassConfig().getMethods());
    assertEquals(2, config.getApiClassConfig().getMethods().size());
    ApiMethodConfig fn1 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(BridgeInheritanceEndpoint.class.getMethod("fn1")));
    validateMethod(fn1, "api6.foos.fn1", "fn1", ApiMethod.HttpMethod.GET, DEFAULT_SCOPES, DEFAULT_AUDIENCES, DEFAULT_CLIENTIDS, null, null);
    ApiMethodConfig fn2 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(BridgeInheritanceEndpoint.class.getSuperclass().getMethod("fn2")));
    validateMethod(fn2, "api6.foos.fn2", "fn2", ApiMethod.HttpMethod.GET, DEFAULT_SCOPES, DEFAULT_AUDIENCES, DEFAULT_CLIENTIDS, null, null);
    ApiMethodConfig bridge = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(BridgeInheritanceEndpoint.class.getSuperclass().getMethod("fn1")));
    assertNull(bridge);
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) BridgeInheritanceEndpoint(com.google.api.server.spi.testing.BridgeInheritanceEndpoint) Test(org.junit.Test)

Example 78 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testSimpleOverrideEndpoint.

@Test
public void testSimpleOverrideEndpoint() throws Exception {
    ApiConfig config = createConfig(SimpleOverrideEndpoint.class);
    annotationReader.loadEndpointClass(serviceContext, SimpleOverrideEndpoint.class, config);
    annotationReader.loadEndpointMethods(serviceContext, SimpleOverrideEndpoint.class, config.getApiClassConfig().getMethods());
    assertEquals(1, config.getApiClassConfig().getMethods().size());
    ApiMethodConfig foo = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(SimpleOverrideEndpoint.class.getMethod("foo", String.class)));
    validateMethod(foo, "api.foos.fn", "fn", 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 79 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testServiceWithOverridingReference.

@Test
public void testServiceWithOverridingReference() throws Exception {
    ApiConfig config = createConfig(ReferenceOverridingEndpoint.class);
    annotationReader.loadEndpointClass(serviceContext, ReferenceOverridingEndpoint.class, config);
    assertEquals("api", config.getName());
    assertEquals("v3", config.getVersion());
    assertEquals("more overridden description", config.getDescription());
    assertTrue(config.getIsDefaultVersion());
    assertTrue(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, ReferenceOverridingEndpoint.class, config.getApiClassConfig().getMethods());
    String[] defaultScopes = { "ss0b", "ss1b" };
    String[] defaultAudiences = { "aa0b", "aa1b" };
    String[] defaultClientIds = { "cc0b", "cc1b" };
    assertEquals(8, config.getApiClassConfig().getMethods().size());
    ApiMethodConfig getFoo = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(ReferenceOverridingEndpoint.class.getMethod("getFoo", String.class)));
    validateMethod(getFoo, "foos.get3", "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);
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) 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 80 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testSimpleContravarianceEndpoint.

@Test
public void testSimpleContravarianceEndpoint() throws Exception {
    ApiConfig config = createConfig(SimpleContravarianceEndpoint.class);
    annotationReader.loadEndpointMethods(serviceContext, SimpleContravarianceEndpoint.class, config.getApiClassConfig().getMethods());
    ApiMethodConfig method1 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(SimpleContravarianceEndpoint.class.getMethod("foo", Object.class)));
    assertEquals("api.foos.fn", method1.getName());
    ApiMethodConfig method2 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(SimpleContravarianceEndpoint.class.getSuperclass().getMethod("foo", Number.class)));
    assertEquals("api.foos.base", method2.getName());
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) SimpleContravarianceEndpoint(com.google.api.server.spi.testing.SimpleContravarianceEndpoint) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) 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