use of com.google.api.server.spi.config.Named in project endpoints-java by cloudendpoints.
the class ServletRequestParamReaderTest method testReadEnumArrayParameters.
@Test
public void testReadEnumArrayParameters() throws Exception {
class Test {
@SuppressWarnings("unused")
public void array(@Named("array") Outcome[] outcomes) {
}
}
Method method = Test.class.getDeclaredMethod("array", Outcome[].class);
doTestReadArrayEnumParameter("array", EndpointMethod.create(Test.class, method));
}
use of com.google.api.server.spi.config.Named in project endpoints-java by cloudendpoints.
the class ServletRequestParamReaderTest method testReadNullList.
@Test
public void testReadNullList() throws Exception {
class Test {
@SuppressWarnings("unused")
public void collection(@Nullable @Named("list") List<Integer> integers) {
}
}
Method method = Test.class.getDeclaredMethod("collection", List.class);
Object[] params = readParameters("{}", method);
assertEquals(1, params.length);
@SuppressWarnings("unchecked") List<Integer> integers = (List<Integer>) params[0];
assertNull(integers);
}
use of com.google.api.server.spi.config.Named in project endpoints-java by cloudendpoints.
the class ServletRequestParamReaderTest method testCachedNamesAreUsed.
@Test
public void testCachedNamesAreUsed() throws Exception {
class Test {
@SuppressWarnings("unused")
public void foo(@Named("foo1") String f1, @Nullable @Named("foo2") String f2, @Named("foo3") String f3) {
}
}
Method method = Test.class.getDeclaredMethod("foo", String.class, String.class, String.class);
EndpointMethod endpointMethod = EndpointMethod.create(method.getDeclaringClass(), method);
endpointMethod.setParameterNames(ImmutableList.of("name1", "name2", "name3"));
String requestString = "{\"name1\":\"v1\", \"foo2\":\"v2\", \"name3\":\"v3\"}";
Object[] params = readParameters(requestString, endpointMethod);
assertEquals(3, params.length);
assertEquals("v1", params[0]);
assertNull(params[1]);
assertEquals("v3", params[2]);
}
use of com.google.api.server.spi.config.Named in project endpoints-java by cloudendpoints.
the class ServletRequestParamReaderTest method testNamesAreCached.
@Test
public void testNamesAreCached() throws Exception {
class Test {
@SuppressWarnings("unused")
public void foo(@Nullable @Named("foo1") String f1, @Nullable @Named("foo2") String f2, @Nullable @Named("foo3") String f3) {
}
}
Method method = Test.class.getDeclaredMethod("foo", String.class, String.class, String.class);
EndpointMethod endpointMethod = EndpointMethod.create(method.getDeclaringClass(), method);
readParameters("{}", endpointMethod);
List<String> parameterNames = endpointMethod.getParameterNames();
assertEquals(3, parameterNames.size());
assertEquals("foo1", parameterNames.get(0));
assertEquals("foo2", parameterNames.get(1));
assertEquals("foo3", parameterNames.get(2));
}
use of com.google.api.server.spi.config.Named 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);
}
Aggregations