use of com.google.api.server.spi.config.model.ApiMethodConfig in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testSerializedParameter.
@Test
public void testSerializedParameter() throws Exception {
@Api
final class Test {
@SuppressWarnings("unused")
public void method(@Named("serialized") TestBean tb) {
}
}
ApiConfig config = createConfig(Test.class);
annotationReader.loadEndpointClass(serviceContext, Test.class, config);
annotationReader.loadEndpointMethods(serviceContext, Test.class, config.getApiClassConfig().getMethods());
ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Test.class.getMethod("method", TestBean.class)));
validateMethod(methodConfig, "Test.method", "method/{serialized}", ApiMethod.HttpMethod.POST, DEFAULT_SCOPES, DEFAULT_AUDIENCES, DEFAULT_CLIENTIDS, null, null);
validateParameter(methodConfig.getParameterConfigs().get(0), "serialized", false, null, TestBean.class, TestSerializer.class, String.class);
}
use of com.google.api.server.spi.config.model.ApiMethodConfig in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testMethodAuthDefaults.
@Test
public void testMethodAuthDefaults() throws Exception {
// Default.
@Api
final class Test1 {
@SuppressWarnings("unused")
public void method() {
}
}
ApiConfig config = createConfig(Test1.class);
annotationReader.loadEndpointMethods(serviceContext, Test1.class, config.getApiClassConfig().getMethods());
ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Test1.class.getMethod("method")));
validateMethodForAuth(methodConfig, DEFAULT_SCOPES, DEFAULT_AUDIENCES, DEFAULT_CLIENTIDS, DEFAULT_AUTH_LEVEL);
// Method explicitly set scopes, etc. empty.
@Api
final class Test2 {
@SuppressWarnings("unused")
@ApiMethod(scopes = {}, audiences = {}, clientIds = {})
public void method() {
}
}
config = createConfig(Test2.class);
annotationReader.loadEndpointMethods(serviceContext, Test2.class, config.getApiClassConfig().getMethods());
methodConfig = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Test2.class.getMethod("method")));
String[] empty = {};
validateMethodForAuth(methodConfig, empty, empty, empty, DEFAULT_AUTH_LEVEL);
// Api explicitly set scopes, etc. empty.
@Api(scopes = {}, audiences = {}, clientIds = {})
final class Test3 {
@SuppressWarnings("unused")
public void method() {
}
}
config = createConfig(Test3.class);
annotationReader.loadEndpointClass(serviceContext, Test3.class, config);
annotationReader.loadEndpointMethods(serviceContext, Test3.class, config.getApiClassConfig().getMethods());
methodConfig = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Test3.class.getMethod("method")));
validateMethodForAuth(methodConfig, empty, empty, empty, DEFAULT_AUTH_LEVEL);
// Method explicitly set scopes, etc. empty and overwrite Api.
@Api(scopes = { "s0", "s1 s2" }, audiences = { "a0", "a1" }, clientIds = { "c0", "c1" })
final class Test4 {
@SuppressWarnings("unused")
@ApiMethod(scopes = {}, audiences = {}, clientIds = {})
public void method() {
}
}
config = createConfig(Test4.class);
annotationReader.loadEndpointClass(serviceContext, Test4.class, config);
annotationReader.loadEndpointMethods(serviceContext, Test4.class, config.getApiClassConfig().getMethods());
methodConfig = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Test4.class.getMethod("method")));
validateMethodForAuth(methodConfig, empty, empty, empty, DEFAULT_AUTH_LEVEL);
}
use of com.google.api.server.spi.config.model.ApiMethodConfig in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testParameterAnnotations_javax.
@Test
public void testParameterAnnotations_javax() throws Exception {
@Api
class Endpoint {
@SuppressWarnings("unused")
public void method(@javax.inject.Named("foo") @javax.annotation.Nullable 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, null, int.class, null, int.class);
}
use of com.google.api.server.spi.config.model.ApiMethodConfig in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testParameterDescription.
@Test
public void testParameterDescription() throws Exception {
@Api
final class TestParameterDescription {
public void foo(@Description("desc") String param) {
}
}
ApiConfig config = createConfig(TestParameterDescription.class);
annotationReader.loadEndpointMethods(serviceContext, TestParameterDescription.class, config.getApiClassConfig().getMethods());
ApiMethodConfig methodConfig = Iterables.getOnlyElement(config.getApiClassConfig().getMethods().values());
ApiParameterConfig parameterConfig = Iterables.getOnlyElement(methodConfig.getParameterConfigs());
assertEquals("desc", parameterConfig.getDescription());
}
use of com.google.api.server.spi.config.model.ApiMethodConfig in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method implValidTestDefaultValuedParameter.
private <T> String implValidTestDefaultValuedParameter(Class<? extends DefaultValuedEndpoint<T>> clazz) throws Exception {
ApiConfig config = createConfig(clazz);
annotationReader.loadEndpointClass(serviceContext, clazz, config);
annotationReader.loadEndpointMethods(serviceContext, clazz, config.getApiClassConfig().getMethods());
ApiMethodConfig method = Iterables.getOnlyElement(config.getApiClassConfig().getMethods().values());
String defaultValue = method.getParameterConfigs().get(0).getDefaultValue();
assertNotNull(defaultValue);
return defaultValue;
}
Aggregations