Search in sources :

Example 6 with TestLink

use of org.talend.dataprep.transformation.pipeline.TestLink in project data-prep by Talend.

the class FilterNodeTest method receive_multi_should_filter_with_multi_predicate.

@Test
public void receive_multi_should_filter_with_multi_predicate() throws Exception {
    // given
    final RowMetadata metadata0 = new RowMetadata();
    final DataSetRow row0 = new DataSetRow(new HashMap<>());
    // does not pass the predicate
    row0.setTdpId(0L);
    final RowMetadata metadata1 = new RowMetadata();
    final DataSetRow row1 = new DataSetRow(new HashMap<>());
    // pass the predicate
    row1.setTdpId(1L);
    final RowMetadata metadata2 = new RowMetadata();
    final DataSetRow row2 = new DataSetRow(new HashMap<>());
    // does not pass the predicate
    row2.setTdpId(2L);
    final RowMetadata metadata3 = new RowMetadata();
    final DataSetRow row3 = new DataSetRow(new HashMap<>());
    // pass the predicate
    row3.setTdpId(3L);
    final RowMetadata[] metadataGroup0 = new RowMetadata[] { metadata0, metadata1 };
    // pass the predicate
    final DataSetRow[] rowGroup0 = new DataSetRow[] { row0, row1 };
    final RowMetadata[] metadataGroup1 = new RowMetadata[] { metadata2, metadata3 };
    // des not pass the predicate
    final DataSetRow[] rowGroup1 = new DataSetRow[] { row2, row3 };
    final TestLink link = new TestLink(new BasicNode());
    final FilterNode node = new FilterNode((row, metadata) -> true, (row, metadata) -> row.getTdpId() == 1);
    node.setLink(link);
    // when
    node.receive(rowGroup0, metadataGroup0);
    node.receive(rowGroup1, metadataGroup1);
    // then
    assertThat(link.getEmittedRows(), hasSize(2));
    assertThat(link.getEmittedRows(), contains(row0, row1));
    assertThat(link.getEmittedMetadata(), hasSize(2));
    assertThat(link.getEmittedMetadata(), contains(metadata0, metadata1));
}
Also used : TestLink(org.talend.dataprep.transformation.pipeline.TestLink) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 TestLink (org.talend.dataprep.transformation.pipeline.TestLink)6 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)5 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)4 Predicate (java.util.function.Predicate)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.arrayContaining (org.hamcrest.Matchers.arrayContaining)1 IsInstanceOf.instanceOf (org.hamcrest.core.IsInstanceOf.instanceOf)1 Node (org.talend.dataprep.transformation.pipeline.Node)1 BasicLink (org.talend.dataprep.transformation.pipeline.link.BasicLink)1 CloneLink (org.talend.dataprep.transformation.pipeline.link.CloneLink)1 BasicNode (org.talend.dataprep.transformation.pipeline.node.BasicNode)1 FilteredSourceNode (org.talend.dataprep.transformation.pipeline.node.FilteredSourceNode)1 SourceNode (org.talend.dataprep.transformation.pipeline.node.SourceNode)1 ZipLink (org.talend.dataprep.transformation.pipeline.node.ZipLink)1