Search in sources :

Example 11 with SimpleTestData

use of com.linkedin.data.it.IteratorTestData.SimpleTestData in project rest.li by linkedin.

the class TestCounter method testCountByPredicateAtPath.

@Test
public void testCountByPredicateAtPath() throws Exception {
    SimpleTestData data = IteratorTestData.createSimpleTestData();
    int count = Builder.create(data.getDataElement(), IterationOrder.PRE_ORDER).filterBy(Predicates.pathMatchesPathSpec(IteratorTestData.PATH_TO_ID)).count();
    assertEquals(3, count);
}
Also used : SimpleTestData(com.linkedin.data.it.IteratorTestData.SimpleTestData) Test(org.testng.annotations.Test)

Example 12 with SimpleTestData

use of com.linkedin.data.it.IteratorTestData.SimpleTestData in project rest.li by linkedin.

the class TestTransformer method testReplaceByPredicate.

@Test
public void testReplaceByPredicate() throws Exception {
    SimpleTestData data = IteratorTestData.createSimpleTestData();
    Builder.create(data.getDataElement(), IterationOrder.PRE_ORDER).filterBy(Predicates.pathMatchesPathSpec(IteratorTestData.PATH_TO_ID)).replace(100);
    assertEquals(data.getValue().getDataList("foo").getDataMap(0).getInteger("id").intValue(), 100);
    assertEquals(data.getValue().getDataList("foo").getDataMap(1).getInteger("id").intValue(), 100);
    assertEquals(data.getValue().getDataList("foo").getDataMap(2).getInteger("id").intValue(), 100);
}
Also used : SimpleTestData(com.linkedin.data.it.IteratorTestData.SimpleTestData) Test(org.testng.annotations.Test)

Example 13 with SimpleTestData

use of com.linkedin.data.it.IteratorTestData.SimpleTestData in project rest.li by linkedin.

the class TestTransformer method testReplaceRoot.

@Test
public void testReplaceRoot() throws Exception {
    SimpleTestData data = IteratorTestData.createSimpleTestData();
    Object result = Builder.create(data.getDataElement(), IterationOrder.PRE_ORDER).filterBy(Predicates.dataSchemaNameEquals("Foo")).replace(new DataMap());
    assertTrue(result instanceof DataMap);
    assertEquals(((DataMap) result).size(), 0);
}
Also used : SimpleTestData(com.linkedin.data.it.IteratorTestData.SimpleTestData) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 14 with SimpleTestData

use of com.linkedin.data.it.IteratorTestData.SimpleTestData in project rest.li by linkedin.

the class TestTransformer method testTransformByPredicateAtPath.

@Test
public void testTransformByPredicateAtPath() throws Exception {
    SimpleTestData data = IteratorTestData.createSimpleTestData();
    Builder.create(data.getDataElement(), IterationOrder.PRE_ORDER).filterBy(Predicates.pathMatchesPattern("foo", Wildcard.ANY_ONE, "id")).transform(plusTenTransform);
    assertEquals(data.getValue().getDataList("foo").getDataMap(0).getInteger("id").intValue(), 11);
    assertEquals(data.getValue().getDataList("foo").getDataMap(1).getInteger("id").intValue(), 12);
    assertEquals(data.getValue().getDataList("foo").getDataMap(2).getInteger("id").intValue(), 13);
}
Also used : SimpleTestData(com.linkedin.data.it.IteratorTestData.SimpleTestData) Test(org.testng.annotations.Test)

Aggregations

SimpleTestData (com.linkedin.data.it.IteratorTestData.SimpleTestData)14 Test (org.testng.annotations.Test)14 SimpleDataElement (com.linkedin.data.element.SimpleDataElement)3 PathSpec (com.linkedin.data.schema.PathSpec)3 DataMap (com.linkedin.data.DataMap)2 ArrayList (java.util.ArrayList)2 DataList (com.linkedin.data.DataList)1 LinkedList (java.util.LinkedList)1