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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations