Search in sources :

Example 1 with ZeebeTestEngine

use of io.camunda.zeebe.process.test.api.ZeebeTestEngine in project zeebe-process-test by camunda.

the class PrintRecordStreamExtension method testFailed.

@Override
public void testFailed(final ExtensionContext context, final Throwable cause) {
    try {
        final Field zeebeEngineField = context.getRequiredTestClass().getDeclaredField("zeebeEngine");
        ReflectionUtils.makeAccessible(zeebeEngineField);
        final ZeebeTestEngine zeebeEngine = (ZeebeTestEngine) zeebeEngineField.get(context.getRequiredTestInstance());
        System.out.println("===== Test failed! Printing records from the stream:");
        RecordStream.of(zeebeEngine.getRecordStreamSource()).print(true);
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
Also used : ZeebeTestEngine(io.camunda.zeebe.process.test.api.ZeebeTestEngine) Field(java.lang.reflect.Field)

Example 2 with ZeebeTestEngine

use of io.camunda.zeebe.process.test.api.ZeebeTestEngine in project spring-zeebe by camunda-community-hub.

the class ZeebeTestThreadSupport method waitForProcessInstanceCompleted.

public static void waitForProcessInstanceCompleted(InspectedProcessInstance inspectedProcessInstance, Duration duration) {
    // get it in the thread of the test
    final ZeebeTestEngine engine = ENGINES.get();
    if (engine == null) {
        throw new IllegalStateException("No Zeebe engine is initialized for the current thread, annotate the test with @ZeebeSpringTest");
    }
    if (duration == null) {
        duration = DEFAULT_DURATION;
    }
    Awaitility.await().atMost(duration).untilAsserted(() -> {
        // allow the worker to work
        Thread.sleep(DEFAULT_INTERVAL_MILLIS);
        BpmnAssert.initRecordStream(RecordStream.of(Objects.requireNonNull(engine).getRecordStreamSource()));
        // use inside the awaitility thread
        assertThat(inspectedProcessInstance).isCompleted();
    });
}
Also used : ZeebeTestEngine(io.camunda.zeebe.process.test.api.ZeebeTestEngine)

Example 3 with ZeebeTestEngine

use of io.camunda.zeebe.process.test.api.ZeebeTestEngine in project zeebe-process-test by camunda-cloud.

the class PrintRecordStreamExtension method testFailed.

@Override
public void testFailed(final ExtensionContext context, final Throwable cause) {
    try {
        final Field zeebeEngineField = context.getRequiredTestClass().getDeclaredField("zeebeEngine");
        ReflectionUtils.makeAccessible(zeebeEngineField);
        final ZeebeTestEngine zeebeEngine = (ZeebeTestEngine) zeebeEngineField.get(context.getRequiredTestInstance());
        System.out.println("===== Test failed! Printing records from the stream:");
        RecordStream.of(zeebeEngine.getRecordStreamSource()).print(true);
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
Also used : ZeebeTestEngine(io.camunda.zeebe.process.test.api.ZeebeTestEngine) Field(java.lang.reflect.Field)

Example 4 with ZeebeTestEngine

use of io.camunda.zeebe.process.test.api.ZeebeTestEngine in project zeebe-process-test by camunda-cloud.

the class ZeebeProcessTestEngine method main.

public static void main(final String[] args) throws IOException {
    final ZeebeTestEngine engine = EngineFactory.create(AgentProperties.getGatewayPort());
    final EngineControlImpl engineService = new EngineControlImpl(engine);
    final Server server = ServerBuilder.forPort(AgentProperties.getControllerPort()).addService(engineService).build();
    server.start();
    // In the testcontainer extension we are waiting for this line to be logged before continuing
    // test execution. If this log gets changed please also change the extension!
    LOG.info("ZeebeProcessTestEngine container has started ...");
}
Also used : ZeebeTestEngine(io.camunda.zeebe.process.test.api.ZeebeTestEngine) Server(io.grpc.Server)

Example 5 with ZeebeTestEngine

use of io.camunda.zeebe.process.test.api.ZeebeTestEngine in project zeebe-process-test by camunda-cloud.

the class ZeebeProcessTestExtension method beforeEach.

/**
 * Before each test a new test engine gets created and started. A client to communicate with the
 * engine will also be created. Together with a {@link RecordStream} these will be injected in the
 * fields of the test class, if they are available.
 *
 * @param extensionContext jUnit5 extension context
 */
@Override
public void beforeEach(final ExtensionContext extensionContext) {
    final ZeebeTestEngine engine = EngineFactory.create();
    engine.start();
    final ZeebeClient client = engine.createClient();
    final RecordStream recordStream = RecordStream.of(engine.getRecordStreamSource());
    try {
        injectFields(extensionContext, engine, client, recordStream);
    } catch (final Exception ex) {
        client.close();
        engine.stop();
        throw ex;
    }
    BpmnAssert.initRecordStream(recordStream);
    getStore(extensionContext).put(KEY_ZEEBE_CLIENT, client);
    getStore(extensionContext).put(KEY_ZEEBE_ENGINE, engine);
}
Also used : ZeebeTestEngine(io.camunda.zeebe.process.test.api.ZeebeTestEngine) RecordStream(io.camunda.zeebe.process.test.filters.RecordStream) ZeebeClient(io.camunda.zeebe.client.ZeebeClient)

Aggregations

ZeebeTestEngine (io.camunda.zeebe.process.test.api.ZeebeTestEngine)13 ZeebeClient (io.camunda.zeebe.client.ZeebeClient)4 RecordStream (io.camunda.zeebe.process.test.filters.RecordStream)2 Server (io.grpc.Server)2 Field (java.lang.reflect.Field)2 Bean (org.springframework.context.annotation.Bean)1 Primary (org.springframework.context.annotation.Primary)1