Search in sources :

Example 1 with DefaultValueSerializer

use of com.google.api.server.spi.testing.DefaultValueSerializer 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 2 with DefaultValueSerializer

use of com.google.api.server.spi.testing.DefaultValueSerializer 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 3 with DefaultValueSerializer

use of com.google.api.server.spi.testing.DefaultValueSerializer 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 4 with DefaultValueSerializer

use of com.google.api.server.spi.testing.DefaultValueSerializer 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)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 Api (com.google.api.server.spi.config.Api)4 DefaultValueSerializer (com.google.api.server.spi.testing.DefaultValueSerializer)4 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)4 Test (org.junit.Test)4 Named (javax.inject.Named)2