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));
}
Aggregations