Search in sources :

Example 6 with CustomPoint

use of com.linkedin.data.template.TestCustom.CustomPoint in project rest.li by linkedin.

the class TestCustomPoint method testCustomPointUnionMember.

@Test
public void testCustomPointUnionMember() {
    CustomPoint[] input = { new CustomPoint("1,1"), new CustomPoint("2,2"), new CustomPoint("3,3") };
    CustomPointRecord.CustomPointUnion u = new CustomPointRecord.CustomPointUnion();
    assertFalse(u.isCustomPoint());
    assertNull(u.getCustomPoint());
    Integer i = 66;
    for (CustomPoint p : input) {
        u.setCustomPoint(p);
        assertTrue(u.isCustomPoint());
        assertEquals(u.getCustomPoint(), p);
        assertFalse(u.isInt());
        assertNull(u.getInt());
        u.setInt(i);
        assertFalse(u.isCustomPoint());
        assertNull(u.getCustomPoint());
        assertTrue(u.isInt());
        assertEquals(u.getInt(), i);
        i += 11;
    }
}
Also used : CustomPoint(com.linkedin.data.template.TestCustom.CustomPoint) Test(org.testng.annotations.Test)

Example 7 with CustomPoint

use of com.linkedin.data.template.TestCustom.CustomPoint in project rest.li by linkedin.

the class TestCustomPoint method testCustomPointRecordArray.

@Test
public void testCustomPointRecordArray() throws CloneNotSupportedException {
    final List<String> input = new ArrayList<String>(Arrays.asList("1,1", "2,2", "3,3"));
    final DataList inputDataList = new DataList(input);
    CustomPointRecord record = new CustomPointRecord();
    CustomPointArray a1 = new CustomPointArray(inputDataList);
    record.setCustomPointArray(a1);
    CustomPointRecord recordCopy = new CustomPointRecord(record.data().copy());
    for (int i = 0; i < input.size(); i++) {
        assertEquals(recordCopy.getCustomPointArray().get(i), new CustomPoint(input.get(i)));
    }
}
Also used : DataList(com.linkedin.data.DataList) ArrayList(java.util.ArrayList) CustomPoint(com.linkedin.data.template.TestCustom.CustomPoint) CustomPoint(com.linkedin.data.template.TestCustom.CustomPoint) Test(org.testng.annotations.Test)

Example 8 with CustomPoint

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());
}
Also used : CustomPoint(com.linkedin.data.template.TestCustom.CustomPoint) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 9 with CustomPoint

use of com.linkedin.data.template.TestCustom.CustomPoint in project rest.li by linkedin.

the class TestCustomPoint method testCustomPointMap.

@Test
public void testCustomPointMap() throws IOException {
    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"));
    final String customPointMapSchemaText = "{\"type\":\"map\",\"values\":{\"type\":\"typeref\",\"name\":\"CustomPoint\",\"namespace\":\"com.linkedin.pegasus.generator.testpackage\", \"package\":\"com.linkedin.pegasus.generator.override\", \"doc\":\"Test generation of Java bindings for custom types with package override\", \"ref\":\"string\",\"java\":{\"class\":\"com.linkedin.data.template.TestCustom.CustomPoint\"}}}";
    CustomPointMap a1 = new CustomPointMap();
    assertEquals(a1.schema(), TestUtil.dataSchemaFromString(customPointMapSchemaText));
    for (Map.Entry<String, CustomPoint> e : input.entrySet()) {
        a1.put(e.getKey(), e.getValue());
        assertTrue(a1.containsKey(e.getKey()));
        assertTrue(a1.containsValue(e.getValue()));
    }
    CustomPointMap a2 = new CustomPointMap(inputDataMap);
    assertEquals(a1, a2);
    assertEquals(a1.data(), a2.data());
    for (Map.Entry<String, CustomPoint> e : input.entrySet()) {
        assertTrue(a2.containsKey(e.getKey()));
        assertTrue(a2.containsValue(e.getValue()));
    }
    for (Map.Entry<String, CustomPoint> e : input.entrySet()) {
        CustomPoint p = a1.get(e.getKey());
        assertEquals(p, e.getValue());
    }
    CustomPointMap a3 = new CustomPointMap(input.size());
    for (Map.Entry<String, CustomPoint> e : input.entrySet()) {
        String j = e.getKey() + "_";
        a3.put(j, e.getValue());
        assertEquals(a3.get(j), e.getValue());
    }
}
Also used : DataMap(com.linkedin.data.DataMap) Map(java.util.Map) TestUtil.asMap(com.linkedin.data.TestUtil.asMap) CustomPoint(com.linkedin.data.template.TestCustom.CustomPoint) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 10 with CustomPoint

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\"}}}";
    com.linkedin.pegasus.generator.test.CustomPointArray a1 = new com.linkedin.pegasus.generator.test.CustomPointArray();
    assertEquals(a1.schema(), TestUtil.dataSchemaFromString(customPointArraySchemaText));
    for (String s : input) {
        a1.add(new CustomPoint(s));
        assertTrue(a1.contains(new CustomPoint(s)));
    }
    com.linkedin.pegasus.generator.test.CustomPointArray a2 = new com.linkedin.pegasus.generator.test.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)));
    }
}
Also used : ArrayList(java.util.ArrayList) CustomPoint(com.linkedin.data.template.TestCustom.CustomPoint) DataList(com.linkedin.data.DataList) CustomPoint(com.linkedin.data.template.TestCustom.CustomPoint) Test(org.testng.annotations.Test)

Aggregations

CustomPoint (com.linkedin.data.template.TestCustom.CustomPoint)14 Test (org.testng.annotations.Test)14 DataList (com.linkedin.data.DataList)4 DataMap (com.linkedin.data.DataMap)4 TestUtil.asMap (com.linkedin.data.TestUtil.asMap)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 IOException (java.io.IOException)2