use of io.swagger.models.properties.DateTimeProperty in project swagger-core by swagger-api.
the class JodaDateTimeConverterTest method testJodaDateTime.
@Test
public void testJodaDateTime() {
final Map<String, Model> models = ModelConverters.getInstance().read(ModelWithJodaDateTime.class);
// don't create a Joda DateTime object
assertEquals(models.size(), 1);
final Model model = models.get("ModelWithJodaDateTime");
final Property dateTimeProperty = model.getProperties().get("createdAt");
assertTrue(dateTimeProperty instanceof DateTimeProperty);
assertEquals((int) dateTimeProperty.getPosition(), 1);
assertTrue(dateTimeProperty.getRequired());
assertEquals(dateTimeProperty.getDescription(), "creation timestamp");
final Property nameProperty = model.getProperties().get("name");
assertTrue(nameProperty instanceof StringProperty);
assertEquals((int) nameProperty.getPosition(), 2);
assertEquals(nameProperty.getDescription(), "name of the model");
}
use of io.swagger.models.properties.DateTimeProperty in project swagger-core by swagger-api.
the class XMLGregorianCalendarTest method testXMLGregorianCalendar.
@Test(description = "it should read a model with XMLGregorianCalendar")
public void testXMLGregorianCalendar() {
final Map<String, Model> models = ModelConverters.getInstance().readAll(ModelWithCalendar.class);
// don't create a Joda DateTime object
assertEquals(models.size(), 1);
final Map<String, Property> properties = models.get("ModelWithCalendar").getProperties();
final Property nameProperty = properties.get("name");
assertTrue(nameProperty instanceof StringProperty);
assertEquals((int) nameProperty.getPosition(), 2);
assertEquals(nameProperty.getDescription(), "name of the model");
final Property dateTimeProperty = properties.get("createdAt");
assertTrue(dateTimeProperty instanceof DateTimeProperty);
assertEquals((int) dateTimeProperty.getPosition(), 1);
assertTrue(dateTimeProperty.getRequired());
assertEquals(dateTimeProperty.getDescription(), "creation timestamp");
}
use of io.swagger.models.properties.DateTimeProperty in project swagger-core by swagger-api.
the class ModelSerializerTest method convertModel.
@Test(description = "it should convert a model")
public void convertModel() throws JsonProcessingException {
final ModelImpl pet = new ModelImpl();
final HashMap<String, Property> props = new HashMap<String, Property>();
props.put("intValue", new IntegerProperty());
props.put("longValue", new LongProperty());
props.put("dateValue", new DateProperty());
props.put("dateTimeValue", new DateTimeProperty());
pet.setProperties(props);
pet.setRequired(Arrays.asList("intValue", "name"));
final String json = "{\n" + " \"required\":[\n" + " \"intValue\"\n" + " ],\n" + " \"properties\":{\n" + " \"dateValue\":{\n" + " \"type\":\"string\",\n" + " \"format\":\"date\"\n" + " },\n" + " \"longValue\":{\n" + " \"type\":\"integer\",\n" + " \"format\":\"int64\"\n" + " },\n" + " \"dateTimeValue\":{\n" + " \"type\":\"string\",\n" + " \"format\":\"date-time\"\n" + " },\n" + " \"intValue\":{\n" + " \"type\":\"integer\",\n" + " \"format\":\"int32\"\n" + " }\n" + " }\n" + "}";
SerializationMatchers.assertEqualsToJson(pet, json);
}
use of io.swagger.models.properties.DateTimeProperty in project swagger-core by swagger-api.
the class PropertySerializationTest method deserializeDateTimeProperty.
@Test(description = "it should deserialize a DateTimeProperty")
public void deserializeDateTimeProperty() throws IOException {
final String json = "{\"type\":\"string\",\"format\":\"date-time\"}";
final Property p = m.readValue(json, Property.class);
assertEquals(p.getType(), "string");
assertEquals(p.getFormat(), "date-time");
assertEquals(p.getClass(), DateTimeProperty.class);
assertEquals(m.writeValueAsString(p), json);
}
use of io.swagger.models.properties.DateTimeProperty in project swagger-core by swagger-api.
the class PropertySerializationTest method serializeDateTimeProperty.
@Test(description = "it should serialize a DateTimeProperty")
public void serializeDateTimeProperty() throws IOException {
final DateTimeProperty p = new DateTimeProperty();
final String json = "{\"type\":\"string\",\"format\":\"date-time\"}";
assertEquals(m.writeValueAsString(p), json);
}
Aggregations