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