use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.
the class AnnotationApiConfigGeneratorTest method testValidEnumInParameter.
@Test
public void testValidEnumInParameter() throws Exception {
@Api
class EnumParameter {
@SuppressWarnings("unused")
public void pick(@Named("outcome") Outcome outcome) {
}
}
String apiConfigSource = g.generateConfig(EnumParameter.class).get("myapi-v1.api");
ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
JsonNode request = root.path("methods").path("myapi.enumParameter.pick").path("request");
verifyMethodRequestParameter(request, "outcome", "string", true, false, "WON", "LOST", "TIE");
assertTrue(root.path("descriptor").path("schemas").path("Outcome").isMissingNode());
verifyEmptyMethodRequest(root, EnumParameter.class.getName() + ".pick");
}
use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.
the class AnnotationApiConfigGeneratorTest method testSerializedEnum.
@Test
public void testSerializedEnum() throws Exception {
class OutcomeToIntegerSerializer extends DefaultValueSerializer<Outcome, Integer> {
}
@Api(transformers = { OutcomeToIntegerSerializer.class })
class EnumParameter {
@SuppressWarnings("unused")
public void foo(@Named("outcome") Outcome outcome) {
}
}
String apiConfigSource = g.generateConfig(EnumParameter.class).get("myapi-v1.api");
ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
JsonNode request = root.path("methods").path("myapi.enumParameter.foo").path("request");
verifyMethodRequestParameter(request, "outcome", "int32", true, false);
}
use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.
the class AnnotationApiConfigGeneratorTest method testCollectionRequest.
@Test
public void testCollectionRequest() throws Exception {
@Api
class BooleanCollection {
@SuppressWarnings("unused")
public void foo(@Named("collection") Collection<Boolean> b) {
}
}
String apiConfigSource = g.generateConfig(BooleanCollection.class).get("myapi-v1.api");
ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
JsonNode methodNode = root.path("methods").path("myapi.booleanCollection.foo");
assertFalse(methodNode.isMissingNode());
verifyMethodRequestParameter(methodNode.get("request"), "collection", "boolean", true, true);
}
use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.
the class AnnotationApiConfigGeneratorTest method testMethodPaths_apiAndMethodsAtCustomPaths.
@Test
public void testMethodPaths_apiAndMethodsAtCustomPaths() throws Exception {
@Api(resource = "foo")
class AcmeCo {
@ApiMethod(path = "foos")
public List<Foo> list() {
return null;
}
@SuppressWarnings("unused")
public List<Foo> listAllTheThings() {
return null;
}
@ApiMethod(path = "give")
public Foo giveMeOne() {
return null;
}
}
String apiConfigSource = g.generateConfig(AcmeCo.class).get("myapi-v1.api");
ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
verifyMethodPathAndHttpMethod(root, "myapi.foo.list", "foos", "GET");
verifyMethodPathAndHttpMethod(root, "myapi.foo.listAllTheThings", "foo", "GET");
verifyMethodPathAndHttpMethod(root, "myapi.foo.giveMeOne", "give", "POST");
}
use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.
the class AnnotationApiConfigGeneratorTest method testGenericArrayRequest.
@Test
public void testGenericArrayRequest() throws Exception {
@Api
abstract class GenericArray<T> {
@SuppressWarnings("unused")
public void foo(@Named("collection") T[] t) {
}
}
// TODO: remove with JDK8, dummy to force inclusion of GenericArray to InnerClass attribute
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=2210448
GenericArray<Integer> dummy = new GenericArray<Integer>() {
};
class Int32Array extends GenericArray<Integer> {
}
String apiConfigSource = g.generateConfig(Int32Array.class).get("myapi-v1.api");
ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
JsonNode methodNode = root.path("methods").path("myapi.int32Array.foo");
assertFalse(methodNode.isMissingNode());
verifyMethodRequestParameter(methodNode.get("request"), "collection", "int32", true, true);
}
Aggregations