use of com.linkedin.data.template.TestCustom.CustomPoint in project rest.li by linkedin.
the class TestCustomPoint method testCustomPointRecordMap.
@Test
public void testCustomPointRecordMap() throws CloneNotSupportedException {
final Map<String, CustomPoint> input = asMap("1", new CustomPoint("1,1"), "2", new CustomPoint("2,2"), "3", new CustomPoint("3,3"));
final DataMap inputDataMap = new DataMap(asMap("1", "1,1", "2", "2,2", "3", "3,3"));
CustomPointRecord record = new CustomPointRecord();
CustomPointMap a1 = new CustomPointMap(inputDataMap);
record.setCustomPointMap(a1);
CustomPointRecord recordCopy = new CustomPointRecord(record.data().copy());
for (Map.Entry<String, CustomPoint> e : input.entrySet()) {
assertEquals(recordCopy.getCustomPointMap().get(e.getKey()), e.getValue());
}
}
use of com.linkedin.data.template.TestCustom.CustomPoint in project rest.li by linkedin.
the class TestCustomPoint method testCustomPointRecord.
@Test
public void testCustomPointRecord() {
CustomPoint[] input = { new CustomPoint("1,1"), new CustomPoint("2,2"), new CustomPoint("3,3") };
CustomPointRecord foo = new CustomPointRecord();
for (CustomPoint p : input) {
foo.setCustomPoint(p);
assertTrue(foo.hasCustomPoint());
assertEquals(foo.getCustomPoint(), p);
foo.removeCustomPoint();
assertFalse(foo.hasCustomPoint());
}
CustomPointRecord foo1 = new CustomPointRecord();
foo1.setCustomPoint(input[2]);
CustomPointRecord foo2 = new CustomPointRecord();
foo2.setCustomPoint(input[2]);
assertEquals(foo1, foo2);
assertEquals(foo1.data(), foo2.data());
Exception exc = null;
try {
foo.setCustomPoint(null, SetMode.DISALLOW_NULL);
} catch (RuntimeException e) {
exc = e;
}
assertTrue(exc instanceof NullPointerException);
foo.setCustomPoint(input[1], SetMode.DISALLOW_NULL);
foo.setCustomPoint(null, SetMode.IGNORE_NULL);
assertEquals(foo.getCustomPoint(), input[1]);
foo.setCustomPoint(null, SetMode.REMOVE_IF_NULL);
assertFalse(foo.hasCustomPoint());
}
use of com.linkedin.data.template.TestCustom.CustomPoint in project rest.li by linkedin.
the class TestCustomPoint method testCustomPointArray.
@Test
public void testCustomPointArray() throws IOException {
final List<String> input = new ArrayList<String>(Arrays.asList("1,1", "2,2", "3,3"));
final DataList inputDataList = new DataList(input);
final String customPointArraySchemaText = "{\"type\":\"array\",\"items\":{\"type\":\"typeref\",\"name\":\"CustomPoint\",\"namespace\":\"com.linkedin.pegasus.generator.test\",\"ref\":\"string\",\"java\":{\"class\":\"com.linkedin.data.template.TestCustom.CustomPoint\"}}}";
CustomPointArray a1 = new CustomPointArray();
assertEquals(a1.schema(), TestUtil.dataSchemaFromString(customPointArraySchemaText));
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.template.TestCustom.CustomPoint in project rest.li by linkedin.
the class TestCustomPoint method testCustomPointRecordUnion.
@Test
public void testCustomPointRecordUnion() throws CloneNotSupportedException {
CustomPoint point = new CustomPoint("1,1");
CustomPointRecord record = new CustomPointRecord();
CustomPointRecord.CustomPointUnion u = new CustomPointRecord.CustomPointUnion();
u.setCustomPoint(point);
record.setCustomPointUnion(u);
CustomPointRecord recordCopy = new CustomPointRecord(record.data().copy());
assertEquals(recordCopy, record);
assertTrue(recordCopy.getCustomPointUnion().isCustomPoint());
assertEquals(recordCopy.getCustomPointUnion().getCustomPoint(), point);
Integer i = 66;
record.getCustomPointUnion().setInt(i);
assertTrue(record.getCustomPointUnion().isInt());
assertEquals(record.getCustomPointUnion().getInt(), i);
// recordCopy has not changed
assertTrue(recordCopy.getCustomPointUnion().isCustomPoint());
assertEquals(recordCopy.getCustomPointUnion().getCustomPoint(), point);
}
Aggregations