@Test(description = "it should deserialize a integer MapProperty") public void deserializeIntegerMapProperty() throws IOException { final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}"; final Schema p = m.readValue(json, Schema.class); assertEquals(p.getType(), "object"); assertEquals(p.getClass(), MapSchema.class); assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should deserialize a long MapProperty") public void deserializeLongMapProperty() throws IOException { final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int64\"}}"; final Schema p = m.readValue(json, Schema.class); assertEquals(p.getType(), "object"); assertEquals(p.getClass(), MapSchema.class); assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should deserialize a string array property") public void deserializeArrayStringProperty() throws IOException { final String json = "{\"type\":\"array\",\"items\":{\"type\":\"string\"}}"; final Schema p = m.readValue(json, Schema.class); assertEquals(p.getType(), "array"); assertEquals(p.getClass(), ArraySchema.class); assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should deserialize a string MapProperty") public void deserializeStringMapProperty() throws IOException { final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"string\"}}"; final Schema p = m.readValue(json, Schema.class); assertEquals(p.getType(), "object"); assertEquals(p.getClass(), MapSchema.class); assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should deserialize a StringProperty") public void deserializeStringProperty() throws IOException { final String json = "{\"type\":\"string\"}"; final Schema p = m.readValue(json, Schema.class); assertEquals(p.getType(), "string"); assertEquals(p.getClass(), StringSchema.class); assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should deserialize a FloatProperty") public void deserializeFloatProperty() throws IOException { final String json = "{\"type\":\"number\",\"format\":\"float\"}"; final Schema p = m.readValue(json, Schema.class); assertEquals(p.getType(), "number"); assertEquals(p.getFormat(), "float"); assertEquals(p.getClass(), NumberSchema.class); assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should deserialize a LongProperty") public void deserializeLongProperty() throws IOException { final String json = "{\"type\":\"integer\",\"format\":\"int64\"}"; final Schema p = m.readValue(json, Schema.class); assertEquals(p.getType(), "integer"); assertEquals(p.getFormat(), "int64"); assertEquals(p.getClass(), IntegerSchema.class); assertEquals(m.writeValueAsString(p), json); }
private void assertSub2PropertiesValid(Map<String, Schema> subProperties) { assertEquals(subProperties.size(), 1); for (Map.Entry<String, Schema> entry : subProperties.entrySet()) { final String name = entry.getKey(); final Schema prop = entry.getValue(); if ("d".equals(name)) { assertEquals(prop.getType(), "integer"); assertEquals(prop.getFormat(), "int32"); } } }
@Test(description = "it should deserialize a StringProperty with enums") public void deserializeEnumStringProperty() throws IOException { final String json = "{\"type\":\"string\",\"enum\":[\"a\",\"b\"]}"; final Schema p = m.readValue(json, Schema.class); assertEquals(p.getType(), "string"); List<String> _enum = ((StringSchema) p).getEnum(); assertNotNull(_enum); assertEquals(_enum, Arrays.asList("a", "b")); assertEquals(p.getClass(), StringSchema.class); assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should deserialize a DoubleProperty") public void deserializeDoubleProperty() throws IOException { final String json = "{\"type\":\"number\",\"format\":\"double\"}"; final Schema p = m.readValue(json, Schema.class); assertEquals(p.getType(), "number"); assertEquals(p.getFormat(), "double"); assertEquals(p.getClass(), NumberSchema.class); assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should deserialize a IntegerProperty") public void deserializeIntegerProperty() throws IOException { final String json = "{\"type\":\"integer\",\"format\":\"int32\"}"; final Schema p = m.readValue(json, Schema.class); assertEquals(p.getType(), "integer"); assertEquals(p.getFormat(), "int32"); assertEquals(p.getClass(), IntegerSchema.class); assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should deserialize a DateProperty") public void deserializeDateProperty() throws IOException { final String json = "{\"type\":\"string\",\"format\":\"date\"}"; final Schema p = m.readValue(json, Schema.class); assertEquals(p.getType(), "string"); assertEquals(p.getFormat(), "date"); assertEquals(p.getClass(), DateSchema.class); assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should deserialize a DateTimeProperty") public void deserializeDateTimeProperty() throws IOException { final String json = "{\"type\":\"string\",\"format\":\"date-time\"}"; final Schema p = m.readValue(json, Schema.class); assertEquals(p.getType(), "string"); assertEquals(p.getFormat(), "date-time"); assertEquals(p.getClass(), DateTimeSchema.class); assertEquals(m.writeValueAsString(p), json); }
private void assertSub1PropertiesValid(Map<String, Schema> subProperties) { assertEquals(subProperties.size(), 1); for (Map.Entry<String, Schema> entry : subProperties.entrySet()) { final String name = entry.getKey(); final Schema prop = entry.getValue(); if ("c".equals(name)) { assertEquals(prop.getType(), "integer"); assertEquals(prop.getFormat(), "int32"); } } }
@Test(description = "it should deserialize a BooleanSchema") public void deserializeBooleanSchema() throws IOException { final String json = "{\"type\":\"boolean\",\"default\":false}"; final Schema p = m.readValue(json, Schema.class); assertEquals(p.getType(), "boolean"); assertNull(p.getFormat()); assertEquals(p.getClass(), BooleanSchema.class); assertEquals(((BooleanSchema) p).getDefault(), Boolean.FALSE); assertEquals(m.writeValueAsString(p), json); }
private void checkType(Schema property, Class<?> cls, String type, String format) { assertTrue(cls.isInstance(property)); assertEquals(property.getType(), type); if (format == null) { assertNull(property.getFormat()); } else { assertEquals(property.getFormat(), format); } }
@Test(description = "it should scan an empty model per 499") public void scanEmptyModel() { final Map<String, Schema> schemas = readAll(EmptyModel.class); final Schema model = (Schema) schemas.get("EmptyModel"); assertNull(model.getProperties()); assertEquals(model.getType(), "object"); }
@Test public void testIntArray() throws Exception { final Schema model = context.resolve(new AnnotatedType(IntArrayBean.class)); final Map<String, Schema> props = model.getProperties(); assertEquals(props.size(), 1); String key = props.keySet().iterator().next(); final Schema prop = props.get(key); assertEquals(key, "b"); assertEquals(prop.getType(), "array"); }
@Test(description = "it tests a model with java offset") public void scanModelWithOffset() throws IOException { final Map<String, Schema> models = readAll(ModelWithOffset.class); assertEquals(models.size(), 1); final Schema model = models.get("ModelWithOffset"); Schema property = (Schema) model.getProperties().get("offset"); assertEquals(property.getType(), "string"); assertEquals(property.getFormat(), "date-time"); }
@Test(description = "it should check handling of string types") public void checkStringTypesHandling() { for (Class<?> cls : Arrays.asList(URI.class, URL.class, UUID.class)) { final Map<String, Schema> schemas = readAll(cls); assertEquals(schemas.size(), 0); final Schema property = ModelConverters.getInstance().readAllAsResolvedSchema(cls).schema; assertNotNull(property); assertEquals(property.getType(), "string"); } }