Search in sources :

Example 1 with Formatter

use of io.vertigo.dynamo.domain.metamodel.Formatter in project vertigo by KleeGroup.

the class NumberFormatterTest method testFormatterNumber.

/**
 * Test du formatter de nombre.
 * @throws FormatterException e
 */
@Test
public void testFormatterNumber() throws FormatterException {
    final Formatter formatterNumber = new FormatterNumber("#,###,##0.00");
    // BigDecimal
    final BigDecimal pi = new BigDecimal("3.14");
    Assert.assertEquals(pi, formatterNumber.stringToValue("3.14", DataType.BigDecimal));
    Assert.assertEquals(pi, formatterNumber.stringToValue("3,14", DataType.BigDecimal));
    Assert.assertEquals("3,14", formatterNumber.valueToString(pi, DataType.BigDecimal));
    Assert.assertEquals(new BigDecimal("0.14"), formatterNumber.stringToValue("0.14", DataType.BigDecimal));
    // Integer
    Assert.assertEquals(1492, formatterNumber.stringToValue("1492", DataType.Integer));
    Assert.assertEquals(1492, formatterNumber.stringToValue("1 492", DataType.Integer));
    Assert.assertEquals(1492, formatterNumber.stringToValue("1492  ", DataType.Integer));
    Assert.assertEquals(1492, formatterNumber.stringToValue("01492  ", DataType.Integer));
    // Long
    Assert.assertEquals(1492L, formatterNumber.stringToValue("1492", DataType.Long));
    Assert.assertEquals(1492L, formatterNumber.stringToValue("1 492", DataType.Long));
    Assert.assertEquals(1492L, formatterNumber.stringToValue("1492  ", DataType.Long));
    Assert.assertEquals(1492L, formatterNumber.stringToValue("01492  ", DataType.Long));
    // Double
    Assert.assertEquals(3.14D, formatterNumber.stringToValue("3.14", DataType.Double));
    Assert.assertEquals(3.14D, formatterNumber.stringToValue("3,14", DataType.Double));
    Assert.assertEquals(.14D, formatterNumber.stringToValue("0.14", DataType.Double));
    Assert.assertEquals("3,14", formatterNumber.valueToString(3.14D, DataType.Double));
}
Also used : FormatterNumber(io.vertigo.dynamox.domain.formatter.FormatterNumber) Formatter(io.vertigo.dynamo.domain.metamodel.Formatter) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 2 with Formatter

use of io.vertigo.dynamo.domain.metamodel.Formatter in project vertigo by KleeGroup.

the class OOMEnvironmentManagerTest method testDefaultBooleanFormatter.

@Test
public void testDefaultBooleanFormatter() {
    final DefinitionSpace definitionSpace = getApp().getDefinitionSpace();
    final Formatter formatter = definitionSpace.resolve("FMT_DEFAULT", FormatterDefinition.class);
    Assert.assertEquals("MyTrue", formatter.valueToString(true, DataType.Boolean));
}
Also used : Formatter(io.vertigo.dynamo.domain.metamodel.Formatter) DefinitionSpace(io.vertigo.core.definition.DefinitionSpace) Test(org.junit.Test)

Aggregations

Formatter (io.vertigo.dynamo.domain.metamodel.Formatter)2 Test (org.junit.Test)2 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)1 FormatterNumber (io.vertigo.dynamox.domain.formatter.FormatterNumber)1 BigDecimal (java.math.BigDecimal)1