Search in sources :

Example 26 with DataList

use of com.linkedin.data.DataList in project rest.li by linkedin.

the class TestJacksonDataTemplateCodec method testArray.

@Test
public void testArray() throws IOException {
    Object[][] inputs = { { // empty record array
    asList(), "[]", "[]" }, { // non-empty record array
    asList(new DataMap(asMap("int", 1, "long", 12L, "float", 3.0f, "double", 2.0, "long1", 12L, "double1", 3.0))), "[{\"long1\":12,\"int\":1,\"long\":12,\"double\":2.0,\"double1\":3.0,\"float\":3.0}]", "[{\"int\":1,\"long\":12,\"float\":3.0,\"double\":2.0,\"double1\":3.0,\"long1\":12}]" } };
    for (Object[] row : inputs) {
        @SuppressWarnings("unchecked") DataList list = new DataList((List<Object>) row[0]);
        FooArray fooArray = new FooArray(list);
        String noOrder = templateToString(fooArray, false);
        String order = templateToString(fooArray, true);
        // We have to compare reconstructed DataLists because the key/value pairs inside of the map which is inside of
        // the list are in a non-deterministic order
        DataList expectedNoOrderList = stringToDataList(noOrder);
        DataList actualNoOrderList = stringToDataList((String) row[1]);
        assertEquals(expectedNoOrderList, actualNoOrderList);
        assertEquals(order, row[2]);
    }
}
Also used : DataList(com.linkedin.data.DataList) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 27 with DataList

use of com.linkedin.data.DataList in project rest.li by linkedin.

the class TestCustom method testCustomPointArray.

@Test
public void testCustomPointArray() {
    final List<String> input = new ArrayList<>(Arrays.asList("1,1", "2,2", "3,3"));
    final DataList inputDataList = new DataList(input);
    CustomPointArray a1 = new CustomPointArray();
    for (String s : input) {
        a1.add(new CustomPoint(s));
        assertTrue(a1.contains(new CustomPoint(s)));
    }
    CustomPointArray a2 = new CustomPointArray(inputDataList);
    assertEquals(a1, a2);
    assertEquals(a1.data(), a2.data());
    for (String s : input) {
        assertTrue(a2.contains(new CustomPoint(s)));
    }
    for (int i = 0; i < input.size(); i++) {
        CustomPoint p = a1.get(i);
        assertEquals(p, new CustomPoint(input.get(i)));
    }
    CustomPointArray a3 = new CustomPointArray(input.size());
    for (int i = 0; i < input.size(); i++) {
        a3.add(new CustomPoint(input.get(i)));
        assertEquals(a3.get(i), new CustomPoint(input.get(i)));
    }
    for (int i = 0; i < input.size(); i++) {
        int j = input.size() - i - 1;
        a3.set(j, new CustomPoint(input.get(i)));
        assertEquals(a3.get(j), new CustomPoint(input.get(i)));
    }
}
Also used : DataList(com.linkedin.data.DataList) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 28 with DataList

use of com.linkedin.data.DataList in project rest.li by linkedin.

the class TestValidation method testDoubleStringToPrimitiveCoercionValidation.

@Test
public void testDoubleStringToPrimitiveCoercionValidation() throws IOException {
    String schemaText = "{ \"type\" : \"record\", \"name\" : \"foo\", \"fields\" : " + "[ { \"name\" : \"bar\", \"type\" : \"double\" } ] }";
    Object[][] inputs = { { new String("1"), Double.valueOf(1) }, { new String("-1"), Double.valueOf(-1) }, { new String("1.01"), Double.valueOf(1.01) }, { new String("-1.01"), Double.valueOf(-1.01) }, { new String("" + Double.MAX_VALUE), Double.MAX_VALUE }, { Double.valueOf(1), Double.valueOf(1) }, { Double.valueOf(-1), Double.valueOf(-1) }, { Integer.valueOf(1), Double.valueOf(1) }, { Long.valueOf(1), Double.valueOf(1) }, { Float.valueOf(1f), 1d }, { String.valueOf(Double.NaN), Double.NaN }, { String.valueOf(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY }, { String.valueOf(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY }, { Float.NaN, Double.NaN }, { Float.POSITIVE_INFINITY, Double.POSITIVE_INFINITY }, { Float.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY } };
    Object[] badObjects = { Boolean.TRUE, new String("abc"), ByteString.copyAvroString("bytes", false), new DataMap(), new DataList() };
    testStringToPrimitiveCoercionValidation(schemaText, "bar", inputs, badObjects);
}
Also used : DataList(com.linkedin.data.DataList) TestUtil.dataMapFromString(com.linkedin.data.TestUtil.dataMapFromString) ByteString(com.linkedin.data.ByteString) TestUtil.dataSchemaFromString(com.linkedin.data.TestUtil.dataSchemaFromString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 29 with DataList

use of com.linkedin.data.DataList in project rest.li by linkedin.

the class TestValidation method testBooleanStringToPrimitiveFixupValidation.

@Test
public void testBooleanStringToPrimitiveFixupValidation() throws IOException {
    String schemaText = "{ \"type\" : \"record\", \"name\" : \"foo\", \"fields\" : " + "[ { \"name\" : \"bar\", \"type\" : \"boolean\" } ] }";
    Object[][] input = { { new String("true"), Boolean.TRUE }, { new String("false"), Boolean.FALSE } };
    Object[] badObjects = { Integer.valueOf(1), Long.valueOf(1), Float.valueOf(1f), Double.valueOf(1), new String("abc"), new DataMap(), new DataList() };
    testStringToPrimitiveCoercionValidation(schemaText, "bar", input, badObjects);
}
Also used : DataList(com.linkedin.data.DataList) TestUtil.dataMapFromString(com.linkedin.data.TestUtil.dataMapFromString) ByteString(com.linkedin.data.ByteString) TestUtil.dataSchemaFromString(com.linkedin.data.TestUtil.dataSchemaFromString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 30 with DataList

use of com.linkedin.data.DataList in project rest.li by linkedin.

the class TestValidation method testLongNormalCoercionValidation.

@Test
public void testLongNormalCoercionValidation() throws IOException {
    String schemaText = "{ \"type\" : \"record\", \"name\" : \"foo\", \"fields\" : " + "[ { \"name\" : \"bar\", \"type\" : \"long\" } ] }";
    Object[][] inputs = { { Long.valueOf(1), Long.valueOf(1) }, { Long.valueOf(-1), Long.valueOf(-1) }, { Integer.valueOf(1), Long.valueOf(1) }, { Float.valueOf(1f), Long.valueOf(1) }, { Double.valueOf(1), Long.valueOf(1) }, { Float.NaN, 0L }, { Double.POSITIVE_INFINITY, Long.MAX_VALUE }, { Float.NEGATIVE_INFINITY, Long.MIN_VALUE } };
    Object[] badObjects = { Boolean.TRUE, new String("abc"), ByteString.copyAvroString("bytes", false), new DataMap(), new DataList(), String.valueOf(Double.NaN), String.valueOf(Float.POSITIVE_INFINITY), String.valueOf(Double.NEGATIVE_INFINITY) };
    testNormalCoercionValidation(schemaText, "bar", inputs, badObjects);
}
Also used : DataList(com.linkedin.data.DataList) TestUtil.dataMapFromString(com.linkedin.data.TestUtil.dataMapFromString) ByteString(com.linkedin.data.ByteString) TestUtil.dataSchemaFromString(com.linkedin.data.TestUtil.dataSchemaFromString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Aggregations

DataList (com.linkedin.data.DataList)202 DataMap (com.linkedin.data.DataMap)151 Test (org.testng.annotations.Test)109 ByteString (com.linkedin.data.ByteString)72 TestUtil.dataMapFromString (com.linkedin.data.TestUtil.dataMapFromString)34 TestUtil.dataSchemaFromString (com.linkedin.data.TestUtil.dataSchemaFromString)33 ArrayList (java.util.ArrayList)27 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)22 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)15 DataSchema (com.linkedin.data.schema.DataSchema)14 RecordTemplate (com.linkedin.data.template.RecordTemplate)14 HashMap (java.util.HashMap)13 MapDataSchema (com.linkedin.data.schema.MapDataSchema)12 TestUtil.asReadOnlyDataMap (com.linkedin.data.TestUtil.asReadOnlyDataMap)11 Map (java.util.Map)11 List (java.util.List)10 DataProvider (org.testng.annotations.DataProvider)10 DataComplex (com.linkedin.data.DataComplex)9 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)5 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)5