Search in sources :

Example 31 with Api

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);
}
Also used : Named(javax.inject.Named) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) SimpleLevelOverridingApi(com.google.api.server.spi.testing.SimpleLevelOverridingApi) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Example 32 with Api

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");
}
Also used : Named(javax.inject.Named) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) List(java.util.List) JsonNode(com.fasterxml.jackson.databind.JsonNode) SimpleLevelOverridingApi(com.google.api.server.spi.testing.SimpleLevelOverridingApi) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Example 33 with Api

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");
}
Also used : Named(javax.inject.Named) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Collection(java.util.Collection) JsonNode(com.fasterxml.jackson.databind.JsonNode) SimpleLevelOverridingApi(com.google.api.server.spi.testing.SimpleLevelOverridingApi) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Example 34 with Api

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");
}
Also used : Named(javax.inject.Named) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultValueSerializer(com.google.api.server.spi.testing.DefaultValueSerializer) JsonNode(com.fasterxml.jackson.databind.JsonNode) SimpleLevelOverridingApi(com.google.api.server.spi.testing.SimpleLevelOverridingApi) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Example 35 with Api

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());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Test(org.junit.Test) SimpleLevelOverridingApi(com.google.api.server.spi.testing.SimpleLevelOverridingApi) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Aggregations

Api (com.google.api.server.spi.config.Api)56 Test (org.junit.Test)55 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)45 ApiConfig (com.google.api.server.spi.config.model.ApiConfig)29 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)27 SimpleLevelOverridingInheritedApi (com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi)18 JsonNode (com.fasterxml.jackson.databind.JsonNode)16 Named (javax.inject.Named)15 ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)8 ApiParameterConfig (com.google.api.server.spi.config.model.ApiParameterConfig)7 DefaultValueSerializer (com.google.api.server.spi.testing.DefaultValueSerializer)4 Collection (java.util.Collection)4 Foo (com.google.api.server.spi.testing.Foo)3 List (java.util.List)3 TypeLoader (com.google.api.server.spi.TypeLoader)2 ApiFrontendLimits (com.google.api.server.spi.config.ApiFrontendLimits)2 Named (com.google.api.server.spi.config.Named)2 ApiKey (com.google.api.server.spi.config.model.ApiKey)2 ApiConfigValidator (com.google.api.server.spi.config.validation.ApiConfigValidator)2 Date (java.util.Date)2