Search in sources :

Example 6 with ModifiableValueMapDecorator

use of org.apache.sling.api.wrappers.ModifiableValueMapDecorator in project acs-aem-commons by Adobe-Consulting-Services.

the class AnnotatedFieldDeserializerTest method testPrimitiveInputs.

/**
 * Check if primitives are deserialized properly.
 *
 * @throws java.lang.Exception
 */
@Test
public void testPrimitiveInputs() throws Exception {
    System.out.println("processInput");
    PrimitivesTest target = new PrimitivesTest();
    Map<String, Object> params = new HashMap<>();
    params.put("intValue", "123");
    params.put("doubleValue", numberFormat.format(123.456));
    params.put("floatValue", numberFormat.format(234.567f));
    params.put("longValue", "1234567890");
    params.put("booleanValue", "true");
    AnnotatedFieldDeserializer.deserializeFormFields(target, new ModifiableValueMapDecorator(params));
    assertEquals(123, target.intValue);
    assertEquals(123.456D, target.doubleValue, 0);
    assertEquals(234.567F, target.floatValue, 0);
    assertEquals(1234567890L, target.longValue);
    assertEquals(true, target.booleanValue);
}
Also used : ModifiableValueMapDecorator(org.apache.sling.api.wrappers.ModifiableValueMapDecorator) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 7 with ModifiableValueMapDecorator

use of org.apache.sling.api.wrappers.ModifiableValueMapDecorator in project acs-aem-commons by Adobe-Consulting-Services.

the class AnnotatedFieldDeserializerTest method testPrimitiveArrayInputs.

/**
 * Check if primitives are deserialized properly.
 *
 * @throws java.lang.Exception
 */
@Test
public void testPrimitiveArrayInputs() throws Exception {
    System.out.println("processInput");
    PrimitiveArrayTest target = new PrimitiveArrayTest();
    Map<String, Object> params = new HashMap<>();
    params.put("intValue", new String[] { "123", "456", "789" });
    params.put("doubleValue", numberFormat.format(123.456));
    params.put("floatValue", new String[] { numberFormat.format(234.567f), numberFormat.format(111.222f), numberFormat.format(333.444f), numberFormat.format(555.666f) });
    AnnotatedFieldDeserializer.deserializeFormFields(target, new ModifiableValueMapDecorator(params));
    assertArrayEquals(new int[] { 123, 456, 789 }, target.intValue);
    assertArrayEquals(new double[] { 123.456D }, target.doubleValue, 0);
    assertNotNull(target.floatValue);
    assertEquals(4, target.floatValue.size());
    assertEquals(234.567F, target.floatValue.get(0), 0);
    assertEquals(111.222F, target.floatValue.get(1), 0);
    assertEquals(333.444F, target.floatValue.get(2), 0);
    assertEquals(555.666F, target.floatValue.get(3), 0);
}
Also used : ModifiableValueMapDecorator(org.apache.sling.api.wrappers.ModifiableValueMapDecorator) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

ModifiableValueMapDecorator (org.apache.sling.api.wrappers.ModifiableValueMapDecorator)7 HashMap (java.util.HashMap)4 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)3 ValueMap (org.apache.sling.api.resource.ValueMap)3 Test (org.junit.Test)3 Resource (org.apache.sling.api.resource.Resource)2 MockValueMap (org.apache.sling.testing.resourceresolver.MockValueMap)2 Calendar (java.util.Calendar)1 JSONObject (org.apache.sling.commons.json.JSONObject)1 Before (org.junit.Before)1