Search in sources :

Example 51 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testLevelOverridingWithClassOverrides.

@Test
public void testLevelOverridingWithClassOverrides() throws Exception {
    @ApiClass(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);
    assertEquals("resource2", config.getApiClassConfig().getResource());
    assertTrue(config.getApiClassConfig().getUseDatastore());
    annotationReader.loadEndpointMethods(serviceContext, Test.class, config.getApiClassConfig().getMethods());
    ApiMethodConfig noOverrides = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(SimpleLevelOverridingApi.class.getMethod("noOverrides")));
    assertEquals(toScopeExpression("s0c", "s1c"), noOverrides.getScopeExpression());
    assertEquals(Lists.newArrayList("a0c", "a1c"), noOverrides.getAudiences());
    assertEquals(Lists.newArrayList("c0c", "c1c"), noOverrides.getClientIds());
    ApiMethodConfig overrides = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(SimpleLevelOverridingApi.class.getMethod("overrides")));
    assertEquals(toScopeExpression("s0b", "s1b"), overrides.getScopeExpression());
    assertEquals(Lists.newArrayList("a0b", "a1b"), overrides.getAudiences());
    assertEquals(Lists.newArrayList("c0b", "c1b"), overrides.getClientIds());
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) SimpleLevelOverridingInheritedApi(com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) ApiClass(com.google.api.server.spi.config.ApiClass) Test(org.junit.Test)

Example 52 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testBoundedGenericEndpoint.

@Test
public void testBoundedGenericEndpoint() throws Exception {
    ApiConfig config = createConfig(BoundedGenericEndpoint.class);
    annotationReader.loadEndpointMethods(serviceContext, BoundedGenericEndpoint.class, config.getApiClassConfig().getMethods());
    assertEquals(1, config.getApiClassConfig().getMethods().size());
}
Also used : ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Test(org.junit.Test)

Example 53 with ApiConfig

use of com.google.api.server.spi.config.model.ApiConfig 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 54 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testFullyConfiguredEndpoint.

@Test
public void testFullyConfiguredEndpoint() throws Exception {
    ApiConfig config = createConfig(Endpoint1.class);
    annotationReader.loadEndpointClass(serviceContext, Endpoint1.class, config);
    annotationReader.loadEndpointMethods(serviceContext, Endpoint1.class, config.getApiClassConfig().getMethods());
    validateEndpoint1(config, Endpoint1.class);
}
Also used : ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Test(org.junit.Test)

Example 55 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testFrontendLimitsRuleWithSameMatchOverridesParentRule.

@Test
public void testFrontendLimitsRuleWithSameMatchOverridesParentRule() throws Exception {
    @Api(frontendLimits = @ApiFrontendLimits(rules = { @ApiFrontendLimitRule(match = "test", qps = 1) }))
    class Test {
    }
    @Api(frontendLimits = @ApiFrontendLimits(rules = { @ApiFrontendLimitRule(match = "test", userQps = 1) }))
    final class Child extends Test {
    }
    ApiConfig config = createConfig(Child.class);
    annotationReader.loadEndpointClass(serviceContext, Child.class, config);
    assertEquals(1, config.getFrontendLimitsConfig().getRules().size());
    FrontendLimitsRule rule = config.getFrontendLimitsConfig().getRules().get(0);
    assertEquals("test", rule.getMatch());
    assertEquals(-1, rule.getQps());
    assertEquals(1, rule.getUserQps());
}
Also used : FrontendLimitsRule(com.google.api.server.spi.config.model.ApiFrontendLimitsConfig.FrontendLimitsRule) 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)

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