Skip to content

Commit

Permalink
fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chillleader committed Nov 12, 2024
1 parent 00536b3 commit 7d63de5
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
import io.camunda.connector.runtime.inbound.importer.ProcessDefinitionSearch;
import io.camunda.operate.CamundaOperateClient;
import io.camunda.zeebe.client.ZeebeClient;
import java.io.File;
import java.util.Collections;
Expand All @@ -46,8 +45,6 @@ public abstract class BaseAutomationAnywhereTest {

@MockBean ProcessDefinitionSearch processDefinitionSearch;

@Autowired CamundaOperateClient camundaOperateClient;

@LocalServerPort int serverPort;

protected static final String ELEMENT_TEMPLATE_PATH =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import io.camunda.connector.e2e.app.TestConnectorRuntimeApplication;
import io.camunda.connector.runtime.inbound.importer.ProcessDefinitionSearch;
import io.camunda.operate.CamundaOperateClient;
import io.camunda.process.test.api.CamundaSpringProcessTest;
import io.camunda.zeebe.client.ZeebeClient;
import java.io.File;
Expand Down Expand Up @@ -57,7 +56,6 @@ public abstract class BaseAwsTest {
@TempDir File tempDir;
@Autowired ZeebeClient zeebeClient;
@MockBean ProcessDefinitionSearch processDefinitionSearch;
@Autowired CamundaOperateClient camundaOperateClient;

static LocalStackContainer localstack;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package io.camunda.connector.e2e.app;

import io.camunda.operate.CamundaOperateClient;
import io.camunda.connector.runtime.inbound.operate.OperateClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand All @@ -28,7 +28,7 @@
io.camunda.connector.runtime.OutboundConnectorsAutoConfiguration.class,
io.camunda.connector.runtime.WebhookConnectorAutoConfiguration.class
})
@MockBean(CamundaOperateClient.class)
@MockBean(OperateClient.class)
public class TestConnectorRuntimeApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
import io.camunda.connector.runtime.inbound.importer.ProcessDefinitionSearch;
import io.camunda.operate.CamundaOperateClient;
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.model.bpmn.Bpmn;
import io.camunda.zeebe.model.bpmn.BpmnModelInstance;
Expand Down Expand Up @@ -71,8 +70,6 @@ public abstract class BaseEasyPostTest {

@MockBean ProcessDefinitionSearch processDefinitionSearch;

@Autowired CamundaOperateClient camundaOperateClient;

@LocalServerPort int serverPort;

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@
import io.camunda.connector.http.base.model.auth.BearerAuthentication;
import io.camunda.connector.http.base.model.auth.OAuthAuthentication;
import io.camunda.connector.runtime.inbound.importer.ProcessDefinitionSearch;
import io.camunda.connector.runtime.inbound.operate.OperateClient;
import io.camunda.connector.runtime.inbound.state.ProcessImportResult;
import io.camunda.connector.runtime.inbound.state.ProcessImportResult.ProcessDefinitionIdentifier;
import io.camunda.connector.runtime.inbound.state.ProcessImportResult.ProcessDefinitionVersion;
import io.camunda.connector.runtime.inbound.state.ProcessStateStore;
import io.camunda.operate.CamundaOperateClient;
import io.camunda.operate.model.ProcessDefinition;
import io.camunda.process.test.api.CamundaProcessTestContext;
import io.camunda.process.test.api.CamundaSpringProcessTest;
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.api.search.response.ProcessDefinition;
import io.camunda.zeebe.model.bpmn.Bpmn;
import io.camunda.zeebe.model.bpmn.instance.Process;
import java.io.File;
Expand Down Expand Up @@ -88,9 +87,7 @@ public class HttpTests {

@Autowired ProcessStateStore stateStore;

@MockBean CamundaOperateClient camundaOperateClient;

@Autowired CamundaProcessTestContext context;
@MockBean OperateClient operateClient;

@LocalServerPort int serverPort;

Expand Down Expand Up @@ -341,21 +338,21 @@ void successfulWebhookModelRun() throws Exception {
var model = replace("webhook_connector.bpmn", replace("http://webhook", mockUrl));

// Prepare a mocked process connectorData backed by our test model
when(camundaOperateClient.getProcessDefinitionModel(1L)).thenReturn(model);
when(operateClient.getProcessModel(1L)).thenReturn(model);
var processDef = mock(ProcessDefinition.class);
when(processDef.getKey()).thenReturn(1L);
when(processDef.getProcessDefinitionKey()).thenReturn(1L);
when(processDef.getTenantId()).thenReturn(zeebeClient.getConfiguration().getDefaultTenantId());
when(processDef.getBpmnProcessId())
when(processDef.getProcessDefinitionId())
.thenReturn(model.getModelElementsByType(Process.class).stream().findFirst().get().getId());

// Deploy the webhook
stateStore.update(
new ProcessImportResult(
Map.of(
new ProcessDefinitionIdentifier(
processDef.getBpmnProcessId(), processDef.getTenantId()),
processDef.getProcessDefinitionId(), processDef.getTenantId()),
new ProcessDefinitionVersion(
processDef.getKey(), processDef.getVersion().intValue()))));
processDef.getProcessDefinitionKey(), processDef.getVersion()))));

var bpmnTest =
ZeebeTest.with(zeebeClient).deploy(model).createInstance().waitForProcessCompletion();
Expand All @@ -370,21 +367,21 @@ void successfulWebhookModelWithQueryParamsRun() throws Exception {
var model = replace("webhook_connector.bpmn", replace("http://webhook", mockUrl));

// Prepare a mocked process connectorData backed by our test model
when(camundaOperateClient.getProcessDefinitionModel(1L)).thenReturn(model);
when(operateClient.getProcessModel(1L)).thenReturn(model);
var processDef = mock(ProcessDefinition.class);
when(processDef.getKey()).thenReturn(1L);
when(processDef.getProcessDefinitionKey()).thenReturn(1L);
when(processDef.getTenantId()).thenReturn(zeebeClient.getConfiguration().getDefaultTenantId());
when(processDef.getBpmnProcessId())
when(processDef.getProcessDefinitionId())
.thenReturn(model.getModelElementsByType(Process.class).stream().findFirst().get().getId());

// Deploy the webhook
stateStore.update(
new ProcessImportResult(
Map.of(
new ProcessDefinitionIdentifier(
processDef.getBpmnProcessId(), processDef.getTenantId()),
processDef.getProcessDefinitionId(), processDef.getTenantId()),
new ProcessDefinitionVersion(
processDef.getKey(), processDef.getVersion().intValue()))));
processDef.getProcessDefinitionKey(), processDef.getVersion()))));

var bpmnTest =
ZeebeTest.with(zeebeClient).deploy(model).createInstance().waitForProcessCompletion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import static org.mockito.Mockito.when;

import io.camunda.connector.runtime.inbound.importer.ProcessDefinitionSearch;
import io.camunda.connector.runtime.inbound.operate.OperateClient;
import io.camunda.connector.runtime.inbound.state.ProcessStateStore;
import io.camunda.operate.CamundaOperateClient;
import io.camunda.zeebe.client.ZeebeClient;
import java.io.File;
import java.util.Arrays;
Expand Down Expand Up @@ -63,7 +63,7 @@ public class BaseKafkaTest {

@Autowired ProcessStateStore processStateStore;

@Autowired CamundaOperateClient camundaOperateClient;
@Autowired OperateClient camundaOperateClient;

static KafkaContainer kafkaContainer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
import io.camunda.connector.runtime.inbound.state.ProcessImportResult;
import io.camunda.connector.runtime.inbound.state.ProcessImportResult.ProcessDefinitionIdentifier;
import io.camunda.connector.runtime.inbound.state.ProcessImportResult.ProcessDefinitionVersion;
import io.camunda.operate.exception.OperateException;
import io.camunda.operate.model.ProcessDefinition;
import io.camunda.process.test.api.CamundaAssert;
import io.camunda.process.test.api.CamundaSpringProcessTest;
import io.camunda.zeebe.client.api.search.response.ProcessDefinition;
import io.camunda.zeebe.model.bpmn.BpmnModelInstance;
import io.camunda.zeebe.model.bpmn.instance.Process;
import java.util.Map;
Expand Down Expand Up @@ -68,7 +67,7 @@ public void afterEach() {
}

@Test
void testKafkaIntermediateConnectorProcessWithJsonKey() throws OperateException {
void testKafkaIntermediateConnectorProcessWithJsonKey() {
Map<String, Object> expectedJsonResponse =
Map.of(
"key", MESSAGE_KEY_JSON_AS_OBJECT,
Expand All @@ -87,9 +86,9 @@ void testKafkaIntermediateConnectorProcessWithJsonKey() throws OperateException
new ProcessImportResult(
Map.of(
new ProcessDefinitionIdentifier(
processDef.getBpmnProcessId(), processDef.getTenantId()),
processDef.getProcessDefinitionId(), processDef.getTenantId()),
new ProcessDefinitionVersion(
processDef.getKey(), processDef.getVersion().intValue()))));
processDef.getProcessDefinitionKey(), processDef.getVersion()))));

AtomicBoolean kafkaProducerThreadRun =
producer.startContinuousMessageSending(
Expand All @@ -107,7 +106,7 @@ void testKafkaIntermediateConnectorProcessWithJsonKey() throws OperateException
}

@Test
void testKafkaIntermediateConnectorProcessWithStringKey() throws OperateException {
void testKafkaIntermediateConnectorProcessWithStringKey() {
Map<String, Object> expectedJsonResponse =
Map.of(
"key",
Expand All @@ -130,9 +129,9 @@ void testKafkaIntermediateConnectorProcessWithStringKey() throws OperateExceptio
new ProcessImportResult(
Map.of(
new ProcessDefinitionIdentifier(
processDef.getBpmnProcessId(), processDef.getTenantId()),
processDef.getProcessDefinitionId(), processDef.getTenantId()),
new ProcessDefinitionVersion(
processDef.getKey(), processDef.getVersion().intValue()))));
processDef.getProcessDefinitionKey(), processDef.getVersion()))));

AtomicBoolean kafkaProducerThreadRun =
producer.startContinuousMessageSending(
Expand All @@ -147,11 +146,11 @@ void testKafkaIntermediateConnectorProcessWithStringKey() throws OperateExceptio
.hasVariable("allResult", expectedJsonResponse);
}

private void mockProcessDefinition(BpmnModelInstance model) throws OperateException {
when(camundaOperateClient.getProcessDefinitionModel(1L)).thenReturn(model);
when(processDef.getKey()).thenReturn(1L);
private void mockProcessDefinition(BpmnModelInstance model) {
when(camundaOperateClient.getProcessModel(1)).thenReturn(model);
when(processDef.getProcessDefinitionKey()).thenReturn(1L);
when(processDef.getTenantId()).thenReturn(zeebeClient.getConfiguration().getDefaultTenantId());
when(processDef.getBpmnProcessId())
when(processDef.getProcessDefinitionId())
.thenReturn(model.getModelElementsByType(Process.class).stream().findFirst().get().getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
import static org.mockito.Mockito.when;

import io.camunda.connector.e2e.app.TestConnectorRuntimeApplication;
import io.camunda.connector.runtime.inbound.operate.OperateClient;
import io.camunda.connector.runtime.inbound.state.ProcessImportResult;
import io.camunda.connector.runtime.inbound.state.ProcessStateStore;
import io.camunda.operate.CamundaOperateClient;
import io.camunda.operate.exception.OperateException;
import io.camunda.operate.model.ProcessDefinition;
import io.camunda.process.test.api.CamundaSpringProcessTest;
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.api.search.response.ProcessDefinition;
import io.camunda.zeebe.model.bpmn.BpmnModelInstance;
import io.camunda.zeebe.model.bpmn.instance.Process;
import jakarta.mail.Flags;
Expand All @@ -38,7 +37,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicInteger;
import org.awaitility.core.ConditionTimeoutException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -61,9 +60,9 @@ public class InboundEmailTest extends BaseEmailTest {

private static final ScheduledExecutorService scheduler =
Executors.newSingleThreadScheduledExecutor();
private static AtomicLong counter = new AtomicLong(1);
private static final AtomicInteger counter = new AtomicInteger(1);
@Autowired ProcessStateStore processStateStore;
@Autowired CamundaOperateClient camundaOperateClient;
@Autowired OperateClient camundaOperateClient;
@Mock private ProcessDefinition processDef;
@Autowired private ZeebeClient zeebeClient;

Expand All @@ -73,7 +72,7 @@ public void beforeEach() {
}

@Test
public void shouldReceiveEmailAndSetAsSeen() throws OperateException, MessagingException {
public void shouldReceiveEmailAndSetAsSeen() throws MessagingException {
var model =
replace(
"email-inbound-connector-intermediate_unseen_read.bpmn",
Expand All @@ -92,9 +91,9 @@ public void shouldReceiveEmailAndSetAsSeen() throws OperateException, MessagingE
new ProcessImportResult(
Map.of(
new ProcessImportResult.ProcessDefinitionIdentifier(
processDef.getBpmnProcessId(), processDef.getTenantId()),
processDef.getProcessDefinitionId(), processDef.getTenantId()),
new ProcessImportResult.ProcessDefinitionVersion(
processDef.getKey(), processDef.getVersion().intValue()))));
processDef.getProcessDefinitionKey(), processDef.getVersion()))));

bpmnTest = bpmnTest.waitForProcessCompletion();

Expand All @@ -109,7 +108,7 @@ public void shouldReceiveEmailAndSetAsSeen() throws OperateException, MessagingE
}

@Test
public void shouldThrowWhenAllMessageAreSeen() throws OperateException, MessagingException {
public void shouldThrowWhenAllMessageAreSeen() throws MessagingException {
var model =
replace(
"email-inbound-connector-intermediate_unseen_read.bpmn",
Expand Down Expand Up @@ -137,15 +136,15 @@ public void shouldThrowWhenAllMessageAreSeen() throws OperateException, Messagin
new ProcessImportResult(
Map.of(
new ProcessImportResult.ProcessDefinitionIdentifier(
processDef.getBpmnProcessId(), processDef.getTenantId()),
processDef.getProcessDefinitionId(), processDef.getTenantId()),
new ProcessImportResult.ProcessDefinitionVersion(
processDef.getKey(), processDef.getVersion().intValue()))));
processDef.getProcessDefinitionKey(), processDef.getVersion()))));

Assertions.assertThrows(ConditionTimeoutException.class, bpmnTest::waitForProcessCompletion);
}

@Test
public void shouldReceiveEmailAndDelete() throws OperateException, MessagingException {
public void shouldReceiveEmailAndDelete() throws MessagingException {
var model =
replace(
"email-inbound-connector-intermediate_unseen_delete.bpmn",
Expand All @@ -164,9 +163,9 @@ public void shouldReceiveEmailAndDelete() throws OperateException, MessagingExce
new ProcessImportResult(
Map.of(
new ProcessImportResult.ProcessDefinitionIdentifier(
processDef.getBpmnProcessId(), processDef.getTenantId()),
processDef.getProcessDefinitionId(), processDef.getTenantId()),
new ProcessImportResult.ProcessDefinitionVersion(
processDef.getKey(), processDef.getVersion().intValue()))));
processDef.getProcessDefinitionKey(), processDef.getVersion()))));

bpmnTest = bpmnTest.waitForProcessCompletion();

Expand All @@ -181,7 +180,7 @@ public void shouldReceiveEmailAndDelete() throws OperateException, MessagingExce
}

@Test
public void shouldReceiveEmailAndMove() throws OperateException, MessagingException {
public void shouldReceiveEmailAndMove() throws MessagingException {
var model =
replace(
"email-inbound-connector-intermediate_unseen_move.bpmn",
Expand All @@ -200,9 +199,9 @@ public void shouldReceiveEmailAndMove() throws OperateException, MessagingExcept
new ProcessImportResult(
Map.of(
new ProcessImportResult.ProcessDefinitionIdentifier(
processDef.getBpmnProcessId(), processDef.getTenantId()),
processDef.getProcessDefinitionId(), processDef.getTenantId()),
new ProcessImportResult.ProcessDefinitionVersion(
processDef.getKey(), processDef.getVersion().intValue()))));
processDef.getProcessDefinitionKey(), processDef.getVersion()))));

bpmnTest = bpmnTest.waitForProcessCompletion();

Expand All @@ -217,17 +216,17 @@ public void shouldReceiveEmailAndMove() throws OperateException, MessagingExcept
assertThat(bpmnTest.getProcessInstanceEvent()).hasVariable("plainTextBody", "hey");
}

private void mockProcessDefinition(BpmnModelInstance model) throws OperateException {
when(camundaOperateClient.getProcessDefinitionModel(1L)).thenReturn(model);
when(processDef.getKey()).thenReturn(1L);
private void mockProcessDefinition(BpmnModelInstance model) {
when(camundaOperateClient.getProcessModel(1L)).thenReturn(model);
when(processDef.getProcessDefinitionKey()).thenReturn(1L);
when(processDef.getTenantId()).thenReturn(zeebeClient.getConfiguration().getDefaultTenantId());
when(processDef.getBpmnProcessId())
when(processDef.getProcessDefinitionId())
.thenReturn(model.getModelElementsByType(Process.class).stream().findFirst().get().getId());
when(processDef.getVersion()).thenReturn(counter.getAndIncrement());
}

@Test
public void shouldPollEmailAndMove() throws OperateException, MessagingException {
public void shouldPollEmailAndMove() throws MessagingException {
var model =
replace(
"email-inbound-connector-intermediate_all_delete.bpmn",
Expand Down Expand Up @@ -258,9 +257,9 @@ public void shouldPollEmailAndMove() throws OperateException, MessagingException
new ProcessImportResult(
Map.of(
new ProcessImportResult.ProcessDefinitionIdentifier(
processDef.getBpmnProcessId(), processDef.getTenantId()),
processDef.getProcessDefinitionId(), processDef.getTenantId()),
new ProcessImportResult.ProcessDefinitionVersion(
processDef.getKey(), processDef.getVersion().intValue()))));
processDef.getProcessDefinitionKey(), processDef.getVersion()))));

bpmnTest = bpmnTest.waitForProcessCompletion();

Expand Down
Loading

0 comments on commit 7d63de5

Please sign in to comment.