use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.
the class AnnotationApiConfigGeneratorTest method testAbstract.
@Test
public void testAbstract() throws Exception {
@Api(isAbstract = AnnotationBoolean.TRUE)
class Test {
}
String apiConfigSource = g.generateConfig(Test.class).get("myapi-v1.api");
ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
assertTrue(root.get("abstract").asBoolean());
}
use of com.google.api.server.spi.config.Api 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());
}
use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.
the class JsonConfigWriterTest method writeConfigOrderIsPreservedMulticlass.
@Test
public void writeConfigOrderIsPreservedMulticlass() throws Exception {
@Api(name = "onetoday", description = "OneToday API")
final class OneToday {
}
@Api(name = "onetoday", description = "OneToday API")
final class OneToday2 {
}
@Api(name = "onetodayadmin", description = "One Today Admin API")
final class OneTodayAdmin {
}
@Api(name = "onetodayadmin", description = "One Today Admin API")
final class OneTodayAdmin2 {
}
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 oneToday2 = new ApiConfig.Factory().create(serviceContext, typeLoader, OneToday2.class);
ApiConfig oneTodayAdmin = new ApiConfig.Factory().create(serviceContext, typeLoader, OneTodayAdmin.class);
ApiConfig oneTodayAdmin2 = new ApiConfig.Factory().create(serviceContext, typeLoader, OneTodayAdmin2.class);
oneToday.setName("onetoday");
oneToday.setVersion("v1");
oneToday2.setName("onetoday");
oneToday2.setVersion("v1");
oneTodayAdmin.setName("onetodayadmin");
oneTodayAdmin.setVersion("v1");
oneTodayAdmin2.setName("onetodayadmin");
oneTodayAdmin2.setVersion("v1");
Map<ApiKey, String> configs = writer.writeConfig(Lists.newArrayList(oneToday, oneTodayAdmin, oneTodayAdmin2, oneToday2));
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.Api 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.Api in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testKnownParameterizedType.
@Test
public void testKnownParameterizedType() throws Exception {
@Api
class Bar<T1> {
@SuppressWarnings("unused")
public void bar(T1 t1) {
}
}
class Foo extends Bar<Integer> {
}
ApiConfig config = createConfig(Foo.class);
annotationReader.loadEndpointMethods(serviceContext, Foo.class, config.getApiClassConfig().getMethods());
ApiParameterConfig parameter = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Foo.class.getSuperclass().getDeclaredMethod("bar", Object.class))).getParameterConfigs().get(0);
assertEquals(ApiParameterConfig.Classification.API_PARAMETER, parameter.getClassification());
}
Aggregations