Search in sources :

Example 1 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 2 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 3 with SimpleTestData

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

the class TestTransformer method testReplaceByNameNested.

/**
 * Removes multiple nodes in a complex type, including non-leaf nodes.
 */
@Test
public void testReplaceByNameNested() throws Exception {
    SimpleTestData data = IteratorTestData.createSimpleTestData();
    Builder.create(data.getDataElement(), IterationOrder.PRE_ORDER).filterBy(Predicates.nameEquals("foo")).replace(new DataList());
    assertEquals(Builder.create(data.getDataElement(), IterationOrder.PRE_ORDER).filterBy(Predicates.pathMatchesPathSpec(new PathSpec("nested", "nested", "foo", PathSpec.WILDCARD))).count(), 0);
    assertEquals(Builder.create(data.getDataElement(), IterationOrder.PRE_ORDER).filterBy(Predicates.pathMatchesPathSpec(new PathSpec("foo", PathSpec.WILDCARD))).count(), 0);
}
Also used : DataList(com.linkedin.data.DataList) SimpleTestData(com.linkedin.data.it.IteratorTestData.SimpleTestData) PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Example 4 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<>(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<>(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 5 with SimpleTestData

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

the class TestCounter method testCountByPredicateAtPathWithFilter.

@Test
public void testCountByPredicateAtPathWithFilter() throws Exception {
    SimpleTestData data = IteratorTestData.createSimpleTestData();
    int count = Builder.create(data.getDataElement(), IterationOrder.PRE_ORDER).filterBy(Predicates.and(Predicates.pathMatchesPathSpec(IteratorTestData.PATH_TO_ID), IteratorTestData.LESS_THAN_3_CONDITION)).count();
    assertEquals(2, count);
}
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