Search in sources :

Example 6 with SimpleTestData

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

the class TestTransformer method testReplaceByPredicateAtPath.

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

Example 7 with SimpleTestData

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

the class TestTransformer method testReplaceAtPathNested.

@Test
public void testReplaceAtPathNested() throws Exception {
    SimpleTestData data = IteratorTestData.createSimpleTestData();
    Builder.create(data.getDataElement(), IterationOrder.PRE_ORDER).filterBy(Predicates.pathMatchesPathSpec(new PathSpec("nested", "nested"))).replace(new DataMap());
    int count = Builder.create(data.getDataElement(), IterationOrder.PRE_ORDER).filterBy(Predicates.pathMatchesPathSpec(new PathSpec("nested", "nested", "foo"))).count();
    assertEquals(count, 0);
}
Also used : SimpleTestData(com.linkedin.data.it.IteratorTestData.SimpleTestData) PathSpec(com.linkedin.data.schema.PathSpec) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 8 with SimpleTestData

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

the class TestTransformer method testReplaceBySchemaNameNested.

@Test
public void testReplaceBySchemaNameNested() throws Exception {
    SimpleTestData data = IteratorTestData.createSimpleTestData();
    Builder.create(data.getDataElement(), IterationOrder.PRE_ORDER).filterBy(Predicates.dataSchemaNameEquals("Bar")).replace(500);
    List<Object> accumulate = new ArrayList<Object>(Builder.create(data.getDataElement(), IterationOrder.PRE_ORDER).filterBy(Predicates.pathMatchesPathSpec(new PathSpec("nested", "nested", "foo", PathSpec.WILDCARD))).accumulateValues());
    assertEquals(accumulate.size(), 2);
    assertEquals(accumulate.get(0), 500);
    assertEquals(accumulate.get(1), 500);
    accumulate = new ArrayList<Object>(Builder.create(data.getDataElement(), IterationOrder.PRE_ORDER).filterBy(Predicates.pathMatchesPathSpec(new PathSpec("foo", PathSpec.WILDCARD))).accumulateValues());
    assertEquals(accumulate.size(), 3);
    assertEquals(accumulate.get(0), 500);
    assertEquals(accumulate.get(1), 500);
    assertEquals(accumulate.get(2), 500);
}
Also used : SimpleTestData(com.linkedin.data.it.IteratorTestData.SimpleTestData) ArrayList(java.util.ArrayList) PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Example 9 with SimpleTestData

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

the class TestValueAccumulator method testAccumulateByPathAndFilter.

@Test
public void testAccumulateByPathAndFilter() throws Exception {
    SimpleTestData data = IteratorTestData.createSimpleTestData();
    List<Object> ids = new ArrayList<Object>(Builder.create(data.getDataElement(), IterationOrder.PRE_ORDER).filterBy(Predicates.and(Predicates.pathMatchesPathSpec(IteratorTestData.PATH_TO_ID), IteratorTestData.LESS_THAN_3_CONDITION)).accumulateValues());
    assertEquals(2, ids.size());
    assertTrue(ids.contains(1));
    assertTrue(ids.contains(2));
}
Also used : SimpleTestData(com.linkedin.data.it.IteratorTestData.SimpleTestData) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 10 with SimpleTestData

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

the class TestValueAccumulator method testAccumulateByPath.

@Test
public void testAccumulateByPath() throws Exception {
    SimpleTestData data = IteratorTestData.createSimpleTestData();
    List<Object> ids = new LinkedList<Object>();
    Builder.create(data.getDataElement(), IterationOrder.PRE_ORDER).filterBy(Predicates.and(Predicates.pathMatchesPattern("foo", Wildcard.ANY_ONE, "id"))).accumulateValues(ids);
    assertEquals(3, ids.size());
    assertTrue(ids.contains(1));
    assertTrue(ids.contains(2));
    assertTrue(ids.contains(3));
}
Also used : SimpleTestData(com.linkedin.data.it.IteratorTestData.SimpleTestData) LinkedList(java.util.LinkedList) 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