Search in sources :

Example 36 with ApiMethodConfig

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

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

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

the class ApiConfigAnnotationReaderTest method verifySimpleLevelOverriding.

private void verifySimpleLevelOverriding(ApiConfig config) throws Exception {
    assertEquals("resource1", config.getApiClassConfig().getResource());
    assertFalse(config.getApiClassConfig().getUseDatastore());
    ApiMethodConfig noOverrides = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(SimpleLevelOverridingApi.class.getMethod("noOverrides")));
    assertEquals(toScopeExpression("s0a", "s1a"), noOverrides.getScopeExpression());
    assertEquals(Lists.newArrayList("a0a", "a1a"), noOverrides.getAudiences());
    assertEquals(Lists.newArrayList("c0a", "c1a"), noOverrides.getClientIds());
    assertEquals(AuthLevel.REQUIRED, noOverrides.getAuthLevel());
    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());
    assertEquals(AuthLevel.OPTIONAL, overrides.getAuthLevel());
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig)

Example 39 with ApiMethodConfig

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

the class ApiConfigAnnotationReaderTest method testLevelOverridingWithMethodOverrides.

@Test
public void testLevelOverridingWithMethodOverrides() throws Exception {
    final class Test extends SimpleLevelOverridingInheritedApi {

        @ApiMethod(scopes = { "s0c", "s1c" }, audiences = { "a0c", "a1c" }, clientIds = { "c0c", "c1c" })
        @Override
        public void overrides() {
            super.overrides();
        }
    }
    ApiConfig config = createConfig(Test.class);
    annotationReader.loadEndpointClass(serviceContext, Test.class, config);
    annotationReader.loadEndpointMethods(serviceContext, Test.class, config.getApiClassConfig().getMethods());
    ApiMethodConfig overrides = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Test.class.getMethod("overrides")));
    assertEquals(toScopeExpression("s0c", "s1c"), overrides.getScopeExpression());
    assertEquals(Lists.newArrayList("a0c", "a1c"), overrides.getAudiences());
    assertEquals(Lists.newArrayList("c0c", "c1c"), 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) Test(org.junit.Test)

Example 40 with ApiMethodConfig

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

the class ApiConfigValidator method validateRestSignatureUnique.

private void validateRestSignatureUnique(ApiMethodConfig methodConfig, Map<String, ApiMethodConfig> restfulSignatures) throws DuplicateRestPathException {
    String restSignature = methodConfig.getRestfulSignature();
    ApiMethodConfig seenMethod = restfulSignatures.get(restSignature);
    if (seenMethod == null) {
        restfulSignatures.put(restSignature, methodConfig);
    } else {
        throw new DuplicateRestPathException(methodConfig.getApiClassConfig(), restSignature, methodConfig.getName(), seenMethod.getName());
    }
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig)

Aggregations

ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)54 Test (org.junit.Test)37 ApiConfig (com.google.api.server.spi.config.model.ApiConfig)26 EndpointMethod (com.google.api.server.spi.EndpointMethod)16 SimpleLevelOverridingInheritedApi (com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi)10 Api (com.google.api.server.spi.config.Api)8 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)8 User (com.google.api.server.spi.auth.common.User)5 PassAuthenticator (com.google.api.server.spi.testing.PassAuthenticator)5 PassPeerAuthenticator (com.google.api.server.spi.testing.PassPeerAuthenticator)5 ApiParameterConfig (com.google.api.server.spi.config.model.ApiParameterConfig)4 ApiAuthConfig (com.google.api.server.spi.config.model.ApiAuthConfig)3 ApiCacheControlConfig (com.google.api.server.spi.config.model.ApiCacheControlConfig)3 ApiFrontendLimitsConfig (com.google.api.server.spi.config.model.ApiFrontendLimitsConfig)3 Attribute (com.google.api.server.spi.request.Attribute)3 Named (com.google.api.server.spi.config.Named)2 ApiSerializationConfig (com.google.api.server.spi.config.model.ApiSerializationConfig)2 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)2 FailAuthenticator (com.google.api.server.spi.testing.FailAuthenticator)2 FailPeerAuthenticator (com.google.api.server.spi.testing.FailPeerAuthenticator)2