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