Search in sources :

Example 1 with LoopState

use of org.talend.sdk.component.runtime.di.beam.LoopState in project component-runtime by Talend.

the class QueueOutputTest method execution.

@Test
void execution() {
    final QueueOutput output = new QueueOutput("test", "test", "test", null);
    output.setState(new JobStateAware.State());
    output.onNext(name -> Branches.DEFAULT_BRANCH.equals(name) ? Json.createObjectBuilder().add("id", 1).build() : null, name -> value -> {
        throw new UnsupportedOperationException();
    });
    final LoopState loopState = LoopState.lookup(output.getStateId());
    loopState.end();
    final JsonObject next = loopState.next();
    assertNotNull(next);
    assertEquals(1, next.getInt("id"));
    assertNull(loopState.next());
}
Also used : LoopState(org.talend.sdk.component.runtime.di.beam.LoopState) JobStateAware(org.talend.sdk.component.runtime.di.JobStateAware) JsonObject(javax.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 2 with LoopState

use of org.talend.sdk.component.runtime.di.beam.LoopState in project component-runtime by Talend.

the class QueueMapperTest method execution.

@Test
void execution() {
    final QueueMapper mapper = new QueueMapper("test", "test", "test", null);
    try {
        mapper.setState(new JobStateAware.State());
    } catch (final NullPointerException npe) {
    // not sexy but for the test it is ok
    }
    final Input input = mapper.create();
    final LoopState lookup = LoopState.lookup(mapper.getStateId());
    lookup.push(Json.createObjectBuilder().add("id", 1).build());
    lookup.end();
    assertEquals(1, JsonObject.class.cast(input.next()).getInt("id"));
    assertNull(input.next());
}
Also used : LoopState(org.talend.sdk.component.runtime.di.beam.LoopState) Input(org.talend.sdk.component.runtime.input.Input) JobStateAware(org.talend.sdk.component.runtime.di.JobStateAware) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 JobStateAware (org.talend.sdk.component.runtime.di.JobStateAware)2 LoopState (org.talend.sdk.component.runtime.di.beam.LoopState)2 JsonObject (javax.json.JsonObject)1 Input (org.talend.sdk.component.runtime.input.Input)1