Search in sources :

Example 1 with BeanValidationsModel

use of io.swagger.models.BeanValidationsModel in project swagger-core by swagger-api.

the class BeanValidatorTest method readBeanValidatorTest.

@Test(description = "read bean validations")
public void readBeanValidatorTest() {
    final Map<String, Model> schemas = ModelConverters.getInstance().readAll(BeanValidationsModel.class);
    final Model model = schemas.get("BeanValidationsModel");
    final Map<String, Property> properties = model.getProperties();
    final IntegerProperty age = (IntegerProperty) properties.get("age");
    Assert.assertEquals(age.getMinimum(), new BigDecimal(13.0));
    Assert.assertEquals(age.getMaximum(), new BigDecimal(99.0));
    final StringProperty password = (StringProperty) properties.get("password");
    Assert.assertEquals((int) password.getMinLength(), 6);
    Assert.assertEquals((int) password.getMaxLength(), 20);
    final StringProperty email = (StringProperty) properties.get("email");
    Assert.assertEquals((String) email.getPattern(), "(.+?)@(.+?)");
    final DoubleProperty minBalance = (DoubleProperty) properties.get("minBalance");
    Assert.assertTrue(minBalance.getExclusiveMinimum());
    final DoubleProperty maxBalance = (DoubleProperty) properties.get("maxBalance");
    Assert.assertTrue(maxBalance.getExclusiveMaximum());
    final ArrayProperty items = (ArrayProperty) properties.get("items");
    Assert.assertEquals((int) items.getMinItems(), 2);
    Assert.assertEquals((int) items.getMaxItems(), 10);
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) BeanValidationsModel(io.swagger.models.BeanValidationsModel) Model(io.swagger.models.Model) StringProperty(io.swagger.models.properties.StringProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

BeanValidationsModel (io.swagger.models.BeanValidationsModel)1 Model (io.swagger.models.Model)1 ArrayProperty (io.swagger.models.properties.ArrayProperty)1 DoubleProperty (io.swagger.models.properties.DoubleProperty)1 IntegerProperty (io.swagger.models.properties.IntegerProperty)1 Property (io.swagger.models.properties.Property)1 StringProperty (io.swagger.models.properties.StringProperty)1 BigDecimal (java.math.BigDecimal)1 Test (org.testng.annotations.Test)1