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