Search in sources :

Example 1 with Api

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

the class AnnotationApiConfigGeneratorTest method testSerializedPropertyInResourceSchema.

@Test
public void testSerializedPropertyInResourceSchema() throws Exception {
    class BazToDateSerializer extends DefaultValueSerializer<Baz, Date> {
    }
    @Api(transformers = { BazToDateSerializer.class, BarResourceSerializer.class })
    class BarEndpoint {

        @SuppressWarnings("unused")
        public Bar getBar() {
            return null;
        }
    }
    String apiConfigSource = g.generateConfig(BarEndpoint.class).get("myapi-v1.api");
    ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
    JsonNode bar = root.path("descriptor").path("schemas").path("Bar");
    verifyObjectPropertySchema(bar, "someBaz", "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 2 with Api

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

the class AnnotationApiConfigGeneratorTest method testMethodPaths_inheritanceResourceInheritedAndSpecified.

@Test
public void testMethodPaths_inheritanceResourceInheritedAndSpecified() throws Exception {
    @Api(resource = "foos")
    class Foos extends GenBars<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 3 with Api

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

the class AnnotationApiConfigGeneratorTest method testValidDateInParameter.

@Test
public void testValidDateInParameter() throws Exception {
    @Api
    class DateParameter {

        @SuppressWarnings("unused")
        public void foo(@Named("date") Date date) {
        }
    }
    String apiConfigSource = g.generateConfig(DateParameter.class).get("myapi-v1.api");
    ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
    JsonNode request = root.path("methods").path("myapi.dateParameter.foo").path("request");
    verifyMethodRequestParameter(request, "date", "datetime", true, false);
    assertTrue(root.path("descriptor").path("schemas").path("Outcome").isMissingNode());
    verifyEmptyMethodRequest(root, DateParameter.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) Date(java.util.Date) Test(org.junit.Test)

Example 4 with Api

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

the class AnnotationApiConfigGeneratorTest method testTitle.

@Test
public void testTitle() throws Exception {
    @Api(name = "myapi", title = "My API Title")
    class ApiWithTitle {
    }
    String apiConfigSource = g.generateConfig(ApiWithTitle.class).get("myapi-v1.api");
    ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
    assertEquals("myapi", root.path("name").asText());
    assertEquals("My API Title", root.path("title").asText());
}
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 5 with Api

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

the class AnnotationApiConfigGeneratorTest method testMethodPaths_apiAtCustomPath.

@Test
public void testMethodPaths_apiAtCustomPath() throws Exception {
    @SuppressWarnings("unused")
    @Api(resource = "foos")
    class Foos {

        public List<Foo> list() {
            return null;
        }

        public Foo get(@Named("id") Long id) {
            return null;
        }
    }
    String apiConfigSource = g.generateConfig(Foos.class).get("myapi-v1.api");
    ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
    verifyMethodPathAndHttpMethod(root, "myapi.foos.list", "foos", "GET");
    verifyMethodPathAndHttpMethod(root, "myapi.foos.get", "foos/{id}", "GET");
}
Also used : Named(javax.inject.Named) 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)

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