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