Search in sources :

Example 71 with DataList

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

the class TestValidation method testIntegerNormalCoercionValidation.

@Test
public void testIntegerNormalCoercionValidation() throws IOException {
    String schemaText = "{ \"type\" : \"record\", \"name\" : \"foo\", \"fields\" : " + "[ { \"name\" : \"bar\", \"type\" : \"int\" } ] }";
    Object[][] input = { { new Integer(1), new Integer(1) }, { new Integer(-1), new Integer(-1) }, { Integer.MAX_VALUE, Integer.MAX_VALUE }, { Integer.MAX_VALUE - 1, Integer.MAX_VALUE - 1 }, { new Long(1), new Integer(1) }, { new Float(1), new Integer(1) }, { new Double(1), new Integer(1) } };
    Object[] badObjects = { new Boolean(true), new String("abc"), ByteString.copyAvroString("bytes", false), new DataMap(), new DataList() };
    testNormalCoercionValidation(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 72 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 = { { new Long(1), new Long(1) }, { new Long(-1), new Long(-1) }, { new Integer(1), new Long(1) }, { new Float(1), new Long(1) }, { new Double(1), new Long(1) } };
    Object[] badObjects = { new Boolean(true), new String("abc"), ByteString.copyAvroString("bytes", false), new DataMap(), new DataList() };
    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 73 with DataList

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

the class TestValidation method testBytesValidation.

@Test
public void testBytesValidation() throws IOException {
    String schemaText = "{ \"type\" : \"record\", \"name\" : \"foo\", \"fields\" : " + "[ { \"name\" : \"bar\", \"type\" : \"bytes\" } ] }";
    Object[] goodObjects = { "abc", ByteString.copyAvroString("bytes", false), ByteString.empty() };
    Object[] badObjects = { new Boolean(true), new Integer(1), new Long(1), new Float(1), new Double(1), new DataMap(), new DataList(), new String("Ā"), new String("abĀc"), new String("abĀcȀ") };
    testCoercionValidation(schemaText, "bar", goodObjects, badObjects, noCoercionValidationOption());
    Object[][] inputs = { { ByteString.copyAvroString("abc", false), ByteString.copyAvroString("abc", false) }, { "abc", ByteString.copyAvroString("abc", false) } };
    testNormalCoercionValidation(schemaText, "bar", inputs, badObjects);
    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 74 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 = { new Double(1), new Double(-1) };
    Object[] badObjects = { new Boolean(true), new Integer(1), new Long(1), new Float(1), new String("abc"), ByteString.copyAvroString("bytes", false), new DataMap(), new DataList() };
    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 75 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 = { new Integer(1), new Integer(-1), Integer.MAX_VALUE, Integer.MAX_VALUE - 1 };
    Object[] badObjects = { new Boolean(true), new Long(1), new Float(1), new Double(1), new String("abc"), ByteString.copyAvroString("bytes", false), new DataMap(), new DataList() };
    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)160 DataMap (com.linkedin.data.DataMap)126 Test (org.testng.annotations.Test)102 ByteString (com.linkedin.data.ByteString)64 TestUtil.dataMapFromString (com.linkedin.data.TestUtil.dataMapFromString)34 TestUtil.dataSchemaFromString (com.linkedin.data.TestUtil.dataSchemaFromString)33 ArrayList (java.util.ArrayList)22 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)17 DataSchema (com.linkedin.data.schema.DataSchema)10 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)10 HashMap (java.util.HashMap)10 MapDataSchema (com.linkedin.data.schema.MapDataSchema)9 RecordTemplate (com.linkedin.data.template.RecordTemplate)9 Map (java.util.Map)8 DataProvider (org.testng.annotations.DataProvider)8 List (java.util.List)7 PathSpec (com.linkedin.data.schema.PathSpec)6 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)5 DataComplex (com.linkedin.data.DataComplex)4 CustomPoint (com.linkedin.data.template.TestCustom.CustomPoint)4