Search in sources :

Example 16 with DataList

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

the class TestValidation method testArrayNormalCoercionValidation.

@Test
public void testArrayNormalCoercionValidation() throws IOException {
    String schemaText = "{ \"type\" : \"record\", \"name\" : \"foo\", \"fields\" : " + "[ { \"name\" : \"bar\", \"type\" : { \"type\" : \"array\", \"items\" : \"int\" } } ] }";
    Object[][] inputs = { { new DataList(), new DataList() }, { new DataList(asList(1)), new DataList(asList(1)) }, { new DataList(asList(2, 3)), new DataList(asList(2, 3)) }, { new DataList(asList(1L)), new DataList(asList(1)) }, { new DataList(asList(1.0f)), new DataList(asList(1)) }, { new DataList(asList(1.0)), new DataList(asList(1)) } };
    Object[] badObjects = { Boolean.TRUE, Integer.valueOf(1), Long.valueOf(1), Float.valueOf(1f), Double.valueOf(1), new String(), new DataMap(), new DataList(asList(Boolean.TRUE)), new DataList(asList(new String("1"))), new DataList(asList(new DataMap())), new DataList(asList(new DataList())), new DataList(asList(Boolean.TRUE, Integer.valueOf(1))), new DataList(asList(Integer.valueOf(1), Boolean.TRUE)) };
    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)

Example 17 with DataList

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

the class TestValidation method testLongNoCoercionValidation.

@Test
public void testLongNoCoercionValidation() throws IOException {
    String schemaText = "{ \"type\" : \"record\", \"name\" : \"foo\", \"fields\" : " + "[ { \"name\" : \"bar\", \"type\" : \"long\" } ] }";
    Object[] goodObjects = { Long.valueOf(1), Long.valueOf(-1) };
    Object[] badObjects = { Boolean.TRUE, Integer.valueOf(1), Float.valueOf(1f), Double.valueOf(1), new String("abc"), ByteString.copyAvroString("bytes", false), new DataMap(), new DataList(), Double.NaN, Float.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY };
    testCoercionValidation(schemaText, "bar", goodObjects, badObjects, noCoercionValidationOption());
}
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 18 with DataList

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

the class TestValidation method testBooleanValidation.

@Test
public void testBooleanValidation() throws IOException {
    String schemaText = "{ \"type\" : \"record\", \"name\" : \"foo\", \"fields\" : " + "[ { \"name\" : \"bar\", \"type\" : \"boolean\" } ] }";
    Object[] goodObjects = { Boolean.TRUE, Boolean.FALSE };
    Object[] badObjects = { Integer.valueOf(1), Long.valueOf(1), Float.valueOf(1f), Double.valueOf(1), new String("abc"), ByteString.copyAvroString("bytes", false), new DataMap(), new DataList() };
    testCoercionValidation(schemaText, "bar", goodObjects, badObjects, normalCoercionValidationOption());
    testCoercionValidation(schemaText, "bar", goodObjects, badObjects, noCoercionValidationOption());
}
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 19 with DataList

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

the class TestValidation method testIntegerNoCoercionValidation.

@Test
public void testIntegerNoCoercionValidation() throws IOException {
    String schemaText = "{ \"type\" : \"record\", \"name\" : \"foo\", \"fields\" : " + "[ { \"name\" : \"bar\", \"type\" : \"int\" } ] }";
    Object[] goodObjects = { Integer.valueOf(1), Integer.valueOf(-1), Integer.MAX_VALUE, Integer.MAX_VALUE - 1 };
    Object[] badObjects = { Boolean.TRUE, Long.valueOf(1), Float.valueOf(1f), Double.valueOf(1), new String("abc"), ByteString.copyAvroString("bytes", false), new DataMap(), new DataList(), Float.NaN, Double.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY };
    testCoercionValidation(schemaText, "bar", goodObjects, badObjects, noCoercionValidationOption());
}
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 20 with DataList

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

the class TestValidation method testDoubleNoCoercionValidation.

@Test
public void testDoubleNoCoercionValidation() throws IOException {
    String schemaText = "{ \"type\" : \"record\", \"name\" : \"foo\", \"fields\" : " + "[ { \"name\" : \"bar\", \"type\" : \"double\" } ] }";
    Object[] goodObjects = { Double.valueOf(1), Double.valueOf(-1), Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY };
    Object[] badObjects = { Boolean.TRUE, Integer.valueOf(1), Long.valueOf(1), Float.valueOf(1f), new String("abc"), ByteString.copyAvroString("bytes", false), new DataMap(), new DataList(), "1.1", "-1.1", String.valueOf(Double.NaN), String.valueOf(Double.POSITIVE_INFINITY), String.valueOf(Double.NEGATIVE_INFINITY) };
    testCoercionValidation(schemaText, "bar", goodObjects, badObjects, noCoercionValidationOption());
}
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