Search in sources :

Example 1 with ApiCacheControlConfig

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

the class ApiConfigAnnotationReaderTest method validateEndpoint1.

private void validateEndpoint1(ApiConfig config, Class<? extends Endpoint1> clazz) throws Exception {
    assertEquals("api", config.getName());
    assertEquals("v1", config.getVersion());
    assertTrue(config.getIsDefaultVersion());
    assertFalse(config.getIsAbstract());
    assertTrue(config.getApiClassConfig().getUseDatastore());
    assertEquals(ImmutableList.of(PassAuthenticator.class), config.getAuthenticators());
    ApiAuthConfig auth = config.getAuthConfig();
    assertTrue(auth.getAllowCookieAuth());
    assertEquals(1, auth.getBlockedRegions().size());
    assertEquals("CU", auth.getBlockedRegions().get(0));
    ApiFrontendLimitsConfig frontendLimits = config.getFrontendLimitsConfig();
    assertEquals(1, frontendLimits.getUnregisteredUserQps());
    assertEquals(2, frontendLimits.getUnregisteredQps());
    assertEquals(3, frontendLimits.getUnregisteredDaily());
    // TODO: After fixing http://b/7459341, add check for number of rules.
    assertEquals("match0", frontendLimits.getRules().get(0).getMatch());
    assertEquals(1, frontendLimits.getRules().get(0).getQps());
    assertEquals(2, frontendLimits.getRules().get(0).getUserQps());
    assertEquals(3, frontendLimits.getRules().get(0).getDaily());
    assertEquals("analyticsId0", frontendLimits.getRules().get(0).getAnalyticsId());
    assertEquals("match10", frontendLimits.getRules().get(1).getMatch());
    assertEquals(11, frontendLimits.getRules().get(1).getQps());
    assertEquals(12, frontendLimits.getRules().get(1).getUserQps());
    assertEquals(13, frontendLimits.getRules().get(1).getDaily());
    assertEquals("analyticsId10", frontendLimits.getRules().get(1).getAnalyticsId());
    ApiCacheControlConfig cacheControl = config.getCacheControlConfig();
    assertEquals(ApiCacheControl.Type.PUBLIC, cacheControl.getType());
    assertEquals(1, cacheControl.getMaxAge());
    ApiSerializationConfig serialization = config.getSerializationConfig();
    assertEquals(1, serialization.getSerializerConfigs().size());
    ApiSerializationConfig.SerializerConfig serializerConfig = serialization.getSerializerConfig(TypeToken.of(SimpleBean.class));
    assertEquals(TypeToken.of(SimpleBean.class), serializerConfig.getSourceType());
    assertEquals(DumbSerializer1.class, serializerConfig.getSerializer());
    String[] defaultScopes = { "ss0", "ss1 ss2" };
    String[] defaultAudiences = { "aa0", "aa1" };
    String[] defaultClientIds = { "cc0", "cc1" };
    ApiMethodConfig listFoos = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.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(Endpoint1.class.getMethod("getFoo", String.class)));
    validateMethod(getFoo, "foos.get", "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 updateFoo = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.class.getMethod("updateFoo", String.class, Foo.class)));
    validateMethod(updateFoo, "foos.update", "foos/{id}", ApiMethod.HttpMethod.PUT, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
    assertEquals(2, updateFoo.getParameterConfigs().size());
    validateParameter(updateFoo.getParameterConfigs().get(0), "id", false, null, String.class);
    validateParameter(updateFoo.getParameterConfigs().get(1), null, false, null, Foo.class);
    ApiMethodConfig removeFoo = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.class.getMethod("removeFoo", String.class)));
    validateMethod(removeFoo, "foos.remove", "foos/{id}", ApiMethod.HttpMethod.DELETE, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
    assertEquals(1, removeFoo.getParameterConfigs().size());
    validateParameter(removeFoo.getParameterConfigs().get(0), "id", false, null, String.class);
    ApiMethodConfig execute0 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.class.getMethod("execute0", String.class, int.class, Integer.class, long.class, Long.class, boolean.class, Boolean.class, float.class, Double.class)));
    validateMethod(execute0, "foos.execute0", "execute0", "POST", defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
    assertEquals(9, execute0.getParameterConfigs().size());
    validateParameter(execute0.getParameterConfigs().get(0), "id", false, null, String.class);
    validateParameter(execute0.getParameterConfigs().get(1), "i0", false, null, int.class);
    validateParameter(execute0.getParameterConfigs().get(2), "i1", true, null, Integer.class);
    validateParameter(execute0.getParameterConfigs().get(3), "long0", false, null, long.class);
    validateParameter(execute0.getParameterConfigs().get(4), "long1", true, null, Long.class);
    validateParameter(execute0.getParameterConfigs().get(5), "b0", false, null, boolean.class);
    validateParameter(execute0.getParameterConfigs().get(6), "b1", true, null, Boolean.class);
    validateParameter(execute0.getParameterConfigs().get(7), "f", false, null, float.class);
    validateParameter(execute0.getParameterConfigs().get(8), "d", true, null, Double.class);
    ApiMethodConfig execute1 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.class.getMethod("execute1", Foo.class)));
    validateMethod(execute1, clazz.getSimpleName() + ".execute1", "execute1", ApiMethod.HttpMethod.POST, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
    assertEquals(1, execute1.getParameterConfigs().size());
    validateParameter(execute1.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, DumbSerializer1.class, String.class);
}
Also used : FailAuthenticator(com.google.api.server.spi.testing.FailAuthenticator) FailPeerAuthenticator(com.google.api.server.spi.testing.FailPeerAuthenticator) ApiCacheControlConfig(com.google.api.server.spi.config.model.ApiCacheControlConfig) ApiSerializationConfig(com.google.api.server.spi.config.model.ApiSerializationConfig) ApiAuthConfig(com.google.api.server.spi.config.model.ApiAuthConfig) 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) SimpleBean(com.google.api.server.spi.testing.SimpleBean) PassAuthenticator(com.google.api.server.spi.testing.PassAuthenticator)

Example 2 with ApiCacheControlConfig

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

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

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

the class ApiCacheControlAnnotationConfigTest method setUp.

@Before
public void setUp() throws Exception {
    config = new ApiCacheControlConfig();
    annotationConfig = new ApiCacheControlAnnotationConfig(config);
}
Also used : ApiCacheControlConfig(com.google.api.server.spi.config.model.ApiCacheControlConfig) Before(org.junit.Before)

Aggregations

ApiCacheControlConfig (com.google.api.server.spi.config.model.ApiCacheControlConfig)4 ApiAuthConfig (com.google.api.server.spi.config.model.ApiAuthConfig)3 ApiFrontendLimitsConfig (com.google.api.server.spi.config.model.ApiFrontendLimitsConfig)3 ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)3 PassAuthenticator (com.google.api.server.spi.testing.PassAuthenticator)3 PassPeerAuthenticator (com.google.api.server.spi.testing.PassPeerAuthenticator)3 ApiConfig (com.google.api.server.spi.config.model.ApiConfig)2 FailAuthenticator (com.google.api.server.spi.testing.FailAuthenticator)2 FailPeerAuthenticator (com.google.api.server.spi.testing.FailPeerAuthenticator)2 Test (org.junit.Test)2 ApiSerializationConfig (com.google.api.server.spi.config.model.ApiSerializationConfig)1 SimpleBean (com.google.api.server.spi.testing.SimpleBean)1 Before (org.junit.Before)1