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());
}
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);
}
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());
}
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);
}
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());
}
Aggregations