Skip to content

Commit

Permalink
Fix preferential rate test
Browse files Browse the repository at this point in the history
  • Loading branch information
aowss committed Apr 11, 2024
1 parent c720e05 commit 2957800
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 90 deletions.
21 changes: 13 additions & 8 deletions spring-boot/task/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,26 @@
<packaging>jar</packaging>

<properties>
<camunda.version>8.4.0</camunda.version>
<tasklist-client.version>8.4.0.7</tasklist-client.version>
</properties>

<dependencies>
<dependency>
<groupId>io.camunda.spring</groupId>
<artifactId>spring-boot-starter-camunda</artifactId>
<groupId>io.camunda.connector</groupId>
<artifactId>spring-boot-starter-camunda-connectors</artifactId>
<version>${camunda.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
<!-- <version>${spring-boot.version}</version>-->
<!-- </dependency>-->
<dependency>
<groupId>io.camunda.connector</groupId>
<artifactId>connector-http-json</artifactId>
<version>${camunda.version}</version>
</dependency>
<dependency>
<groupId>io.camunda.connector</groupId>
<artifactId>connector-test</artifactId>
<version>${camunda.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.camunda</groupId>
<artifactId>camunda-tasklist-client-java</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

import io.camunda.zeebe.spring.client.annotation.Deployment;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@ImportAutoConfiguration({
io.camunda.connector.runtime.InboundConnectorsAutoConfiguration.class,
io.camunda.connector.runtime.OutboundConnectorsAutoConfiguration.class
})
@Deployment(resources = "classpath*:*.bpmn")
public class Application {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

@Configuration
@ConfigurationProperties(prefix = "tasklist")
@Profile("!test")
public class TaskListClientConfig {

private String url;
Expand Down Expand Up @@ -64,12 +63,14 @@ public CamundaTaskListClient camundaTaskListClient() throws TaskListException {
.jwtConfig(jwtConfig)
.build();

return CamundaTaskListClient.builder()
var client = CamundaTaskListClient.builder()
.taskListUrl(url)
.shouldReturnVariables()
.shouldLoadTruncatedVariables()
.authentication(auth)
.build();

return client;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class ProcessController {

Expand Down
22 changes: 22 additions & 0 deletions spring-boot/task/src/main/resources/application-local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# https://github.com/camunda-community-hub/spring-zeebe#configuring-camunda-platform-8-saas-connection
# https://github.com/camunda-community-hub/spring-zeebe#additional-configuration-options

zeebe:
client:
broker:
gateway-address: localhost:26500
security:
plaintext: true
cloud:
client-id: zeebe
client-secret: zecret
auth-url: http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token

tasklist:
url: http://localhost:8082
keycloak-url: http://localhost:18080
client-id: ${zeebe.client.cloud.client-id}
client-secret: ${zeebe.client.cloud.client-secret}

api:
url: http://${ENV:prod}-rates:9999/exchangeRates
24 changes: 7 additions & 17 deletions spring-boot/task/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,29 @@
# https://github.com/camunda-community-hub/spring-zeebe#configuring-camunda-platform-8-saas-connection
# https://github.com/camunda-community-hub/spring-zeebe#additional-configuration-options

#zeebe:
# client:
# cloud:
# region: ont-1
# clusterId: 35eedd8b-35e5-4373-8a4c-f211043e42da
# clientId: kMVnghsS4TV7lqocluB9AsLNNRSNsCr1
# clientSecret: EIt0BqN-bEK~hVbvN8tZO4vPgmZYQ-RbQdnqRwIsyQnZ9Bp-h5XJBT9NuS8cFnu-

#camunda:
# client:
# mode: oidc
# auth:
# client-id: zeebe
# client-secret: zecret
zeebe:
client:
broker:
gateway-address: localhost:26500
security:
plaintext: true
# connection-mode: ADDRESS
cloud:
client-id: zeebe
client-secret: zecret
auth-url: http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token

tasklist:
# url: https://ont-1.tasklist.camunda.io/35eedd8b-35e5-4373-8a4c-f211043e42da
# keycloak-url: https://login.cloud.camunda.io/oauth/token
url: http://localhost:8082
keycloak-url: http://localhost:18080
client-id: ${zeebe.client.cloud.client-id}
client-secret: ${zeebe.client.cloud.client-secret}

camunda:
connector:
polling:
enabled: false
webhook:
enabled: false

api:
url: http://${ENV:prod}-rates:9999/exchangeRates
13 changes: 8 additions & 5 deletions spring-boot/task/src/main/resources/userTask.bpmn
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<bpmn:outgoing>Flow_1necipk</bpmn:outgoing>
<bpmn:messageEventDefinition id="MessageEventDefinition_0ec01ia" messageRef="Message_3c5v476" />
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_1necipk" sourceRef="Start_ExchangeRateRequest" targetRef="Gateway_0kbfdez" />
<bpmn:sequenceFlow id="Flow_1necipk" sourceRef="Start_ExchangeRateRequest" targetRef="Gateway_LargeAmount" />
<bpmn:serviceTask id="Task_CallExchangeRateAPI" name="Call Exchange Rate API" zeebe:modelerTemplate="io.camunda.connectors.HttpJson.v2" zeebe:modelerTemplateVersion="5" zeebe:modelerTemplateIcon="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTgiIGhlaWdodD0iMTgiIHZpZXdCb3g9IjAgMCAxOCAxOCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTE3LjAzMzUgOC45OTk5N0MxNy4wMzM1IDEzLjQ0NzUgMTMuNDI4MSAxNy4wNTI5IDguOTgwNjUgMTcuMDUyOUM0LjUzMzE2IDE3LjA1MjkgMC45Mjc3NjUgMTMuNDQ3NSAwLjkyNzc2NSA4Ljk5OTk3QzAuOTI3NzY1IDQ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mn:userTask>
<bpmn:exclusiveGateway id="Gateway_0kbfdez" default="Flow_17ovhw0">
<bpmn:exclusiveGateway id="Gateway_LargeAmount" name="large amount?" default="Flow_17ovhw0">
<bpmn:incoming>Flow_1necipk</bpmn:incoming>
<bpmn:outgoing>Flow_17ovhw0</bpmn:outgoing>
<bpmn:outgoing>Flow_0ghnk0a</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:sequenceFlow id="Flow_17ovhw0" name="no" sourceRef="Gateway_0kbfdez" targetRef="Task_CallExchangeRateAPI" />
<bpmn:sequenceFlow id="Flow_0ghnk0a" name="yes" sourceRef="Gateway_0kbfdez" targetRef="UserTask_PreferentialRate">
<bpmn:sequenceFlow id="Flow_17ovhw0" name="no" sourceRef="Gateway_LargeAmount" targetRef="Task_CallExchangeRateAPI" />
<bpmn:sequenceFlow id="Flow_0ghnk0a" name="yes" sourceRef="Gateway_LargeAmount" targetRef="UserTask_PreferentialRate">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=fromAmount &gt;= 1000</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:userTask id="UserTask_PreferentialRate" name="Preferential Rate">
Expand Down Expand Up @@ -94,8 +94,11 @@
<dc:Bounds x="430" y="230" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_0kbfdez_di" bpmnElement="Gateway_0kbfdez" isMarkerVisible="true">
<bpmndi:BPMNShape id="Gateway_0kbfdez_di" bpmnElement="Gateway_LargeAmount" isMarkerVisible="true">
<dc:Bounds x="285" y="92" width="50" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="275" y="62" width="71" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1bbhmi4_di" bpmnElement="UserTask_PreferentialRate">
<dc:Bounds x="260" y="230" width="100" height="80" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,34 @@
import io.camunda.zeebe.process.test.inspections.InspectionUtility;
import io.camunda.zeebe.process.test.inspections.model.InspectedProcessInstance;
import io.camunda.zeebe.spring.test.ZeebeSpringTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
//import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static io.camunda.zeebe.spring.test.ZeebeTestThreadSupport.waitForProcessInstanceCompleted;
import static io.camunda.zeebe.spring.test.ZeebeTestThreadSupport.waitForProcessInstanceHasPassedElement;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import java.time.Duration;
import java.util.concurrent.TimeoutException;

@SpringBootTest
@AutoConfigureMockMvc
@ZeebeSpringTest
@WireMockTest(httpPort = 9999)
//@WireMockTest(httpPort = 9999)
@ActiveProfiles("test")
@DisplayName("User Task Test")
class TaskProcessTest {
Expand All @@ -36,75 +48,37 @@ class TaskProcessTest {
@Autowired
private ZeebeService zeebeService;

@Test
@DisplayName("Amount >= 1000 --> preferential rate")
void preferentialRate() {
zeebeService.startProcess(new ExchangeRateRequest("USD", "CAD", 1000));

InspectedProcessInstance processInstance = InspectionUtility
.findProcessInstances()
.withBpmnProcessId(processId)
.findFirstProcessInstance()
.get();
@Autowired
private MockMvc mvc;

waitForProcessInstanceCompleted(processInstance);
@Autowired
private WebApplicationContext webApplicationContext;

BpmnAssert.assertThat(processInstance)
.hasPassedElement("Start_ExchangeRateRequest")
.isWaitingAtElements("UserTask_PreferentialRate");
@BeforeEach
public void setup() {
//Init MockMvc Object and build
mvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}

@Test
@DisplayName("API error -> default rate")
void error() {
stubFor(
get(urlPathEqualTo("/exchangeRates"))
.withQueryParam("fromCurrency", equalTo("INVALID"))
.withQueryParam("toCurrency", equalTo("CAD"))
.withQueryParam("amount", equalTo("1000"))
.willReturn(serverError())
);

zeebeService.startProcess(new ExchangeRateRequest("INVALID", "CAD", 1000));
@DisplayName("Amount >= 1000 --> preferential rate")
void preferentialRate() throws Exception {
zeebeService.startProcess(new ExchangeRateRequest("USD", "CAD", 1000));

InspectedProcessInstance processInstance = InspectionUtility
.findProcessInstances()
.withBpmnProcessId("Process_RESTConnector")
.withBpmnProcessId(processId)
.findFirstProcessInstance()
.get();

waitForProcessInstanceCompleted(processInstance);
waitForProcessInstanceHasPassedElement(processInstance, "Gateway_LargeAmount");

BpmnAssert.assertThat(processInstance)
.hasPassedElement("Task-DefaultRate")
.hasVariableWithValue("fromCurrency", "INVALID")
.hasVariableWithValue("exchangeRate", 1.3); // default rate
}

@Test
@DisplayName("Request error -> incident")
void incident() throws InterruptedException, TimeoutException {
stubFor(
get(urlPathEqualTo("/exchangeRates"))
.withQueryParam("fromCurrency", equalTo("USD"))
.withQueryParam("toCurrency", equalTo("CAD"))
.withQueryParam("amount", equalTo("0"))
.willReturn(badRequest())
);

zeebeService.startProcess(new ExchangeRateRequest("USD", "CAD", 0));

InspectedProcessInstance processInstance = InspectionUtility
.findProcessInstances()
.withBpmnProcessId("Process_RESTConnector")
.findFirstProcessInstance()
.get();

engine.waitForBusyState(Duration.ofSeconds(10));
.isWaitingAtElements("UserTask_PreferentialRate");

BpmnAssert.assertThat(processInstance)
.hasNotPassedElement("Task_CallExchangeRateAPI")
.hasAnyIncidents();
mvc.perform(get("/task"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.length()").value(1));
}

}

0 comments on commit 2957800

Please sign in to comment.