package org.camunda.bpm.extension.process_test_coverage.examples;

import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.test.Deployment;
import org.camunda.bpm.extension.process_test_coverage.junit5.ProcessEngineCoverageExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests.*;

@ExtendWith(ProcessEngineCoverageExtension.class)
@Deployment(resources = "order-process.bpmn")
public class OrderProcessTest {

    @RegisterExtension
    static ProcessEngineCoverageExtension extension = ProcessEngineCoverageExtension.builder()
            .assertClassCoverageAtLeast(0.9).build();

    @Test
    public void shouldExecuteHappyPath() {
        final ProcessInstance instance = this.startProcess();

        assertThat(instance).isWaitingAt("Task_ProcessOrder");

        complete(task(), withVariables("orderOk", true));

        assertThat(instance).isWaitingAt("Task_DeliverOrder");

        complete(task());

        assertThat(instance)
                .hasPassed("Event_OrderProcessed")
                .isEnded();
    }

    @Test
    public void shouldCancelOrder() {
        final ProcessInstance instance = this.startProcess();

        assertThat(instance).isWaitingAt("Task_ProcessOrder");

        complete(task(), withVariables("orderOk", false));

        assertThat(instance)
                .hasPassed("Event_OrderCancelled")
                .isEnded();
    }


    private ProcessInstance startProcess() {
        return runtimeService().startProcessInstanceByKey("order-process");
    }


}

@@ -345,66 +345,8 @@
 ith;
-%0Aimport org.junit.jupiter.api.extension.RegisterExtension;
 %0A%0Aim
@@ -553,181 +553,8 @@
  %7B%0A%0A
-    @RegisterExtension%0A    static ProcessEngineCoverageExtension extension = ProcessEngineCoverageExtension.builder()%0A            .assertClassCoverageAtLeast(0.9).build();%0A%0A
     

correct junit5 example