use of org.talend.sdk.component.junit.JoinInputFactory in project component-runtime by Talend.
the class ComponentExtensionTest method processorCollector.
@Test
void processorCollector() {
final Processor processor = handler.createProcessor(Transform.class, null);
final SimpleComponentRule.Outputs outputs = handler.collect(processor, new JoinInputFactory().withInput("__default__", asList(new Transform.Record("a"), new Transform.Record("bb"))).withInput("second", asList(new Transform.Record("1"), new Transform.Record("2"))));
assertEquals(2, outputs.size());
assertEquals(asList(2, 3), outputs.get(Integer.class, "size"));
assertEquals(asList("a1", "bb2"), outputs.get(String.class, "value"));
}
use of org.talend.sdk.component.junit.JoinInputFactory in project component-runtime by Talend.
the class MycompProcessorTest method map.
@Test
@Ignore("You need to complete this test")
public void map() throws IOException {
// Processor configuration
// Setup your component configuration for the test here
final MycompProcessorConfiguration configuration = new MycompProcessorConfiguration();
// We create the component processor instance using the configuration filled above
final Processor processor = COMPONENT_FACTORY.createProcessor(MycompProcessor.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());
// Run the flow and get the outputs
final SimpleComponentRule.Outputs outputs = COMPONENT_FACTORY.collect(processor, joinInputFactory);
// TODO - Test Asserts
// test of the output branches count of the component
assertEquals(1, outputs.size());
// Here you have all your processor output branches
// You can fill in the expected data for every branch to test them
final List<JsonObject> value___default__ = outputs.get(JsonObject.class, "__default__");
assertEquals(asList(), value___default__);
}
use of org.talend.sdk.component.junit.JoinInputFactory in project component-runtime by Talend.
the class ProcessorTest method processor.
@Test
public void processor() {
final Processor processor = COMPONENT_FACTORY.createProcessor(SampleProcessor.class, new Object());
final JoinInputFactory joinInputFactory = new JoinInputFactory().withInput("__default__", asList(new SampleProcessor.Sample(1), Json.createObjectBuilder().add("data", 2).build()));
final PCollection<JsonObject> inputs = pipeline.apply(Data.of(processor.plugin(), joinInputFactory.asInputRecords()));
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());
assertEquals(2, result.size());
result.forEach(e -> assertTrue(e.containsKey("__default__") && e.containsKey("reject")));
assertEquals(new HashSet<>(asList(1, 2)), result.stream().map(e -> e.get("__default__").getInt("data")).collect(toSet()));
return null;
});
assertEquals(PipelineResult.State.DONE, pipeline.run().waitUntilFinish());
}
use of org.talend.sdk.component.junit.JoinInputFactory in project component-runtime by Talend.
the class TInOutputBeamTest method processor.
@Test
@Ignore("You need to complete this test with your own data and assertions")
public void processor() {
// Output configuration
// Setup your component configuration for the test here
final TInOutputConfiguration configuration = new TInOutputConfiguration();
// We create the component processor instance using the configuration filled above
final Processor processor = COMPONENT_FACTORY.createProcessor(TInOutput.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
inputs.apply(TalendFn.asFn(processor)).apply(Data.map(processor.plugin(), JsonObject.class));
// run the pipeline and ensure the execution was successful
assertEquals(PipelineResult.State.DONE, pipeline.run().waitUntilFinish());
}
use of org.talend.sdk.component.junit.JoinInputFactory 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());
}
Aggregations