Search in sources :

Example 36 with Api

use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.

the class AnnotationApiConfigGeneratorTest method testMethodPaths_inheritanceResourceSpecified.

@Test
public void testMethodPaths_inheritanceResourceSpecified() throws Exception {
    @Api(resource = "foos")
    class Foos extends GenFoos<Foo> {
    }
    String apiConfigSource = g.generateConfig(Foos.class).get("myapi-v1.api");
    ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
    GenFoos.verifyMethodPathsAndHttpMethods(Foos.class, "foos", root, "foos");
}
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 37 with Api

use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.

the class AnnotationApiConfigGeneratorTest method testArrayOfSerializedResources.

@Test
public void testArrayOfSerializedResources() throws Exception {
    @Api
    class ResourceCollection {

        @SuppressWarnings("unused")
        public void foo(@Named("beans") List<StringBean> beans) {
        }
    }
    String apiConfigSource = g.generateConfig(ResourceCollection.class).get("myapi-v1.api");
    ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
    JsonNode methodNode = root.path("methods").path("myapi.resourceCollection.foo");
    assertFalse(methodNode.isMissingNode());
    verifyMethodRequestParameter(methodNode.get("request"), "beans", "string", true, true);
}
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 38 with Api

use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.

the class AnnotationApiConfigGeneratorTest method testGenericCollectionRequest.

@Test
public void testGenericCollectionRequest() throws Exception {
    @Api
    abstract class GenericCollection<T> {

        @SuppressWarnings("unused")
        public void foo(@Named("collection") 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
    GenericCollection<Long> dummy = new GenericCollection<Long>() {
    };
    class Int64Collection extends GenericCollection<Long> {
    }
    String apiConfigSource = g.generateConfig(Int64Collection.class).get("myapi-v1.api");
    ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
    JsonNode methodNode = root.path("methods").path("myapi.int64Collection.foo");
    assertFalse(methodNode.isMissingNode());
    verifyMethodRequestParameter(methodNode.get("request"), "collection", "int64", 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 39 with Api

use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.

the class AnnotationApiConfigGeneratorTest method testChainedSerializer.

@Test
public void testChainedSerializer() throws Exception {
    class BarToBazSerializer extends DefaultValueSerializer<Bar, Baz> {
    }
    class BazToDateSerializer extends DefaultValueSerializer<Baz, Date> {
    }
    class Qux {

        @SuppressWarnings("unused")
        public Bar getSomeBar() {
            return null;
        }
    }
    @Api(transformers = { BazToDateSerializer.class, BarToBazSerializer.class })
    class QuxEndpoint {

        @SuppressWarnings("unused")
        public Qux getQux() {
            return null;
        }
    }
    String apiConfigSource = g.generateConfig(QuxEndpoint.class).get("myapi-v1.api");
    ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
    JsonNode qux = root.path("descriptor").path("schemas").path("Qux");
    verifyObjectPropertySchema(qux, "someBar", "string", "date-time");
}
Also used : 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 40 with Api

use of com.google.api.server.spi.config.Api in project endpoints-java by cloudendpoints.

the class AnnotationApiConfigGeneratorTest method testMultipleCollectionRequests.

@Test
public void testMultipleCollectionRequests() throws Exception {
    @Api
    class MultipleCollections {

        @SuppressWarnings("unused")
        public void foo(@Named("ids") Long[] ids, @Named("authors") List<String> authors) {
        }
    }
    String apiConfigSource = g.generateConfig(MultipleCollections.class).get("myapi-v1.api");
    ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
    JsonNode methodNode = root.path("methods").path("myapi.multipleCollections.foo");
    assertFalse(methodNode.isMissingNode());
    verifyMethodRequestParameter(methodNode.get("request"), "ids", "int64", true, true);
    verifyMethodRequestParameter(methodNode.get("request"), "authors", "string", true, true);
}
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)

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