All Downloads are FREE. Search and download functionalities are using the official Maven repository.

generator.facet.beam.BeamProcessorTest.mustache Maven / Gradle / Ivy

Go to download

Web application allowing to generate maven or gradle project skeleton to speed up component development.

There is a newer version: 10.57.0
Show newest version
package {{classPackage}};

import static java.util.Arrays.asList;
{{^isOutput}}
import static java.util.stream.Collectors.toList;
{{/isOutput}}
import static org.junit.Assert.assertEquals;

{{^isOutput}}
import java.util.stream.StreamSupport;
import java.util.List;
import java.util.Map;

{{/isOutput}}
import org.apache.beam.sdk.PipelineResult;
{{^isOutput}}
import org.apache.beam.sdk.testing.PAssert;
{{/isOutput}}
import org.apache.beam.sdk.testing.TestPipeline;
{{^isOutput}}
import org.apache.beam.sdk.transforms.SerializableFunction;
{{/isOutput}}
import org.apache.beam.sdk.values.PCollection;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.talend.sdk.component.api.record.Record;
import org.talend.sdk.component.junit.JoinInputFactory;
import org.talend.sdk.component.junit.SimpleComponentRule;
import org.talend.sdk.component.junit.beam.Data;
import org.talend.sdk.component.runtime.beam.TalendFn;
import org.talend.sdk.component.runtime.output.Processor;

public class {{testClassName}} {
    @ClassRule
    public static final SimpleComponentRule COMPONENT_FACTORY = new SimpleComponentRule("{{rootPackage}}");

    @Rule
    public transient final TestPipeline pipeline = TestPipeline.create();

    @Test
    @Ignore("You need to complete this test with your own data and assertions")
    public void processor() {
        // {{#isOutput}}Output{{/isOutput}}{{^isOutput}}Processor{{/isOutput}} configuration
        // Setup your component configuration for the test here
        final {{configurationClassName}} configuration =  new {{configurationClassName}}(){{^hasConfig}};{{/hasConfig}}
            {{#configFields}}
                {{#first}}/*{{/first}}  .set{{value}}(){{#last}} */;{{/last}}
            {{/configFields}}

        // We create the component processor instance using the configuration filled above
        final Processor processor = COMPONENT_FACTORY.createProcessor({{processorClassName}}.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()
            {{#inputBranches}}
                .withInput("{{value.key}}", asList(/* TODO - list of your input data for this branch. Instances of {{value.value}}.class */)){{#last}};{{/last}}
            {{/inputBranches}}

        // Convert it to a beam "source"
        final PCollection inputs =
                pipeline.apply(Data.of(processor.plugin(), joinInputFactory.asInputRecords()));

        // add our processor right after to see each data as configured previously
        {{^isOutput}}final PCollection> outputs = {{/isOutput}}inputs.apply(TalendFn.asFn(processor))
                .apply(Data.map(processor.plugin(), Record.class));

    {{^isOutput}}
        PAssert.that(outputs).satisfies((SerializableFunction>, Void>) input -> {
            final List> result = StreamSupport.stream(input.spliterator(), false).collect(toList());
            //TODO - test the result here

            return null;
        });
    {{/isOutput}}
        // run the pipeline and ensure the execution was successful
        assertEquals(PipelineResult.State.DONE, pipeline.run().waitUntilFinish());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy