use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.
the class AnnotationApiConfigGeneratorTest method testArrayRequest.
@Test
public void testArrayRequest() throws Exception {
@Api
class StringArray {
@SuppressWarnings("unused")
public void foo(@Named("collection") String[] s) {
}
}
String apiConfigSource = g.generateConfig(StringArray.class).get("myapi-v1.api");
ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
JsonNode methodNode = root.path("methods").path("myapi.stringArray.foo");
assertFalse(methodNode.isMissingNode());
verifyMethodRequestParameter(methodNode.get("request"), "collection", "string", true, true);
}
use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.
the class AnnotationApiConfigGeneratorTest method testResourceAndCollection.
@Test
public void testResourceAndCollection() throws Exception {
@Api
class ResourceAndCollection {
@SuppressWarnings("unused")
public void foo(Bean resource, @Named("authors") List<String> authors) {
}
}
String apiConfigSource = g.generateConfig(ResourceAndCollection.class).get("myapi-v1.api");
ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
JsonNode methodNode = root.path("methods").path("myapi.resourceAndCollection.foo");
assertFalse(methodNode.isMissingNode());
verifyMethodRequestParameter(methodNode.get("request"), "authors", "string", true, true);
assertEquals(1, methodNode.path("request").path("parameters").size());
verifyMethodRequestRef(root, ResourceAndCollection.class.getName() + ".foo", "Bean");
}
use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.
the class AnnotationApiConfigGeneratorTest method testEnumCollection.
@Test
public void testEnumCollection() throws Exception {
@Api
class EnumParameters {
@SuppressWarnings("unused")
public void foo(@Named("outcome") Outcome outcome, @Named("outcomes1") Collection<Outcome> outcomes1, @Named("outcomes2") Outcome[] outcomes2) {
}
}
String apiConfigSource = g.generateConfig(EnumParameters.class).get("myapi-v1.api");
ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
JsonNode request = root.path("methods").path("myapi.enumParameters.foo").path("request");
verifyMethodRequestParameter(request, "outcome", "string", true, false, "WON", "LOST", "TIE");
verifyMethodRequestParameter(request, "outcomes1", "string", true, true, "WON", "LOST", "TIE");
verifyMethodRequestParameter(request, "outcomes2", "string", true, true, "WON", "LOST", "TIE");
assertTrue(root.path("descriptor").path("schemas").path("Outcome").isMissingNode());
verifyEmptyMethodRequest(root, EnumParameters.class.getName() + ".foo");
}
use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.
the class AnnotationApiConfigGeneratorTest method testNonSerializedEnumShouldAlwaysBeString.
@Test
public void testNonSerializedEnumShouldAlwaysBeString() throws Exception {
class StringToIntegerSerializer extends DefaultValueSerializer<String, Integer> {
}
@Api(transformers = { StringToIntegerSerializer.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", "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 testAnonymousClass.
@Test
public void testAnonymousClass() throws Exception {
@Api()
class Test {
@SuppressWarnings("unused")
public void test() {
}
}
String apiConfigSource = g.generateConfig(new Test() {
}.getClass()).get("myapi-v1.api");
ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
assertEquals("test", root.path("methods").path("myapi.test").path("path").asText());
}
Aggregations