Search in sources :

Example 36 with BigDecimal

use of java.math.BigDecimal in project disconf by knightliao.

the class MinValidatorForDouble method isValid.

public boolean isValid(Double value, ConstraintValidatorContext constraintValidatorContext) {
    // null values are valid
    if (value == null) {
        return true;
    }
    BigDecimal premium = BigDecimal.valueOf(value);
    BigDecimal netToCompany = BigDecimal.valueOf(minValue);
    BigDecimal commission = premium.subtract(netToCompany);
    return commission.compareTo(BigDecimal.ZERO) >= 0;
}
Also used : BigDecimal(java.math.BigDecimal)

Example 37 with BigDecimal

use of java.math.BigDecimal in project swagger-core by swagger-api.

the class PropertyBuilderTest method testMergeWithDoubleProperty.

@Test
public void testMergeWithDoubleProperty() {
    // given
    args.put(PropertyId.MINIMUM, new BigDecimal(2.0));
    args.put(PropertyId.MAXIMUM, new BigDecimal(112.0));
    args.put(PropertyId.EXCLUSIVE_MINIMUM, true);
    args.put(PropertyId.EXCLUSIVE_MAXIMUM, true);
    args.put(PropertyId.MULTIPLE_OF, new BigDecimal(2.0));
    args.put(PropertyId.DEFAULT, "4");
    DoubleProperty doubleProperty = new DoubleProperty();
    // when
    PropertyBuilder.merge(doubleProperty, args);
    // then
    assertTrue(doubleProperty.getEnum().contains(4.0), "Must contain the enum value passed into args");
    assertEquals(doubleProperty.getDefault(), (Double) 4.0, "Must contain the default value passed into args");
    assertEquals(doubleProperty.getMinimum(), new BigDecimal(2.0), "Must contain the minimum value passed into args");
    assertEquals(doubleProperty.getMaximum(), new BigDecimal(112.0), "Must contain the maximum value passed into args");
    assertTrue(doubleProperty.exclusiveMaximum, "Must contain the exclusive minimum value passed into args");
    assertTrue(doubleProperty.exclusiveMinimum, "Must contain the exclusive maximum value passed into args");
    assertEquals(doubleProperty.getMultipleOf(), new BigDecimal(2.0), "Must contain the multiple of value passed into args");
    // given
    args.put(PropertyId.DEFAULT, null);
    // when
    PropertyBuilder.merge(doubleProperty, args);
    // then
    assertNull(doubleProperty.getDefault(), "Must contain the default value passed into args");
}
Also used : BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 38 with BigDecimal

use of java.math.BigDecimal in project swagger-core by swagger-api.

the class PropertyBuilderTest method testToModelWithDoubleProperty.

@Test
public void testToModelWithDoubleProperty() {
    // given
    DoubleProperty doubleProperty = new DoubleProperty();
    doubleProperty.setDefault(4D);
    // when
    Model model = PropertyBuilder.toModel(doubleProperty);
    // then
    assertEquals(((ModelImpl) model).getDefaultValue(), new BigDecimal("4.0"), "Must contain the default value passed into the property");
}
Also used : Model(io.swagger.models.Model) ArrayModel(io.swagger.models.ArrayModel) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 39 with BigDecimal

use of java.math.BigDecimal in project swagger-core by swagger-api.

the class AbstractSerializableParameterTest method testGettersAndSetters.

/*
     * Tests getters and setters methods on {@link
     * AbstractSerializableParameter} It was not possible to cove it with {@link
     * io.swagger.PojosTest} so a manual implementation is provided for now TODO
     * improve PojosTest to test getters and setters for abstracts classes
     */
@Test
public void testGettersAndSetters() {
    // given
    String type = "type";
    // when
    instance.setType(type);
    // then
    assertEquals(instance.getType(), type, "The get type must be the same as the set one");
    // given
    String format = "format";
    // when
    instance.setFormat(format);
    // then
    assertEquals(instance.getFormat(), format, "The get format must be the same as the set one");
    // given
    String collectionFormat = "collectionFormat";
    // when
    instance.setCollectionFormat(collectionFormat);
    // then
    assertEquals(instance.getCollectionFormat(), collectionFormat, "The get collectionFormat must be the same as the set one");
    // given
    Property items = new BooleanProperty();
    // when
    instance.setItems(items);
    // then
    assertEquals(instance.getItems(), items, "The get items must be the same as the set one");
    // given
    List<String> _enum = Arrays.asList("_enum");
    // when
    instance._enum(_enum);
    instance.setEnum(_enum);
    // then
    assertEquals(instance.getEnum(), _enum, "The get _enum must be the same as the set one");
    // given
    Boolean exclusiveMaximum = true;
    // when
    instance.setExclusiveMaximum(exclusiveMaximum);
    // then
    assertEquals(instance.isExclusiveMaximum(), exclusiveMaximum, "The get exclusiveMaximum must be the same as the set one");
    // given
    Double maximum = 1.0;
    // when
    instance.setMaximum(new BigDecimal(maximum));
    // then
    assertEquals(instance.getMaximum(), new BigDecimal(maximum), "The get maximum must be the same as the set one");
    // given
    Boolean exclusiveMinimum = true;
    // when
    instance.setExclusiveMinimum(exclusiveMinimum);
    // then
    assertEquals(instance.isExclusiveMinimum(), exclusiveMinimum, "The get exclusiveMinimum must be the same as the set one");
    // given
    Double minimum = 0.1;
    // when
    instance.setMinimum(new BigDecimal(minimum));
    // then
    assertEquals(instance.getMinimum(), new BigDecimal(minimum), "The get minimum must be the same as the set one");
    // given
    String example = "example";
    // when
    instance.setExample(example);
    // then
    assertEquals(instance.getExample(), example, "The get example must be the same as the set one");
    // given
    Integer maxItems = 100;
    // when
    instance.setMaxItems(maxItems);
    // then
    assertEquals(instance.getMaxItems(), maxItems, "The get maxItems must be the same as the set one");
    // given
    Integer minItems = 10;
    // when
    instance.setMinItems(minItems);
    // then
    assertEquals(instance.getMinItems(), minItems, "The get minItems must be the same as the set one");
    // given
    Integer maxLength = 500;
    // when
    instance.setMaxLength(maxLength);
    // then
    assertEquals(instance.getMaxLength(), maxLength, "The get maxLength must be the same as the set one");
    // given
    Integer minLength = 25;
    // when
    instance.setMinLength(minLength);
    // then
    assertEquals(instance.getMinLength(), minLength, "The get minLength must be the same as the set one");
    // given
    String pattern = "String pattern";
    // when
    instance.setPattern(pattern);
    // then
    assertEquals(instance.getPattern(), pattern, "The get pattern must be the same as the set one");
    // given
    Boolean uniqueItems = true;
    // when
    instance.setUniqueItems(uniqueItems);
    // then
    assertEquals(instance.isUniqueItems(), uniqueItems, "The get uniqueItems must be the same as the set one");
    // given
    Number multipleOf = 5;
    // when
    instance.setMultipleOf(multipleOf);
    // then
    assertEquals(instance.getMultipleOf(), multipleOf, "The get multipleOf must be the same as the set one");
    // given
    String defaultValue = "defaultValue";
    // when
    instance.setDefaultValue(defaultValue);
    // then
    assertEquals(instance.getDefaultValue(), defaultValue, "The get defaultValue must be the same as the set one");
    // when
    instance.required(true);
    // then
    assertTrue(instance.getRequired(), "The get required must be the same as the set one");
    // given
    StringProperty property = new StringProperty();
    property._enum(_enum);
    // when
    instance.property(property);
    // then
    assertEquals(instance.getEnum(), _enum, "The get _enum must be the same as the set one");
    assertEquals(instance.getType(), property.getType(), "The get type must be the same as the set property type");
    // given
    ArrayProperty arrayProperty = new ArrayProperty();
    // when
    arrayProperty.items(items);
    instance.property(arrayProperty);
    // then
    assertEquals(instance.getItems(), items, "The get items must be the same as the set one");
    assertEquals(instance.getType(), arrayProperty.getType(), "The get type must be the same as the set property type");
    assertEquals(instance.getDefaultCollectionFormat(), "csv", "The get collection format must be csv");
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) StringProperty(io.swagger.models.properties.StringProperty) BaseIntegerProperty(io.swagger.models.properties.BaseIntegerProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 40 with BigDecimal

use of java.math.BigDecimal in project swagger-core by swagger-api.

the class AbstractNumericPropertyTest method testGettersAndSetters.

/*
     * Tests getters and setters methods on {@link AbstractNumericProperty} It was not
     * possible to cove it with {@link io.swagger.PojosTest} so a manual
     * implementation is provided for now TODO improve PojosTest to test getters
     * and setters for abstracts classes
     */
@Test
public void testGettersAndSetters() {
    //given
    Double minimum = 2.2, maximum = 6.4, multipleOf = 1.1;
    Boolean exclusiveMinimum = true, exclusiveMaximum = true;
    AbstractNumericProperty abstractNumericProperty = new BaseIntegerProperty();
    //when
    abstractNumericProperty.setMinimum(new BigDecimal(minimum));
    //then
    assertEquals(abstractNumericProperty.getMinimum(), new BigDecimal(minimum), "The get minimum must return the same as the set one");
    //when
    abstractNumericProperty.setMaximum(new BigDecimal(maximum));
    //then
    assertEquals(abstractNumericProperty.getMaximum(), new BigDecimal(maximum), "The get maximum must return the same as the set one");
    //when
    abstractNumericProperty.setExclusiveMaximum(exclusiveMaximum);
    //then
    assertEquals(abstractNumericProperty.getExclusiveMaximum(), exclusiveMaximum, "The get exclusiveMaximum must return the same as the set one");
    //when
    abstractNumericProperty.setExclusiveMinimum(exclusiveMinimum);
    //then
    assertEquals(abstractNumericProperty.getExclusiveMinimum(), exclusiveMinimum, "The get exclusiveMinimum must return the same as the set one");
    //when
    abstractNumericProperty.setMultipleOf(new BigDecimal(multipleOf));
    //then
    assertEquals(abstractNumericProperty.getMultipleOf(), new BigDecimal(multipleOf), "The get multipleOf must return the same as the set one");
}
Also used : BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

BigDecimal (java.math.BigDecimal)5274 Test (org.junit.Test)834 BigInteger (java.math.BigInteger)657 Test (org.testng.annotations.Test)626 LocalDate (org.joda.time.LocalDate)409 ArrayList (java.util.ArrayList)393 ResultSet (java.sql.ResultSet)251 MathContext (java.math.MathContext)220 Timestamp (java.sql.Timestamp)211 PreparedStatement (java.sql.PreparedStatement)207 Date (java.util.Date)175 SQLException (java.sql.SQLException)170 HashMap (java.util.HashMap)157 UUID (java.util.UUID)149 Invoice (org.killbill.billing.invoice.api.Invoice)148 List (java.util.List)136 DateTime (org.joda.time.DateTime)132 RoundingMode (java.math.RoundingMode)129 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)104 Session (org.hibernate.Session)96