Search in sources :

Example 1 with JoinInputFactory

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"));
}
Also used : Processor(org.talend.sdk.component.runtime.output.Processor) JoinInputFactory(org.talend.sdk.component.junit.JoinInputFactory) SimpleComponentRule(org.talend.sdk.component.junit.SimpleComponentRule) Transform(org.talend.sdk.component.junit.component.Transform) Test(org.junit.jupiter.api.Test)

Example 2 with JoinInputFactory

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__);
}
Also used : Processor(org.talend.sdk.component.runtime.output.Processor) JoinInputFactory(org.talend.sdk.component.junit.JoinInputFactory) JsonObject(javax.json.JsonObject) SimpleComponentRule(org.talend.sdk.component.junit.SimpleComponentRule) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with JoinInputFactory

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());
}
Also used : JsonObject(javax.json.JsonObject) SampleProcessor(org.talend.sdk.component.junit.beam.test.SampleProcessor) 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) HashSet(java.util.HashSet) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Rule(org.junit.Rule) Arrays.asList(java.util.Arrays.asList) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Map(java.util.Map) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Json(javax.json.Json) StreamSupport(java.util.stream.StreamSupport) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ClassRule(org.junit.ClassRule) SimpleComponentRule(org.talend.sdk.component.junit.SimpleComponentRule) Collectors.toSet(java.util.stream.Collectors.toSet) TalendFn(org.talend.sdk.component.runtime.beam.TalendFn) SampleProcessor(org.talend.sdk.component.junit.beam.test.SampleProcessor) Processor(org.talend.sdk.component.runtime.output.Processor) JsonObject(javax.json.JsonObject) 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with JoinInputFactory

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());
}
Also used : Processor(org.talend.sdk.component.runtime.output.Processor) JoinInputFactory(org.talend.sdk.component.junit.JoinInputFactory) JsonObject(javax.json.JsonObject) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with JoinInputFactory

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

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