From 1a243db8a0183ff37a9e92a0004545f70b8e69dc Mon Sep 17 00:00:00 2001 From: sbuettner Date: Mon, 12 Jun 2023 15:06:07 +0200 Subject: [PATCH] chore(test): Add test to verify collaboration is working with inbound webhook. --- .../connector-runtime-spring/pom.xml | 43 ++++++- .../ProcessDefinitionInspectorUtilTests.java | 63 +++++++++++ .../bpmn/multi-webhook-collaboration.bpmn | 106 ++++++++++++++++++ .../bpmn/single-webhook-collaboration.bpmn | 91 +++++++++++++++ 4 files changed, 298 insertions(+), 5 deletions(-) create mode 100644 connector-runtime/connector-runtime-spring/src/test/java/io/camunda/connector/runtime/inbound/importer/ProcessDefinitionInspectorUtilTests.java create mode 100644 connector-runtime/connector-runtime-spring/src/test/resources/bpmn/multi-webhook-collaboration.bpmn create mode 100644 connector-runtime/connector-runtime-spring/src/test/resources/bpmn/single-webhook-collaboration.bpmn diff --git a/connector-runtime/connector-runtime-spring/pom.xml b/connector-runtime/connector-runtime-spring/pom.xml index ad825cc47b..618ca1c6f4 100644 --- a/connector-runtime/connector-runtime-spring/pom.xml +++ b/connector-runtime/connector-runtime-spring/pom.xml @@ -41,9 +41,42 @@ camunda-operate-client-java - - io.camunda.connector - connector-runtime-core - - + + io.camunda.connector + connector-runtime-core + + + + + org.springframework + spring-test + test + + + org.junit.jupiter + junit-jupiter + test + + + org.mockito + mockito-junit-jupiter + test + + + org.assertj + assertj-core + test + + + org.testcontainers + junit-jupiter + test + + + org.junit.jupiter + junit-jupiter + test + + + \ No newline at end of file diff --git a/connector-runtime/connector-runtime-spring/src/test/java/io/camunda/connector/runtime/inbound/importer/ProcessDefinitionInspectorUtilTests.java b/connector-runtime/connector-runtime-spring/src/test/java/io/camunda/connector/runtime/inbound/importer/ProcessDefinitionInspectorUtilTests.java new file mode 100644 index 0000000000..d4fbc29875 --- /dev/null +++ b/connector-runtime/connector-runtime-spring/src/test/java/io/camunda/connector/runtime/inbound/importer/ProcessDefinitionInspectorUtilTests.java @@ -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 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); + } + } +} diff --git a/connector-runtime/connector-runtime-spring/src/test/resources/bpmn/multi-webhook-collaboration.bpmn b/connector-runtime/connector-runtime-spring/src/test/resources/bpmn/multi-webhook-collaboration.bpmn new file mode 100644 index 0000000000..3cad8c626b --- /dev/null +++ b/connector-runtime/connector-runtime-spring/src/test/resources/bpmn/multi-webhook-collaboration.bpmn @@ -0,0 +1,106 @@ + + + + + + + + + + + Flow_1c6ej6l + + + + Flow_1c6ej6l + + + Flow_0oawvuc + + + + + + + + + + + Flow_0oawvuc + + + + + + Flow_0muo5cp + + + + + + + + + + + + + Flow_0muo5cp + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/connector-runtime/connector-runtime-spring/src/test/resources/bpmn/single-webhook-collaboration.bpmn b/connector-runtime/connector-runtime-spring/src/test/resources/bpmn/single-webhook-collaboration.bpmn new file mode 100644 index 0000000000..2c0f2bd5b8 --- /dev/null +++ b/connector-runtime/connector-runtime-spring/src/test/resources/bpmn/single-webhook-collaboration.bpmn @@ -0,0 +1,91 @@ + + + + + + + + + + + Flow_1c6ej6l + + + + Flow_1c6ej6l + + + Flow_0oawvuc + + + + + + + + + + + Flow_0oawvuc + + + + + + Flow_15vkx4q + + + Flow_15vkx4q + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +