use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testFrontendLimitsRulesNotDuplicatedInInheritance.
@Test
public void testFrontendLimitsRulesNotDuplicatedInInheritance() throws Exception {
@Api(frontendLimits = @ApiFrontendLimits(rules = { @ApiFrontendLimitRule(match = "test", qps = 1) }))
class Test {
}
final class Child extends Test {
}
ApiConfig config = createConfig(Child.class);
annotationReader.loadEndpointClass(serviceContext, Child.class, config);
assertEquals(1, config.getFrontendLimitsConfig().getRules().size());
}
use of com.google.api.server.spi.config.Api 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);
}
use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testGenericParameterTypes.
@Test
public void testGenericParameterTypes() throws Exception {
@Api
final class Test<T> {
@SuppressWarnings("unused")
public void setT(T t) {
}
}
ApiConfig config = createConfig(Test.class);
annotationReader.loadEndpointMethods(serviceContext, Test.class, config.getApiClassConfig().getMethods());
ApiParameterConfig parameter = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Test.class.getDeclaredMethod("setT", Object.class))).getParameterConfigs().get(0);
assertEquals(ApiParameterConfig.Classification.UNKNOWN, parameter.getClassification());
}
use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testParameterAnnotations_none.
@Test
public void testParameterAnnotations_none() throws Exception {
@Api
class Endpoint {
@SuppressWarnings("unused")
public void method(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, null, false, null, int.class, null, int.class);
}
use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testReadParametersInApiNamespace.
@Test
public void testReadParametersInApiNamespace() throws Exception {
@Api
class ValidNamespaceDefault {
}
ApiConfig config = createConfig(ValidNamespaceDefault.class);
annotationReader.loadEndpointClass(serviceContext, ValidNamespaceDefault.class, config);
@Api(namespace = @ApiNamespace(ownerDomain = "domain", ownerName = ""))
class BadNamespaceEmptyName {
}
config = createConfig(BadNamespaceEmptyName.class);
annotationReader.loadEndpointClass(serviceContext, BadNamespaceEmptyName.class, config);
assertEquals("domain", config.getNamespaceConfig().getOwnerDomain());
@Api(namespace = @ApiNamespace(ownerDomain = "", ownerName = "name"))
class BadNamespaceEmptyDomain {
}
config = createConfig(BadNamespaceEmptyDomain.class);
annotationReader.loadEndpointClass(serviceContext, BadNamespaceEmptyDomain.class, config);
assertEquals("name", config.getNamespaceConfig().getOwnerName());
@Api(namespace = @ApiNamespace(ownerDomain = "domain", ownerName = "name"))
class ValidNamespaceEmptyPackage {
}
config = createConfig(ValidNamespaceEmptyPackage.class);
annotationReader.loadEndpointClass(serviceContext, ValidNamespaceEmptyPackage.class, config);
assertEquals("domain", config.getNamespaceConfig().getOwnerDomain());
assertEquals("name", config.getNamespaceConfig().getOwnerName());
@Api(namespace = @ApiNamespace(ownerDomain = "domain", ownerName = "name", packagePath = "package"))
class ValidNamespaceFullySpecified {
}
config = createConfig(ValidNamespaceFullySpecified.class);
annotationReader.loadEndpointClass(serviceContext, ValidNamespaceFullySpecified.class, config);
assertEquals("domain", config.getNamespaceConfig().getOwnerDomain());
assertEquals("name", config.getNamespaceConfig().getOwnerName());
assertEquals("package", config.getNamespaceConfig().getPackagePath());
}
Aggregations