|
| 1 | +package io.opentelemetry.instrumentation.camunda.v7_0; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 4 | +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; |
| 5 | + |
| 6 | +import static io.opentelemetry.api.common.AttributeKey.stringKey; |
| 7 | +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; |
| 8 | + |
| 9 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 10 | + |
| 11 | +import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; |
| 12 | +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; |
| 13 | + |
| 14 | +import io.opentelemetry.api.trace.Span; |
| 15 | +import io.opentelemetry.api.trace.SpanContext; |
| 16 | +import io.opentelemetry.context.Context; |
| 17 | +import io.opentelemetry.context.Scope; |
| 18 | +import org.camunda.bpm.engine.ProcessEngine; |
| 19 | +import org.camunda.bpm.engine.ProcessEngineConfiguration; |
| 20 | +import org.camunda.bpm.engine.HistoryService; |
| 21 | +import org.camunda.bpm.engine.RuntimeService; |
| 22 | +import org.camunda.bpm.engine.repository.Deployment; |
| 23 | +import org.camunda.bpm.engine.runtime.ProcessInstance; |
| 24 | +import org.camunda.bpm.engine.test.mock.Mocks; |
| 25 | +import org.junit.jupiter.api.AfterEach; |
| 26 | +import org.junit.jupiter.api.BeforeEach; |
| 27 | +import org.junit.jupiter.api.Test; |
| 28 | + |
| 29 | +import io.opentelemetry.api.trace.SpanKind; |
| 30 | + |
| 31 | +import io.opentelemetry.semconv.ServerAttributes; |
| 32 | + |
| 33 | +public abstract class AbstractCamundaTest { |
| 34 | + |
| 35 | + @RegisterExtension |
| 36 | + private static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); |
| 37 | + |
| 38 | + private ProcessEngine processEngine; |
| 39 | + private RuntimeService runtimeService; |
| 40 | + private HistoryService historyService; |
| 41 | + |
| 42 | + @BeforeEach |
| 43 | + void setUp() { |
| 44 | + processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration() |
| 45 | + .buildProcessEngine(); |
| 46 | + runtimeService = processEngine.getRuntimeService(); |
| 47 | + historyService = processEngine.getHistoryService(); |
| 48 | + |
| 49 | + Product mockDelegate = new Product(); |
| 50 | + |
| 51 | + Mocks.register("Product", mockDelegate); |
| 52 | + } |
| 53 | + |
| 54 | + @AfterEach |
| 55 | + void tearDown() { |
| 56 | + processEngine.close(); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + void testProcessExecutionAllSuccess() { |
| 61 | + Deployment deployment = processEngine.getRepositoryService().createDeployment() |
| 62 | + .addClasspathResource("testMainProcess.bpmn").addClasspathResource("customerSubProcess.bpmn") |
| 63 | + .deploy(); |
| 64 | + |
| 65 | + ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testMainProcess"); |
| 66 | + |
| 67 | + assertNotNull(processInstance); |
| 68 | + |
| 69 | + testing.waitAndAssertTracesWithoutScopeVersionVerification( |
| 70 | + trace -> |
| 71 | + trace.hasSpansSatisfyingExactly( |
| 72 | + span -> |
| 73 | + span.hasName("testMainProcess") |
| 74 | + .hasKind(SpanKind.INTERNAL) |
| 75 | + .hasAttributesSatisfyingExactly( |
| 76 | + equalTo(stringKey("camunda.processdefinitionkey"), "testMainProcess")), |
| 77 | + span -> |
| 78 | + span.hasName("Get Product Info Task") |
| 79 | + .hasKind(SpanKind.INTERNAL) |
| 80 | + .hasAttributesSatisfyingExactly( |
| 81 | + equalTo(stringKey("camunda.activityid"), "getProductInfo"), |
| 82 | + satisfies(stringKey("camunda.processdefinitionid"), value -> value.startsWith("testMainProcess")), |
| 83 | + satisfies(stringKey("camunda.processinstanceid"), value -> assertNotNull(value)), |
| 84 | + equalTo(stringKey("camunda.activityname"), "Get Product Info")), |
| 85 | + span -> |
| 86 | + span.hasName("Verify Customer Task") |
| 87 | + .hasKind(SpanKind.INTERNAL) |
| 88 | + .hasAttributesSatisfyingExactly( |
| 89 | + equalTo(stringKey("camunda.activityid"), "verifyCustomer"), |
| 90 | + satisfies(stringKey("camunda.processdefinitionid"), value -> value.startsWith("testMainProcess")), |
| 91 | + satisfies(stringKey("camunda.processinstanceid"), value -> assertNotNull(value)), |
| 92 | + equalTo(stringKey("camunda.activityname"), "Verify Customer")), |
| 93 | + span -> |
| 94 | + span.hasName("End Event") |
| 95 | + .hasKind(SpanKind.INTERNAL) |
| 96 | + .hasAttributesSatisfyingExactly( |
| 97 | + satisfies(stringKey("camunda.processdefinitionid"), value -> value.startsWith("customerSubProcess")), |
| 98 | + equalTo(stringKey("camunda.activityid"), "Event_12mjag6"), |
| 99 | + satisfies(stringKey("camunda.processinstanceid"), value -> assertNotNull(value)), |
| 100 | + equalTo(stringKey("camunda.activityname"), "End")), |
| 101 | + span -> |
| 102 | + span.hasName("Send Product Info Task") |
| 103 | + .hasKind(SpanKind.INTERNAL) |
| 104 | + .hasAttributesSatisfyingExactly( |
| 105 | + equalTo(stringKey("camunda.activityid"), "sendProductInfo"), |
| 106 | + satisfies(stringKey("camunda.processdefinitionid"), value -> value.startsWith("testMainProcess")), |
| 107 | + satisfies(stringKey("camunda.processinstanceid"), value -> assertNotNull(value)), |
| 108 | + equalTo(stringKey("camunda.activityname"), "Send Product Info")), |
| 109 | + span -> |
| 110 | + span.hasName("End Event") |
| 111 | + .hasKind(SpanKind.INTERNAL) |
| 112 | + .hasAttributesSatisfyingExactly( |
| 113 | + satisfies(stringKey("camunda.processdefinitionid"), value -> value.startsWith("testMainProcess")), |
| 114 | + equalTo(stringKey("camunda.activityid"), "Event_110t6od"), |
| 115 | + satisfies(stringKey("camunda.processinstanceid"), value -> assertNotNull(value)), |
| 116 | + equalTo(stringKey("camunda.activityname"), "End")))); |
| 117 | + |
| 118 | + historyService.deleteHistoricProcessInstanceIfExists(processInstance.getId()); |
| 119 | + processEngine.getRepositoryService().deleteDeployment(deployment.getId(), true); |
| 120 | + } |
| 121 | + |
| 122 | +} |
0 commit comments