Search in sources :

Example 11 with ResourceSchema

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

the class ResourceSchemaTest method testDefaultSchemaWithProperties.

@Test
public void testDefaultSchemaWithProperties() {
    ResourceSchema schema = ResourceSchema.builderForType(Integer.class).addProperty("foo", ResourcePropertySchema.of(TypeToken.of(Float.class))).addProperty("bar", ResourcePropertySchema.of(TypeToken.of(Double.class))).build();
    assertThat(schema.getProperties().keySet()).containsExactly("foo", "bar");
    assertEquals(Float.class, schema.getProperties().get("foo").getJavaType());
    assertEquals(Double.class, schema.getProperties().get("bar").getJavaType());
}
Also used : ResourceSchema(com.google.api.server.spi.config.ResourceSchema) Test(org.junit.Test)

Example 12 with ResourceSchema

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

the class ResourceSchemaTest method testBuilderWithResource.

@Test
public void testBuilderWithResource() {
    ResourceSchema originalSchema = ResourceSchema.builderForType(Integer.class).addProperty("foo", ResourcePropertySchema.of(TypeToken.of(Float.class))).build();
    ResourceSchema.Builder newSchemaBuilder = ResourceSchema.builderWithSchema(originalSchema);
    assertEquals(originalSchema, newSchemaBuilder.build());
    newSchemaBuilder.addProperty("bar", ResourcePropertySchema.of(TypeToken.of(Double.class)));
    newSchemaBuilder.setName("Number");
    assertThat(newSchemaBuilder.build().getProperties().keySet()).containsExactly("foo", "bar");
    assertEquals(newSchemaBuilder.build().getName(), "Number");
}
Also used : ResourceSchema(com.google.api.server.spi.config.ResourceSchema) Test(org.junit.Test)

Example 13 with ResourceSchema

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

the class ResourceSchemaTest method testDefaultSchemaWithAlternateName.

@Test
public void testDefaultSchemaWithAlternateName() {
    ResourceSchema schema = ResourceSchema.builderForType(Integer.class).setName("Number").build();
    assertEquals("Number", schema.getName());
    assertEquals(Integer.class, schema.getType());
}
Also used : ResourceSchema(com.google.api.server.spi.config.ResourceSchema) Test(org.junit.Test)

Example 14 with ResourceSchema

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

the class ResourceSchemaTest method testDuplicateProperties.

@Test
public void testDuplicateProperties() {
    try {
        ResourceSchema schema = ResourceSchema.builderForType(Integer.class).addProperty("foo", ResourcePropertySchema.of(TypeToken.of(Float.class))).addProperty("foo", ResourcePropertySchema.of(TypeToken.of(Double.class))).build();
        fail("Expected " + IllegalArgumentException.class);
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : ResourceSchema(com.google.api.server.spi.config.ResourceSchema) Test(org.junit.Test)

Example 15 with ResourceSchema

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

the class ResourceSchemaProviderTest method testBeanPropertyWithGetterAndSetter.

@Test
public void testBeanPropertyWithGetterAndSetter() throws Exception {
    ResourceSchema schema = getResourceSchema(Bean.class);
    assertThat(schema.getProperties().keySet()).containsExactly("date");
    assertEquals(Date.class, schema.getProperties().get("date").getJavaType());
}
Also used : ResourceSchema(com.google.api.server.spi.config.ResourceSchema) Test(org.junit.Test)

Aggregations

ResourceSchema (com.google.api.server.spi.config.ResourceSchema)21 Test (org.junit.Test)18 ResourcePropertySchema (com.google.api.server.spi.config.ResourcePropertySchema)3 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Field (com.google.api.server.spi.config.model.Schema.Field)1