Search in sources :

Example 11 with Api

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");
}
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 12 with Api

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);
}
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 13 with Api

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);
}
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 14 with Api

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

Example 15 with Api

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);
}
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)

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