Search in sources :

Example 1 with TestLink

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

the class FilterNodeTest method receive_should_filter_with_simple_predicate.

@Test
public void receive_should_filter_with_simple_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 TestLink link = new TestLink(new BasicNode());
    final FilterNode node = new FilterNode((row, metadata) -> row.getTdpId() == 1);
    node.setLink(link);
    // when
    node.receive(row0, metadata0);
    node.receive(row1, metadata1);
    // then
    assertThat(link.getEmittedRows(), hasSize(1));
    assertThat(link.getEmittedRows(), contains(row1));
    assertThat(link.getEmittedMetadata(), hasSize(1));
    assertThat(link.getEmittedMetadata(), contains(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)

Example 2 with TestLink

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

the class NodeBuilderTest method should_append_node_with_provided_link.

@Test
public void should_append_node_with_provided_link() {
    // given
    final Node nextNode = new BasicNode();
    // when
    final Node node = NodeBuilder.source().to((n) -> new TestLink(n[0]), nextNode).build();
    // then
    assertThat(node.getLink(), instanceOf(TestLink.class));
    assertThat(node.getLink().getTarget(), is(nextNode));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Matchers.arrayContaining(org.hamcrest.Matchers.arrayContaining) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) Predicate(java.util.function.Predicate) FilteredSourceNode(org.talend.dataprep.transformation.pipeline.node.FilteredSourceNode) BasicLink(org.talend.dataprep.transformation.pipeline.link.BasicLink) Test(org.junit.Test) SourceNode(org.talend.dataprep.transformation.pipeline.node.SourceNode) TestLink(org.talend.dataprep.transformation.pipeline.TestLink) Node(org.talend.dataprep.transformation.pipeline.Node) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) CloneLink(org.talend.dataprep.transformation.pipeline.link.CloneLink) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) BasicNode(org.talend.dataprep.transformation.pipeline.node.BasicNode) ZipLink(org.talend.dataprep.transformation.pipeline.node.ZipLink) TestLink(org.talend.dataprep.transformation.pipeline.TestLink) FilteredSourceNode(org.talend.dataprep.transformation.pipeline.node.FilteredSourceNode) SourceNode(org.talend.dataprep.transformation.pipeline.node.SourceNode) Node(org.talend.dataprep.transformation.pipeline.Node) BasicNode(org.talend.dataprep.transformation.pipeline.node.BasicNode) BasicNode(org.talend.dataprep.transformation.pipeline.node.BasicNode) Test(org.junit.Test)

Example 3 with TestLink

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

the class BasicNodeTest method should_emit_multi_input_row_to_its_link.

@Test
public void should_emit_multi_input_row_to_its_link() {
    // given
    final TestLink link = new TestLink(new BasicNode());
    final BasicNode node = new BasicNode();
    node.setLink(link);
    final DataSetRow row1 = new DataSetRow(new HashMap<>());
    final DataSetRow row2 = new DataSetRow(new HashMap<>());
    final RowMetadata metadata1 = new RowMetadata(new ArrayList<>());
    final RowMetadata metadata2 = new RowMetadata(new ArrayList<>());
    final DataSetRow[] rows = new DataSetRow[] { row1, row2 };
    final RowMetadata[] metadatas = new RowMetadata[] { metadata1, metadata2 };
    // when
    node.receive(rows, metadatas);
    // then
    assertThat(link.getEmittedRows(), hasSize(2));
    assertThat(link.getEmittedRows(), contains(rows));
    assertThat(link.getEmittedMetadata(), hasSize(2));
    assertThat(link.getEmittedMetadata(), contains(metadatas));
}
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)

Example 4 with TestLink

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

the class BasicNodeTest method should_emit_signal_to_all_targets.

@Test
public void should_emit_signal_to_all_targets() {
    // given
    final TestLink link = new TestLink(null);
    final BasicNode node = new BasicNode();
    node.setLink(link);
    // when
    node.signal(CANCEL);
    // then
    assertThat(link.getEmittedSignals(), hasSize(1));
    assertThat(link.getEmittedSignals(), contains(CANCEL));
}
Also used : TestLink(org.talend.dataprep.transformation.pipeline.TestLink) Test(org.junit.Test)

Example 5 with TestLink

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

the class BasicNodeTest method should_emit_single_input_row_to_its_link.

@Test
public void should_emit_single_input_row_to_its_link() {
    // given
    final TestLink link = new TestLink(new BasicNode());
    final BasicNode node = new BasicNode();
    node.setLink(link);
    final DataSetRow row = new DataSetRow(new HashMap<>());
    final RowMetadata metadata = new RowMetadata(new ArrayList<>());
    // when
    node.receive(row, metadata);
    // then
    assertThat(link.getEmittedRows(), hasSize(1));
    assertThat(link.getEmittedRows(), contains(row));
    assertThat(link.getEmittedMetadata(), hasSize(1));
    assertThat(link.getEmittedMetadata(), contains(metadata));
}
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