use of com.google.api.server.spi.config.Named 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.Named in project endpoints-java by cloudendpoints.
the class ServletRequestParamReaderTest method testReadCollectionParameters.
@Test
public void testReadCollectionParameters() throws Exception {
class Test {
@SuppressWarnings("unused")
public void collection(@Named("collection") Collection<Integer> integers) {
}
}
Method method = Test.class.getDeclaredMethod("collection", Collection.class);
doTestCollectionParameter("collection", EndpointMethod.create(Test.class, method));
}
use of com.google.api.server.spi.config.Named in project endpoints-java by cloudendpoints.
the class ServletRequestParamReaderTest method testReadMultipleResourcesTest.
@Test
public void testReadMultipleResourcesTest() throws Exception {
class TestMultipleResources {
@SuppressWarnings("unused")
public void foo(@Named("str") String string, @Named("integer_array") Integer[] integers, @Named("integer_collection") Collection<Integer> ints, Request request) {
}
}
String requestString = "{\"str\":\"hello\",\"" + TestEndpoint.NAME_STRING + "\":\"" + VALUE_STRING + "\",\"" + TestEndpoint.NAME_INTEGER + "\":" + VALUE_INTEGER + ",\"integer_array\":[1,2,3]," + "\"integer_collection\":[4,5,6], \"stringValue\":" + "\"321\", \"integerValue\":321}";
Method method = TestMultipleResources.class.getDeclaredMethod("foo", String.class, Integer[].class, Collection.class, Request.class);
Object[] params = readParameters(requestString, method);
assertEquals(4, params.length);
String string = (String) params[0];
assertEquals("hello", string);
Integer[] integers = (Integer[]) params[1];
assertEquals(3, integers.length);
assertEquals(1, (int) integers[0]);
assertEquals(2, (int) integers[1]);
assertEquals(3, (int) integers[2]);
@SuppressWarnings("unchecked") Collection<Integer> ints = (Collection<Integer>) params[2];
assertEquals(3, ints.size());
Iterator<Integer> iterator = ints.iterator();
assertEquals(4, (int) iterator.next());
assertEquals(5, (int) iterator.next());
assertEquals(6, (int) iterator.next());
Request request = (Request) params[3];
assertEquals("321", request.getStringValue());
assertEquals(321, (int) request.getIntegerValue());
}
use of com.google.api.server.spi.config.Named in project endpoints-java by cloudendpoints.
the class ServletRequestParamReaderTest method testReadDateCollectionParameters.
@Test
public void testReadDateCollectionParameters() throws Exception {
class Test {
@SuppressWarnings("unused")
public void collection(@Named("collection") Collection<Date> dates) {
}
}
Method method = Test.class.getDeclaredMethod("collection", Collection.class);
doTestReadCollectionDateParameter("collection", EndpointMethod.create(Test.class, method));
}
use of com.google.api.server.spi.config.Named in project endpoints-java by cloudendpoints.
the class ServletRequestParamReaderTest method testReadNullArray.
@Test
public void testReadNullArray() throws Exception {
class Test {
@SuppressWarnings("unused")
public void collection(@Nullable @Named("integer") Integer[] integers) {
}
}
Method method = Test.class.getDeclaredMethod("collection", Integer[].class);
Object[] params = readParameters("{}", method);
assertEquals(1, params.length);
@SuppressWarnings("unchecked") Integer[] integers = (Integer[]) params[0];
assertNull(integers);
}
Aggregations