Search in sources :

Example 41 with Named

use of javax.inject.Named 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 42 with Named

use of javax.inject.Named 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 43 with Named

use of javax.inject.Named 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 44 with Named

use of javax.inject.Named 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 45 with Named

use of javax.inject.Named in project endpoints-java by cloudendpoints.

the class AnnotationApiConfigGeneratorTest method testDateCollection.

@Test
public void testDateCollection() throws Exception {
    @Api
    class DateParameters {

        @SuppressWarnings("unused")
        public void foo(@Named("date") Date date, @Named("dates1") Collection<Date> dates1, @Named("dates2") Date[] dates2) {
        }
    }
    String apiConfigSource = g.generateConfig(DateParameters.class).get("myapi-v1.api");
    ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
    JsonNode request = root.path("methods").path("myapi.dateParameters.foo").path("request");
    verifyMethodRequestParameter(request, "date", "datetime", true, false);
    verifyMethodRequestParameter(request, "dates1", "datetime", true, true);
    verifyMethodRequestParameter(request, "dates2", "datetime", true, true);
    verifyEmptyMethodRequest(root, DateParameters.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) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Named (javax.inject.Named)126 Produces (javax.enterprise.inject.Produces)36 Test (org.junit.Test)29 ApplicationScoped (javax.enterprise.context.ApplicationScoped)26 Provides (com.google.inject.Provides)22 Singleton (javax.inject.Singleton)17 Properties (java.util.Properties)16 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)15 Api (com.google.api.server.spi.config.Api)15 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)12 Annotation (java.lang.annotation.Annotation)11 Provides (dagger.Provides)9 ArrayList (java.util.ArrayList)8 List (java.util.List)7 Inject (javax.inject.Inject)7 HashMap (java.util.HashMap)6 ApiConfigAnnotationReader (com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader)4 Type (java.lang.reflect.Type)4