Skip to content

Commit

Permalink
chore(test): Add test to verify collaboration is working with inbound…
Browse files Browse the repository at this point in the history
… webhook.
  • Loading branch information
sbuettner committed Jun 12, 2023
1 parent 657b0c8 commit 1a243db
Show file tree
Hide file tree
Showing 4 changed files with 298 additions and 5 deletions.
43 changes: 38 additions & 5 deletions connector-runtime/connector-runtime-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,42 @@
<artifactId>camunda-operate-client-java</artifactId>
</dependency>

<dependency>
<groupId>io.camunda.connector</groupId>
<artifactId>connector-runtime-core</artifactId>
</dependency>
</dependencies>
<dependency>
<groupId>io.camunda.connector</groupId>
<artifactId>connector-runtime-core</artifactId>
</dependency>

<!-- Test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.runtime.inbound.importer;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import io.camunda.connector.impl.inbound.InboundConnectorProperties;
import io.camunda.operate.CamundaOperateClient;
import io.camunda.operate.dto.ProcessDefinition;
import io.camunda.zeebe.model.bpmn.Bpmn;
import java.io.FileInputStream;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.util.ResourceUtils;

public class ProcessDefinitionInspectorUtilTests {

@Test
public void testSingleWebhookInCollaboration() throws Exception {
var inboundConnectors = fromModel("single-webhook-collaboration.bpmn");
assertEquals(inboundConnectors.size(), 1);
assertEquals(inboundConnectors.get(0).getElementId(), "start_event");
}

@Test
public void testMultipleWebhooksInCollaboration() throws Exception {
var inboundConnectors = fromModel("multi-webhook-collaboration.bpmn");
assertEquals(inboundConnectors.size(), 2);
assertEquals(inboundConnectors.get(0).getElementId(), "start_event");
assertEquals(inboundConnectors.get(1).getElementId(), "intermediate_event");
}

private List<InboundConnectorProperties> fromModel(String fileName) {
try {
var operateClientMock = mock(CamundaOperateClient.class);
var inspector = new ProcessDefinitionInspector(operateClientMock);
var modelFile = ResourceUtils.getFile("classpath:bpmn/" + fileName);
var model = Bpmn.readModelFromStream(new FileInputStream(modelFile));
var processDefinitionMock = mock(ProcessDefinition.class);
when(processDefinitionMock.getKey()).thenReturn(1L);
when(operateClientMock.getProcessDefinitionModel(1L)).thenReturn(model);
return inspector.findInboundConnectors(processDefinitionMock);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1no15pe" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.11.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.2.0">
<bpmn:collaboration id="Collaboration_1fkq2ek">
<bpmn:participant id="Participant_14ueoe7" processRef="Process_11sdck4" />
<bpmn:participant id="Participant_0iq8omk" processRef="Process_1jqzy4q" />
<bpmn:messageFlow id="Flow_0v8mcd7" sourceRef="Activity_0bbhjnc" targetRef="Activity_0wgjxnj" />
<bpmn:messageFlow id="Flow_0v0wf6z" sourceRef="Activity_1svog89" targetRef="Event_18uvu3b" />
</bpmn:collaboration>
<bpmn:process id="Process_11sdck4" isExecutable="true">
<bpmn:task id="Activity_0wgjxnj" name="yo">
<bpmn:outgoing>Flow_1c6ej6l</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_1c6ej6l" sourceRef="Activity_0wgjxnj" targetRef="Event_19je4ca" />
<bpmn:endEvent id="Event_19je4ca">
<bpmn:incoming>Flow_1c6ej6l</bpmn:incoming>
</bpmn:endEvent>
<bpmn:task id="Activity_1svog89">
<bpmn:incoming>Flow_0oawvuc</bpmn:incoming>
</bpmn:task>
<bpmn:startEvent id="start_event" zeebe:modelerTemplate="io.camunda.connectors.webhook.WebhookConnector.v1" zeebe:modelerTemplateVersion="3" zeebe:modelerTemplateIcon="data:image/svg+xml,%3Csvg id=&#39;icon&#39; xmlns=&#39;http://www.w3.org/2000/svg&#39; width=&#39;18&#39; height=&#39;18&#39; viewBox=&#39;0 0 32 32&#39;%3E%3Cdefs%3E%3Cstyle%3E .cls-1 %7B fill: none; %7D %3C/style%3E%3C/defs%3E%3Cpath d=&#39;M24,26a3,3,0,1,0-2.8164-4H13v1a5,5,0,1,1-5-5V16a7,7,0,1,0,6.9287,8h6.2549A2.9914,2.9914,0,0,0,24,26Z&#39;/%3E%3Cpath d=&#39;M24,16a7.024,7.024,0,0,0-2.57.4873l-3.1656-5.5395a3.0469,3.0469,0,1,0-1.7326.9985l4.1189,7.2085.8686-.4976a5.0006,5.0006,0,1,1-1.851,6.8418L17.937,26.501A7.0005,7.0005,0,1,0,24,16Z&#39;/%3E%3Cpath d=&#39;M8.532,20.0537a3.03,3.03,0,1,0,1.7326.9985C11.74,18.47,13.86,14.7607,13.89,14.708l.4976-.8682-.8677-.497a5,5,0,1,1,6.812-1.8438l1.7315,1.002a7.0008,7.0008,0,1,0-10.3462,2.0356c-.457.7427-1.1021,1.8716-2.0737,3.5728Z&#39;/%3E%3Crect id=&#39;_Transparent_Rectangle_&#39; data-name=&#39;&#38;lt;Transparent Rectangle&#38;gt;&#39; class=&#39;cls-1&#39; width=&#39;32&#39; height=&#39;32&#39;/%3E%3C/svg%3E">
<bpmn:extensionElements>
<zeebe:properties>
<zeebe:property name="inbound.type" value="io.camunda:webhook:1" />
<zeebe:property name="inbound.subtype" value="ConfigurableInboundWebhook" />
<zeebe:property name="inbound.context" value="test" />
<zeebe:property name="inbound.shouldValidateHmac" value="disabled" />
</zeebe:properties>
</bpmn:extensionElements>
<bpmn:outgoing>Flow_0oawvuc</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_0oawvuc" sourceRef="start_event" targetRef="Activity_1svog89" />
</bpmn:process>
<bpmn:process id="Process_1jqzy4q" isExecutable="false">
<bpmn:task id="Activity_0bbhjnc">
<bpmn:incoming>Flow_0muo5cp</bpmn:incoming>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_0muo5cp" sourceRef="intermediate_event" targetRef="Activity_0bbhjnc" />
<bpmn:intermediateCatchEvent id="intermediate_event" zeebe:modelerTemplate="io.camunda.connectors.webhook.WebhookConnectorIntermediate.v1" zeebe:modelerTemplateVersion="2" zeebe:modelerTemplateIcon="data:image/svg+xml,%3Csvg id=&#39;icon&#39; xmlns=&#39;http://www.w3.org/2000/svg&#39; width=&#39;18&#39; height=&#39;18&#39; viewBox=&#39;0 0 32 32&#39;%3E%3Cdefs%3E%3Cstyle%3E .cls-1 %7B fill: none; %7D %3C/style%3E%3C/defs%3E%3Cpath d=&#39;M24,26a3,3,0,1,0-2.8164-4H13v1a5,5,0,1,1-5-5V16a7,7,0,1,0,6.9287,8h6.2549A2.9914,2.9914,0,0,0,24,26Z&#39;/%3E%3Cpath d=&#39;M24,16a7.024,7.024,0,0,0-2.57.4873l-3.1656-5.5395a3.0469,3.0469,0,1,0-1.7326.9985l4.1189,7.2085.8686-.4976a5.0006,5.0006,0,1,1-1.851,6.8418L17.937,26.501A7.0005,7.0005,0,1,0,24,16Z&#39;/%3E%3Cpath d=&#39;M8.532,20.0537a3.03,3.03,0,1,0,1.7326.9985C11.74,18.47,13.86,14.7607,13.89,14.708l.4976-.8682-.8677-.497a5,5,0,1,1,6.812-1.8438l1.7315,1.002a7.0008,7.0008,0,1,0-10.3462,2.0356c-.457.7427-1.1021,1.8716-2.0737,3.5728Z&#39;/%3E%3Crect id=&#39;_Transparent_Rectangle_&#39; data-name=&#39;&#38;lt;Transparent Rectangle&#38;gt;&#39; class=&#39;cls-1&#39; width=&#39;32&#39; height=&#39;32&#39;/%3E%3C/svg%3E">
<bpmn:extensionElements>
<zeebe:properties>
<zeebe:property name="inbound.type" value="io.camunda:webhook:1" />
<zeebe:property name="inbound.subtype" value="ConfigurableInboundWebhook" />
<zeebe:property name="inbound.context" value="intermediate" />
<zeebe:property name="inbound.shouldValidateHmac" value="disabled" />
<zeebe:property name="correlationKeyExpression" value="=&#34;test&#34;" />
</zeebe:properties>
</bpmn:extensionElements>
<bpmn:outgoing>Flow_0muo5cp</bpmn:outgoing>
<bpmn:messageEventDefinition id="MessageEventDefinition_1sns5do" messageRef="Message_0c7tnlx" />
</bpmn:intermediateCatchEvent>
</bpmn:process>
<bpmn:message id="Message_0c7tnlx" name="af13ccea-2581-45b1-928d-165edbc1af8f" zeebe:modelerTemplate="io.camunda.connectors.webhook.WebhookConnectorIntermediate.v1">
<bpmn:extensionElements>
<zeebe:subscription correlationKey="=&#34;test&#34;" />
</bpmn:extensionElements>
</bpmn:message>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1fkq2ek">
<bpmndi:BPMNShape id="Participant_14ueoe7_di" bpmnElement="Participant_14ueoe7" isHorizontal="true">
<dc:Bounds x="160" y="85" width="660" height="250" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0wgjxnj_di" bpmnElement="Activity_0wgjxnj">
<dc:Bounds x="570" y="160" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_19je4ca_di" bpmnElement="Event_19je4ca">
<dc:Bounds x="742" y="182" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1svog89_di" bpmnElement="Activity_1svog89">
<dc:Bounds x="420" y="160" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_104x3kv_di" bpmnElement="Event_1vvb3ug">
<dc:Bounds x="282" y="182" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1c6ej6l_di" bpmnElement="Flow_1c6ej6l">
<di:waypoint x="670" y="200" />
<di:waypoint x="742" y="200" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0oawvuc_di" bpmnElement="Flow_0oawvuc">
<di:waypoint x="318" y="200" />
<di:waypoint x="420" y="200" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Participant_0iq8omk_di" bpmnElement="Participant_0iq8omk" isHorizontal="true">
<dc:Bounds x="160" y="360" width="660" height="250" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0bbhjnc_di" bpmnElement="Activity_0bbhjnc">
<dc:Bounds x="570" y="430" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_18uvu3b_di" bpmnElement="Event_18uvu3b">
<dc:Bounds x="452" y="452" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0muo5cp_di" bpmnElement="Flow_0muo5cp">
<di:waypoint x="488" y="470" />
<di:waypoint x="570" y="470" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0v8mcd7_di" bpmnElement="Flow_0v8mcd7">
<di:waypoint x="620" y="430" />
<di:waypoint x="620" y="240" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0v0wf6z_di" bpmnElement="Flow_0v0wf6z">
<di:waypoint x="470" y="240" />
<di:waypoint x="470" y="452" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1no15pe" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.11.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.2.0">
<bpmn:collaboration id="Collaboration_1fkq2ek">
<bpmn:participant id="Participant_14ueoe7" processRef="Process_11sdck4" />
<bpmn:participant id="Participant_0iq8omk" processRef="Process_1jqzy4q" />
<bpmn:messageFlow id="Flow_0v8mcd7" sourceRef="Activity_0bbhjnc" targetRef="Activity_0wgjxnj" />
<bpmn:messageFlow id="Flow_1w42yir" sourceRef="Activity_1svog89" targetRef="Activity_1up34yp" />
</bpmn:collaboration>
<bpmn:process id="Process_11sdck4" isExecutable="true">
<bpmn:task id="Activity_0wgjxnj" name="yo">
<bpmn:outgoing>Flow_1c6ej6l</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_1c6ej6l" sourceRef="Activity_0wgjxnj" targetRef="Event_19je4ca" />
<bpmn:endEvent id="Event_19je4ca">
<bpmn:incoming>Flow_1c6ej6l</bpmn:incoming>
</bpmn:endEvent>
<bpmn:task id="Activity_1svog89">
<bpmn:incoming>Flow_0oawvuc</bpmn:incoming>
</bpmn:task>
<bpmn:startEvent id="start_event" zeebe:modelerTemplate="io.camunda.connectors.webhook.WebhookConnector.v1" zeebe:modelerTemplateVersion="3" zeebe:modelerTemplateIcon="data:image/svg+xml,%3Csvg id=&#39;icon&#39; xmlns=&#39;http://www.w3.org/2000/svg&#39; width=&#39;18&#39; height=&#39;18&#39; viewBox=&#39;0 0 32 32&#39;%3E%3Cdefs%3E%3Cstyle%3E .cls-1 %7B fill: none; %7D %3C/style%3E%3C/defs%3E%3Cpath d=&#39;M24,26a3,3,0,1,0-2.8164-4H13v1a5,5,0,1,1-5-5V16a7,7,0,1,0,6.9287,8h6.2549A2.9914,2.9914,0,0,0,24,26Z&#39;/%3E%3Cpath d=&#39;M24,16a7.024,7.024,0,0,0-2.57.4873l-3.1656-5.5395a3.0469,3.0469,0,1,0-1.7326.9985l4.1189,7.2085.8686-.4976a5.0006,5.0006,0,1,1-1.851,6.8418L17.937,26.501A7.0005,7.0005,0,1,0,24,16Z&#39;/%3E%3Cpath d=&#39;M8.532,20.0537a3.03,3.03,0,1,0,1.7326.9985C11.74,18.47,13.86,14.7607,13.89,14.708l.4976-.8682-.8677-.497a5,5,0,1,1,6.812-1.8438l1.7315,1.002a7.0008,7.0008,0,1,0-10.3462,2.0356c-.457.7427-1.1021,1.8716-2.0737,3.5728Z&#39;/%3E%3Crect id=&#39;_Transparent_Rectangle_&#39; data-name=&#39;&#38;lt;Transparent Rectangle&#38;gt;&#39; class=&#39;cls-1&#39; width=&#39;32&#39; height=&#39;32&#39;/%3E%3C/svg%3E">
<bpmn:extensionElements>
<zeebe:properties>
<zeebe:property name="inbound.type" value="io.camunda:webhook:1" />
<zeebe:property name="inbound.subtype" value="ConfigurableInboundWebhook" />
<zeebe:property name="inbound.context" value="test" />
<zeebe:property name="inbound.shouldValidateHmac" value="disabled" />
</zeebe:properties>
</bpmn:extensionElements>
<bpmn:outgoing>Flow_0oawvuc</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_0oawvuc" sourceRef="start_event" targetRef="Activity_1svog89" />
</bpmn:process>
<bpmn:process id="Process_1jqzy4q" isExecutable="false">
<bpmn:task id="Activity_0bbhjnc">
<bpmn:incoming>Flow_15vkx4q</bpmn:incoming>
</bpmn:task>
<bpmn:task id="Activity_1up34yp">
<bpmn:outgoing>Flow_15vkx4q</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_15vkx4q" sourceRef="Activity_1up34yp" targetRef="Activity_0bbhjnc" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1fkq2ek">
<bpmndi:BPMNShape id="Participant_14ueoe7_di" bpmnElement="Participant_14ueoe7" isHorizontal="true">
<dc:Bounds x="160" y="85" width="660" height="250" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0wgjxnj_di" bpmnElement="Activity_0wgjxnj">
<dc:Bounds x="570" y="160" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_19je4ca_di" bpmnElement="Event_19je4ca">
<dc:Bounds x="742" y="182" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1svog89_di" bpmnElement="Activity_1svog89">
<dc:Bounds x="420" y="160" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_104x3kv_di" bpmnElement="Event_1vvb3ug">
<dc:Bounds x="282" y="182" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1c6ej6l_di" bpmnElement="Flow_1c6ej6l">
<di:waypoint x="670" y="200" />
<di:waypoint x="742" y="200" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0oawvuc_di" bpmnElement="Flow_0oawvuc">
<di:waypoint x="318" y="200" />
<di:waypoint x="420" y="200" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Participant_0iq8omk_di" bpmnElement="Participant_0iq8omk" isHorizontal="true">
<dc:Bounds x="160" y="360" width="660" height="250" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0bbhjnc_di" bpmnElement="Activity_0bbhjnc">
<dc:Bounds x="570" y="430" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1up34yp_di" bpmnElement="Activity_1up34yp">
<dc:Bounds x="420" y="430" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_15vkx4q_di" bpmnElement="Flow_15vkx4q">
<di:waypoint x="520" y="470" />
<di:waypoint x="570" y="470" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0v8mcd7_di" bpmnElement="Flow_0v8mcd7">
<di:waypoint x="620" y="430" />
<di:waypoint x="620" y="240" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1w42yir_di" bpmnElement="Flow_1w42yir">
<di:waypoint x="470" y="240" />
<di:waypoint x="470" y="430" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

0 comments on commit 1a243db

Please sign in to comment.