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 = { new Boolean(true), new Boolean(false) };
Object[] badObjects = { new Integer(1), 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, normalCoercionValidationOption());
testCoercionValidation(schemaText, "bar", goodObjects, badObjects, noCoercionValidationOption());
}
use of com.linkedin.data.DataList in project rest.li by linkedin.
the class TestValidation method testFloatNormalCoercionValidation.
@Test
public void testFloatNormalCoercionValidation() throws IOException {
String schemaText = "{ \"type\" : \"record\", \"name\" : \"foo\", \"fields\" : " + "[ { \"name\" : \"bar\", \"type\" : \"float\" } ] }";
Object[][] inputs = { { new Float(1), new Float(1) }, { new Float(-1), new Float(-1) }, { new Integer(1), new Float(1) }, { new Long(1), new Float(1) }, { new Double(1), new Float(1) } };
Object[] badObjects = { new Boolean(true), new String("abc"), ByteString.copyAvroString("bytes", false), new DataMap(), new DataList() };
testNormalCoercionValidation(schemaText, "bar", inputs, badObjects);
}
use of com.linkedin.data.DataList in project rest.li by linkedin.
the class TestValidation method testArrayNoCoercionValidation.
@Test
public void testArrayNoCoercionValidation() throws IOException {
String schemaText = "{ \"type\" : \"record\", \"name\" : \"foo\", \"fields\" : " + "[ { \"name\" : \"bar\", \"type\" : { \"type\" : \"array\", \"items\" : \"int\" } } ] }";
Object[] goodObjects = { new DataList(), new DataList(asList(new Integer(1))), new DataList(asList(new Integer(2), new Integer(3))) };
Object[] badObjects = { new Boolean(true), new Integer(1), new Long(1), new Float(1), new Double(1), new String(), new DataMap(), new DataList(asList(new Boolean(true))), new DataList(asList(new Long(1))), new DataList(asList(new Float(1))), new DataList(asList(new Double(1))), new DataList(asList(new String("1"))), new DataList(asList(new DataMap())), new DataList(asList(new DataList())), new DataList(asList(new Boolean(true), new Integer(1))), new DataList(asList(new Integer(1), new Boolean(true))) };
testCoercionValidation(schemaText, "bar", goodObjects, badObjects, noCoercionValidationOption());
}
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 = { new Long(1), new Long(-1) };
Object[] badObjects = { new Boolean(true), new Integer(1), new Float(1), new Double(1), new String("abc"), ByteString.copyAvroString("bytes", false), new DataMap(), new DataList() };
testCoercionValidation(schemaText, "bar", goodObjects, badObjects, noCoercionValidationOption());
}
use of com.linkedin.data.DataList in project rest.li by linkedin.
the class TestMapTemplate method testEnumMap.
@Test
public void testEnumMap() {
// must be unique
Map<String, Fruits> input = asMap("apple", Fruits.APPLE, "orange", Fruits.ORANGE, "banana", Fruits.BANANA);
Map<String, Fruits> adds = asMap("grapes", Fruits.GRAPES, "pineapple", Fruits.PINEAPPLE);
Map<String, Object> badInput = asMap("boolean", true, "integer", 1, "long", 2L, "float", 3.0f, "double", 4.0, "string", "hello", "bytes", ByteString.empty(), "object", new Object(), "null", null, "array", new StringArray(), "record", new FooRecord());
Map<String, Object> badOutput = asMap("boolean", true, "integer", 1, "long", 2L, "float", 3.0f, "double", 4.0, "string", "hello", "bytes", ByteString.empty(), "map", new DataMap(), "list", new DataList());
testMap(EnumMapTemplate.class, EnumMapTemplate.SCHEMA, input, adds);
testMapBadInput(EnumMapTemplate.class, EnumMapTemplate.SCHEMA, input, badInput, badOutput);
}
Aggregations