Search in sources :

Example 1 with Data

use of org.talend.sdk.component.junit.beam.Data in project component-runtime by Talend.

the class TInProcessorBeamTest method processor.

@Test
@Ignore("You need to complete this test with your own data and assertions")
public void processor() {
    // Processor configuration
    // Setup your component configuration for the test here
    final TInProcessorConfiguration configuration = new TInProcessorConfiguration();
    // We create the component processor instance using the configuration filled above
    final Processor processor = COMPONENT_FACTORY.createProcessor(TInProcessor.class, configuration);
    // The join input factory construct inputs test data for every input branch you have defined for this component
    // Make sure to fil in some test data for the branches you want to test
    // You can also remove the branches that you don't need from the factory below
    final JoinInputFactory joinInputFactory = new JoinInputFactory().withInput("__default__", asList());
    // Convert it to a beam "source"
    final PCollection<JsonObject> inputs = pipeline.apply(Data.of(processor.plugin(), joinInputFactory.asInputRecords()));
    // add our processor right after to see each data as configured previously
    final PCollection<Map<String, JsonObject>> outputs = inputs.apply(TalendFn.asFn(processor)).apply(Data.map(processor.plugin(), JsonObject.class));
    PAssert.that(outputs).satisfies((SerializableFunction<Iterable<Map<String, JsonObject>>, Void>) input -> {
        final List<Map<String, JsonObject>> result = StreamSupport.stream(input.spliterator(), false).collect(toList());
        return null;
    });
    // run the pipeline and ensure the execution was successful
    assertEquals(PipelineResult.State.DONE, pipeline.run().waitUntilFinish());
}
Also used : JsonObject(javax.json.JsonObject) PAssert(org.apache.beam.sdk.testing.PAssert) PipelineResult(org.apache.beam.sdk.PipelineResult) SerializableFunction(org.apache.beam.sdk.transforms.SerializableFunction) Test(org.junit.Test) JoinInputFactory(org.talend.sdk.component.junit.JoinInputFactory) PCollection(org.apache.beam.sdk.values.PCollection) Processor(org.talend.sdk.component.runtime.output.Processor) Data(org.talend.sdk.component.junit.beam.Data) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Rule(org.junit.Rule) Ignore(org.junit.Ignore) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) StreamSupport(java.util.stream.StreamSupport) ClassRule(org.junit.ClassRule) SimpleComponentRule(org.talend.sdk.component.junit.SimpleComponentRule) Assert.assertEquals(org.junit.Assert.assertEquals) TalendFn(org.talend.sdk.component.runtime.beam.TalendFn) Processor(org.talend.sdk.component.runtime.output.Processor) JoinInputFactory(org.talend.sdk.component.junit.JoinInputFactory) JsonObject(javax.json.JsonObject) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Map (java.util.Map)1 Collectors.toList (java.util.stream.Collectors.toList)1 StreamSupport (java.util.stream.StreamSupport)1 JsonObject (javax.json.JsonObject)1 PipelineResult (org.apache.beam.sdk.PipelineResult)1 PAssert (org.apache.beam.sdk.testing.PAssert)1 TestPipeline (org.apache.beam.sdk.testing.TestPipeline)1 SerializableFunction (org.apache.beam.sdk.transforms.SerializableFunction)1 PCollection (org.apache.beam.sdk.values.PCollection)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 ClassRule (org.junit.ClassRule)1 Ignore (org.junit.Ignore)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 JoinInputFactory (org.talend.sdk.component.junit.JoinInputFactory)1 SimpleComponentRule (org.talend.sdk.component.junit.SimpleComponentRule)1 Data (org.talend.sdk.component.junit.beam.Data)1 TalendFn (org.talend.sdk.component.runtime.beam.TalendFn)1