diff --git a/taskana-adapter-camunda-spring-boot-test/pom.xml b/taskana-adapter-camunda-spring-boot-test/pom.xml index 84a0dceb..76bd3d29 100644 --- a/taskana-adapter-camunda-spring-boot-test/pom.xml +++ b/taskana-adapter-camunda-spring-boot-test/pom.xml @@ -167,6 +167,12 @@ ${version.jakarta.annotation} test + + com.squareup.okhttp3 + okhttp + test + + diff --git a/taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/AbsIntegrationTest.java b/taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/AbsIntegrationTest.java index 6dee297f..c977b1dc 100644 --- a/taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/AbsIntegrationTest.java +++ b/taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/AbsIntegrationTest.java @@ -9,7 +9,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.client.OkHttp3ClientHttpRequestFactory; import pro.taskana.TaskanaConfiguration; +import pro.taskana.adapter.systemconnector.camunda.api.impl.HttpHeaderProvider; import pro.taskana.classification.api.ClassificationService; import pro.taskana.classification.api.exceptions.ClassificationNotFoundException; import pro.taskana.classification.api.models.Classification; @@ -35,6 +39,8 @@ public abstract class AbsIntegrationTest { private static boolean isInitialised = false; + @LocalServerPort private Integer port; + @Value("${taskana.adapter.scheduler.run.interval.for.start.taskana.tasks.in.milliseconds}") protected long adapterTaskPollingInterval; @@ -42,8 +48,7 @@ public abstract class AbsIntegrationTest { protected long adapterCompletionPollingInterval; @Value( - "${taskana.adapter.scheduler.run.interval.for.check.finished.referenced." - + "tasks.in.milliseconds}") + "${taskana.adapter.scheduler.run.interval.for.check.finished.referenced.tasks.in.milliseconds}") protected long adapterCancelledClaimPollingInterval; @Value("${taskana.adapter.scheduler.run.interval.for.claim.referenced.tasks.in.milliseconds}") @@ -69,9 +74,12 @@ public abstract class AbsIntegrationTest { @Resource(name = "camundaBpmDataSource") protected DataSource camundaBpmDataSource; - @Autowired private TestRestTemplate restTemplate; + private TestRestTemplate restTemplate; + @Autowired private ProcessEngineConfiguration processEngineConfiguration; + @Autowired private HttpHeaderProvider httpHeaderProvider; + @Resource(name = "taskanaDataSource") private DataSource taskanaDataSource; @@ -101,11 +109,19 @@ public void setUp() throws Exception { isInitialised = true; } + this.restTemplate = + new TestRestTemplate( + new RestTemplateBuilder() + .rootUri("http://localhost:" + port) + .requestFactory(OkHttp3ClientHttpRequestFactory.class)); // set up camunda requester and taskanaEngine-Taskservice this.camundaProcessengineRequester = new CamundaProcessengineRequester( - this.processEngineConfiguration.getProcessEngineName(), this.restTemplate); - this.taskanaOutboxRequester = new TaskanaOutboxRequester(this.restTemplate); + this.processEngineConfiguration.getProcessEngineName(), + this.restTemplate, + this.httpHeaderProvider); + this.taskanaOutboxRequester = + new TaskanaOutboxRequester(this.restTemplate, this.httpHeaderProvider); this.taskService = taskanaEngine.getTaskService(); // adjust polling interval, give adapter a little more time diff --git a/taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/CamundaProcessengineRequester.java b/taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/CamundaProcessengineRequester.java index e31e91c6..fc5472c4 100644 --- a/taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/CamundaProcessengineRequester.java +++ b/taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/CamundaProcessengineRequester.java @@ -7,11 +7,10 @@ import org.json.JSONObject; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import pro.taskana.adapter.systemconnector.camunda.api.impl.HttpHeaderProvider; /** Class to assist with building requests against the Camunda REST API. */ public class CamundaProcessengineRequester { @@ -28,25 +27,33 @@ public class CamundaProcessengineRequester { private final String processEngineKey; + private final HttpHeaderProvider httpHeaderProvider; + /** * Constructor for setting up a requester for a process engine with a key other than "default". * * @param processEngineKey the key of the camunda process engine to be called. * @param restTemplate the {@link TestRestTemplate} to be used for the REST calls. + * @param httpHeaderProvider httpHeaderProvider to set correct headers on HTTP Request */ - public CamundaProcessengineRequester(String processEngineKey, TestRestTemplate restTemplate) { + public CamundaProcessengineRequester( + String processEngineKey, + TestRestTemplate restTemplate, + HttpHeaderProvider httpHeaderProvider) { this.processEngineKey = processEngineKey; this.restTemplate = restTemplate; + this.httpHeaderProvider = httpHeaderProvider; } /** * Default constructor to use the default process engine with its key "default". * * @param restTemplate the {@link TestRestTemplate} to be used for the REST calls. + * @param httpHeaderProvider httpHeaderProvider to set correct headers on HTTP Request */ - public CamundaProcessengineRequester(TestRestTemplate restTemplate) { - this.processEngineKey = "default"; - this.restTemplate = restTemplate; + public CamundaProcessengineRequester( + TestRestTemplate restTemplate, HttpHeaderProvider httpHeaderProvider) { + this("default", restTemplate, httpHeaderProvider); } /** @@ -66,7 +73,8 @@ public String startCamundaProcessAndReturnId(String processKey, String variables + PROCESS_DEFINITION_KEY_PATH + processKey + PROCESS_DEFINITION_START_PATH; - HttpEntity requestEntity = prepareEntityFromBody("{" + variables + "}"); + HttpEntity requestEntity = + httpHeaderProvider.prepareNewEntityForCamundaRestApi("{" + variables + "}"); ResponseEntity answer = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); @@ -89,7 +97,7 @@ public List getTaskIdsFromProcessInstanceId(String processInstanceId) List returnList = new ArrayList(); String url = BASIC_ENGINE_PATH + this.processEngineKey + TASK_PATH; - HttpEntity requestEntity = prepareEntityFromBody("{}"); + HttpEntity requestEntity = httpHeaderProvider.prepareNewEntityForCamundaRestApi(); ResponseEntity answer = this.restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class); @@ -120,7 +128,8 @@ public boolean completeTaskWithId(String camundaTaskId) throws JSONException { + "/" + camundaTaskId + COMPLETE_TASK_PATH; - HttpEntity requestEntity = this.prepareEntityFromBody("{}"); + HttpEntity requestEntity = + httpHeaderProvider.prepareNewEntityForCamundaRestApi("{}"); ResponseEntity answer = this.restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); if (answer.getStatusCode().equals(HttpStatus.NO_CONTENT)) { @@ -145,7 +154,7 @@ public boolean completeTaskWithId(String camundaTaskId) throws JSONException { */ public boolean getTaskFromTaskId(String camundaTaskId) throws JSONException { String url = BASIC_ENGINE_PATH + this.processEngineKey + TASK_PATH + "/" + camundaTaskId; - HttpEntity requestEntity = prepareEntityFromBody("{}"); + HttpEntity requestEntity = httpHeaderProvider.prepareNewEntityForCamundaRestApi(); ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class); JSONObject taskRetrievalAnswerJson = new JSONObject(response.getBody()); @@ -170,7 +179,7 @@ public boolean getTaskFromHistoryFromTaskId(String camundaTaskId) throws JSONExc + TASK_PATH + "/?taskId=" + camundaTaskId; - HttpEntity requestEntity = prepareEntityFromBody("{}"); + HttpEntity requestEntity = httpHeaderProvider.prepareNewEntityForCamundaRestApi(); ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class); // no task found will only show in empty body @@ -196,7 +205,7 @@ public boolean isCorrectAssigneeFromHistory(String camundaTaskId, String assigne + TASK_PATH + "/?taskId=" + camundaTaskId; - HttpEntity requestEntity = prepareEntityFromBody("{}"); + HttpEntity requestEntity = httpHeaderProvider.prepareNewEntityForCamundaRestApi(); ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class); // no task found will only show in empty body @@ -228,7 +237,8 @@ public boolean deleteProcessInstanceWithId(String processInstanceId, boolean ski if (skipCustomListeners) { url += "?skipCustomListeners=true"; } - HttpEntity requestEntity = prepareEntityFromBody("{}"); + HttpEntity requestEntity = + httpHeaderProvider.prepareNewEntityForCamundaRestApi("{}"); ResponseEntity answer = this.restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, String.class); if (HttpStatus.NO_CONTENT.equals(answer.getStatusCode())) { @@ -254,7 +264,7 @@ public boolean deleteProcessInstanceWithId(String processInstanceId, boolean ski public boolean isCorrectAssignee(String camundaTaskId, String assigneeValueToVerify) { String requestUrl = BASIC_ENGINE_PATH + this.processEngineKey + TASK_PATH + "/" + camundaTaskId; - HttpEntity requestEntity = prepareEntityFromBody("{}"); + HttpEntity requestEntity = httpHeaderProvider.prepareNewEntityForCamundaRestApi(); ResponseEntity responseEntity = restTemplate.exchange(requestUrl, HttpMethod.GET, requestEntity, String.class); JSONObject taskRetrievalAnswerJson = new JSONObject(responseEntity.getBody()); @@ -273,16 +283,4 @@ public boolean isCorrectAssignee(String camundaTaskId, String assigneeValueToVer return false; } - - /** - * Helper method to create an HttpEntity from a provided body in JSON-format. - * - * @param jsonBody the body of the HttpEntity - * @return the created HttpEntity - */ - private HttpEntity prepareEntityFromBody(String jsonBody) { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - return new HttpEntity(jsonBody, headers); - } } diff --git a/taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/CamundaTaskEventErrorHandlerTest.java b/taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/CamundaTaskEventErrorHandlerTest.java index 6054977f..03f18333 100644 --- a/taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/CamundaTaskEventErrorHandlerTest.java +++ b/taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/CamundaTaskEventErrorHandlerTest.java @@ -7,22 +7,14 @@ import org.json.JSONObject; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.DirtiesContext.ClassMode; +import org.springframework.test.context.ContextConfiguration; import pro.taskana.adapter.camunda.outbox.rest.model.CamundaTaskEvent; -import pro.taskana.adapter.impl.ReferencedTaskClaimCanceler; -import pro.taskana.adapter.impl.ReferencedTaskClaimer; -import pro.taskana.adapter.impl.ReferencedTaskCompleter; -import pro.taskana.adapter.impl.TaskanaTaskStarter; -import pro.taskana.adapter.impl.TaskanaTaskTerminator; import pro.taskana.adapter.manager.AdapterManager; import pro.taskana.adapter.test.TaskanaAdapterTestApplication; import pro.taskana.common.test.security.JaasExtension; @@ -35,14 +27,7 @@ webEnvironment = WebEnvironment.DEFINED_PORT) @AutoConfigureWebTestClient @ExtendWith(JaasExtension.class) -// Disable Schedulers so tasks stay in OutboxDB -@MockBean(ReferencedTaskCompleter.class) -@MockBean(ReferencedTaskClaimer.class) -@MockBean(ReferencedTaskClaimCanceler.class) -@MockBean(TaskanaTaskStarter.class) -@MockBean(TaskanaTaskTerminator.class) -@DirtiesContext(classMode = ClassMode.AFTER_CLASS) -@Disabled +@ContextConfiguration public class CamundaTaskEventErrorHandlerTest extends AbsIntegrationTest { @Autowired private AdapterManager adapterManager; diff --git a/taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/TaskanaOutboxRequester.java b/taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/TaskanaOutboxRequester.java index f1da9e89..6292db38 100644 --- a/taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/TaskanaOutboxRequester.java +++ b/taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/TaskanaOutboxRequester.java @@ -4,13 +4,12 @@ import org.json.JSONException; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import pro.taskana.adapter.camunda.outbox.rest.model.CamundaTaskEvent; import pro.taskana.adapter.camunda.outbox.rest.resource.CamundaTaskEventListResource; +import pro.taskana.adapter.systemconnector.camunda.api.impl.HttpHeaderProvider; /** Class to assist with building requests against the TASKNA Outbox REST API. */ public class TaskanaOutboxRequester { @@ -19,15 +18,20 @@ public class TaskanaOutboxRequester { private final TestRestTemplate restTemplate; - public TaskanaOutboxRequester(TestRestTemplate restTemplate) { + private final HttpHeaderProvider httpHeaderProvider; + + public TaskanaOutboxRequester( + TestRestTemplate restTemplate, HttpHeaderProvider httpHeaderProvider) { this.restTemplate = restTemplate; + this.httpHeaderProvider = httpHeaderProvider; } public boolean deleteFailedEvent(int id) throws JSONException { String url = BASIC_OUTBOX_PATH + "/" + id; - HttpEntity requestEntity = prepareEntityFromBody("{}"); + HttpEntity requestEntity = + httpHeaderProvider.prepareNewEntityForOutboxRestApi("{}"); ResponseEntity answer = this.restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, String.class); @@ -41,7 +45,8 @@ public boolean deleteAllFailedEvents() throws JSONException { String url = BASIC_OUTBOX_PATH + "/delete-failed-events"; - HttpEntity requestEntity = prepareEntityFromBody("{}"); + HttpEntity requestEntity = + httpHeaderProvider.prepareNewEntityForOutboxRestApi("{}"); ResponseEntity answer = this.restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); @@ -55,7 +60,7 @@ public List getFailedEvents() { String url = BASIC_OUTBOX_PATH + "?retries=0"; - HttpEntity requestEntity = prepareEntityFromBody("{}"); + HttpEntity requestEntity = httpHeaderProvider.prepareNewEntityForOutboxRestApi(); ResponseEntity answer = this.restTemplate.exchange( url, HttpMethod.GET, requestEntity, CamundaTaskEventListResource.class); @@ -67,7 +72,7 @@ public List getAllEvents() { String url = BASIC_OUTBOX_PATH; - HttpEntity requestEntity = prepareEntityFromBody("{}"); + HttpEntity requestEntity = httpHeaderProvider.prepareNewEntityForOutboxRestApi(); ResponseEntity answer = this.restTemplate.exchange( url, HttpMethod.GET, requestEntity, CamundaTaskEventListResource.class); @@ -80,7 +85,8 @@ public boolean setRemainingRetries(int id, int newRetries) throws JSONException String url = BASIC_OUTBOX_PATH + "/" + id; HttpEntity requestEntity = - prepareEntityFromBody("{\"remainingRetries\":" + newRetries + "}"); + httpHeaderProvider.prepareNewEntityForOutboxRestApi( + "{\"remainingRetries\":" + newRetries + "}"); ResponseEntity answer = this.restTemplate.exchange(url, HttpMethod.PATCH, requestEntity, String.class); @@ -95,7 +101,8 @@ public boolean setRemainingRetriesForAll(int newRetries) throws JSONException { String url = BASIC_OUTBOX_PATH + "?retries=0"; HttpEntity requestEntity = - prepareEntityFromBody("{\"remainingRetries\":" + newRetries + "}"); + httpHeaderProvider.prepareNewEntityForOutboxRestApi( + "{\"remainingRetries\":" + newRetries + "}"); ResponseEntity answer = this.restTemplate.exchange(url, HttpMethod.PATCH, requestEntity, String.class); @@ -104,16 +111,4 @@ public boolean setRemainingRetriesForAll(int newRetries) throws JSONException { } return false; } - - /** - * Helper method to create an HttpEntity from a provided body in JSON-format. - * - * @param jsonBody the body of the HttpEntity - * @return the created HttpEntity - */ - private HttpEntity prepareEntityFromBody(String jsonBody) { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - return new HttpEntity(jsonBody, headers); - } } diff --git a/taskana-adapter-camunda-system-connector/pom.xml b/taskana-adapter-camunda-system-connector/pom.xml index 4a0a48b9..1669498f 100644 --- a/taskana-adapter-camunda-system-connector/pom.xml +++ b/taskana-adapter-camunda-system-connector/pom.xml @@ -21,11 +21,20 @@ spring-boot-starter ${version.spring.boot} + + com.squareup.okhttp3 + okhttp + org.springframework.boot spring-boot-starter-web ${version.spring.boot} + + org.springframework.boot + spring-boot-starter-validation + ${version.spring.boot} + pro.taskana taskana-adapter @@ -46,7 +55,11 @@ org.junit.vintage junit-vintage-engine - + test + + + org.assertj + assertj-core test diff --git a/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/api/impl/CamundaTaskCompleter.java b/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/api/impl/CamundaTaskCompleter.java index 6bb3ee20..245da07c 100644 --- a/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/api/impl/CamundaTaskCompleter.java +++ b/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/api/impl/CamundaTaskCompleter.java @@ -61,7 +61,7 @@ private void setAssigneeToOwnerOfReferencedTask( CamundaSystemConnectorImpl.BODY_SET_ASSIGNEE + "\"" + referencedTask.getAssignee() + "\"}"; HttpEntity requestEntity = - httpHeaderProvider.prepareEntityFromBodyForCamundaRestApi(requestBody); + httpHeaderProvider.prepareNewEntityForCamundaRestApi(requestBody); ResponseEntity responseEntity = this.restTemplate.exchange( requestUrlBuilder.toString(), HttpMethod.POST, requestEntity, String.class); @@ -87,7 +87,7 @@ private void setCompletionByTaskanaAdapterAsLocalVariable( .append(COMPLETED_BY_TASKANA_ADAPTER_LOCAL_VARIABLE); HttpEntity requestEntity = - httpHeaderProvider.prepareEntityFromBodyForCamundaRestApi( + httpHeaderProvider.prepareNewEntityForCamundaRestApi( "{\"value\" : true, \"type\": \"Boolean\"}"); ResponseEntity responseEntity = @@ -117,7 +117,7 @@ private SystemResponse performCompletion( "completing camunda task {} with request body {}", camundaTask.getId(), requestBody); HttpEntity entity = - httpHeaderProvider.prepareEntityFromBodyForCamundaRestApi(requestBody); + httpHeaderProvider.prepareNewEntityForCamundaRestApi(requestBody); try { ResponseEntity responseEntity = diff --git a/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/api/impl/CamundaUtilRequester.java b/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/api/impl/CamundaUtilRequester.java index 24a9ba5b..d53ec95e 100644 --- a/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/api/impl/CamundaUtilRequester.java +++ b/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/api/impl/CamundaUtilRequester.java @@ -29,8 +29,7 @@ public static boolean isTaskNotExisting( .append(camundaTaskId) .toString(); - HttpEntity requestEntity = - httpHeaderProvider.prepareEntityFromBodyForCamundaRestApi("{}"); + HttpEntity requestEntity = httpHeaderProvider.prepareNewEntityForCamundaRestApi(); try { restTemplate.exchange(requestUrl, HttpMethod.GET, requestEntity, String.class); } catch (HttpStatusCodeException ex) { diff --git a/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/api/impl/HttpHeaderProvider.java b/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/api/impl/HttpHeaderProvider.java index 1fe8ef13..111c5805 100644 --- a/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/api/impl/HttpHeaderProvider.java +++ b/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/api/impl/HttpHeaderProvider.java @@ -43,8 +43,23 @@ public HttpHeaders outboxRestApiHeaders() { } } - HttpEntity prepareEntityFromBodyForCamundaRestApi(String requestBody) { + public HttpEntity prepareNewEntityForCamundaRestApi() { HttpHeaders headers = getHttpHeadersForCamundaRestApi(); + return new HttpEntity<>(headers); + } + + public HttpEntity prepareNewEntityForCamundaRestApi(String requestBody) { + HttpHeaders headers = getHttpHeadersForCamundaRestApi(); + return new HttpEntity<>(requestBody, headers); + } + + public HttpEntity prepareNewEntityForOutboxRestApi() { + HttpHeaders headers = getHttpHeadersForOutboxRestApi(); + return new HttpEntity<>(headers); + } + + public HttpEntity prepareNewEntityForOutboxRestApi(String requestBody) { + HttpHeaders headers = getHttpHeadersForOutboxRestApi(); return new HttpEntity<>(requestBody, headers); } diff --git a/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/config/CamundaSystemConnectorConfiguration.java b/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/config/CamundaSystemConnectorConfiguration.java index fa6aa02b..97f25665 100644 --- a/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/config/CamundaSystemConnectorConfiguration.java +++ b/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/config/CamundaSystemConnectorConfiguration.java @@ -1,10 +1,13 @@ package pro.taskana.adapter.systemconnector.camunda.config; +import java.time.Duration; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; +import org.springframework.http.client.OkHttp3ClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; import pro.taskana.adapter.systemconnector.camunda.api.impl.CamundaTaskClaimCanceler; import pro.taskana.adapter.systemconnector.camunda.api.impl.CamundaTaskClaimer; @@ -16,10 +19,16 @@ /** Configures the camunda system connector. */ @Configuration @DependsOn(value = {"adapterSpringContextProvider"}) +@EnableConfigurationProperties(OkHttpProperties.class) public class CamundaSystemConnectorConfiguration { + @Bean - public RestTemplate restTemplate(RestTemplateBuilder builder) { - return builder.build(); + RestTemplate restTemplate(RestTemplateBuilder builder, OkHttpProperties okHttpProperties) { + return builder + .setConnectTimeout(Duration.ofMillis(okHttpProperties.getConnectionTimeout())) + .setReadTimeout(Duration.ofMillis(okHttpProperties.getReadTimeout())) + .requestFactory(OkHttp3ClientHttpRequestFactory.class) + .build(); } @Bean diff --git a/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/config/OkHttpProperties.java b/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/config/OkHttpProperties.java new file mode 100644 index 00000000..0409d607 --- /dev/null +++ b/taskana-adapter-camunda-system-connector/src/main/java/pro/taskana/adapter/systemconnector/camunda/config/OkHttpProperties.java @@ -0,0 +1,29 @@ +package pro.taskana.adapter.systemconnector.camunda.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ConfigurationProperties(prefix = "okhttp") +public class OkHttpProperties { + + private long connectionTimeout = 2_000; + + private long readTimeout = 5_000; + + public long getConnectionTimeout() { + return connectionTimeout; + } + + public void setConnectionTimeout(long connectionTimeout) { + this.connectionTimeout = connectionTimeout; + } + + public long getReadTimeout() { + return readTimeout; + } + + public void setReadTimeout(long readTimeout) { + this.readTimeout = readTimeout; + } +} diff --git a/taskana-adapter-camunda-system-connector/src/test/java/pro/taskana/adapter/systemconnector/camunda/config/OkHttpPropertiesWithDefaultValuesIntegrationTest.java b/taskana-adapter-camunda-system-connector/src/test/java/pro/taskana/adapter/systemconnector/camunda/config/OkHttpPropertiesWithDefaultValuesIntegrationTest.java new file mode 100644 index 00000000..bad3de5c --- /dev/null +++ b/taskana-adapter-camunda-system-connector/src/test/java/pro/taskana/adapter/systemconnector/camunda/config/OkHttpPropertiesWithDefaultValuesIntegrationTest.java @@ -0,0 +1,30 @@ +package pro.taskana.adapter.systemconnector.camunda.config; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.test.context.SpringBootTest; +import pro.taskana.adapter.systemconnector.camunda.config.OkHttpPropertiesWithDefaultValuesIntegrationTest.OkHttpPropertiesWithDefaultValuesIntegrationTestConfiguration; + +@SpringBootTest(classes = {OkHttpPropertiesWithDefaultValuesIntegrationTestConfiguration.class}) +class OkHttpPropertiesWithDefaultValuesIntegrationTest { + + @Test + void default_Value_for_connection_Timeout_is_2000_milliseconds( + @Autowired OkHttpProperties okHttpProperties + ) { + assertThat(okHttpProperties.getConnectionTimeout()).isEqualTo(2_000); + } + + @Test + void default_Value_for_read_Timeout_is_5000_milliseconds( + @Autowired OkHttpProperties okHttpProperties + ) { + assertThat(okHttpProperties.getReadTimeout()).isEqualTo(5_000); + } + + @EnableConfigurationProperties(OkHttpProperties.class) + static class OkHttpPropertiesWithDefaultValuesIntegrationTestConfiguration {} +} diff --git a/taskana-adapter-camunda-system-connector/src/test/java/pro/taskana/adapter/systemconnector/camunda/config/OkHttpPropertiesWithUserDefinedValuesIntegrationTest.java b/taskana-adapter-camunda-system-connector/src/test/java/pro/taskana/adapter/systemconnector/camunda/config/OkHttpPropertiesWithUserDefinedValuesIntegrationTest.java new file mode 100644 index 00000000..bfbb08f6 --- /dev/null +++ b/taskana-adapter-camunda-system-connector/src/test/java/pro/taskana/adapter/systemconnector/camunda/config/OkHttpPropertiesWithUserDefinedValuesIntegrationTest.java @@ -0,0 +1,30 @@ +package pro.taskana.adapter.systemconnector.camunda.config; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.test.context.SpringBootTest; +import pro.taskana.adapter.systemconnector.camunda.config.OkHttpPropertiesWithUserDefinedValuesIntegrationTest.OkHttpPropertiesWithUserDefinedValuesIntegrationTestConfiguration; + +@SpringBootTest( + classes = {OkHttpPropertiesWithUserDefinedValuesIntegrationTestConfiguration.class}, + properties = {"okhttp.connection-timeout=1000", "okhttp.read-timeout=10000"}) +public class OkHttpPropertiesWithUserDefinedValuesIntegrationTest { + + @Test + void default_Value_for_connection_Timeout_is_1000_milliseconds( + @Autowired OkHttpProperties okHttpProperties) { + assertThat(okHttpProperties.getConnectionTimeout()).isEqualTo(1_000); + } + + @Test + void default_Value_for_read_Timeout_is_10000_milliseconds( + @Autowired OkHttpProperties okHttpProperties) { + assertThat(okHttpProperties.getReadTimeout()).isEqualTo(10_000); + } + + @EnableConfigurationProperties(OkHttpProperties.class) + static class OkHttpPropertiesWithUserDefinedValuesIntegrationTestConfiguration {} +} diff --git a/taskana-adapter-camunda-system-connector/src/test/java/pro/taskana/camunda/camundasystemconnector/configuration/CamundaConnectorTestConfiguration.java b/taskana-adapter-camunda-system-connector/src/test/java/pro/taskana/camunda/camundasystemconnector/configuration/CamundaConnectorTestConfiguration.java index 7765f26b..12d3aecf 100644 --- a/taskana-adapter-camunda-system-connector/src/test/java/pro/taskana/camunda/camundasystemconnector/configuration/CamundaConnectorTestConfiguration.java +++ b/taskana-adapter-camunda-system-connector/src/test/java/pro/taskana/camunda/camundasystemconnector/configuration/CamundaConnectorTestConfiguration.java @@ -1,14 +1,18 @@ package pro.taskana.camunda.camundasystemconnector.configuration; import com.fasterxml.jackson.databind.ObjectMapper; +import java.time.Duration; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.web.client.MockServerRestTemplateCustomizer; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.OkHttp3ClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; import pro.taskana.adapter.systemconnector.camunda.api.impl.CamundaTaskCompleter; import pro.taskana.adapter.systemconnector.camunda.api.impl.CamundaTaskRetriever; import pro.taskana.adapter.systemconnector.camunda.api.impl.HttpHeaderProvider; +import pro.taskana.adapter.systemconnector.camunda.config.OkHttpProperties; /** * Configuration for test of Camunda System Connector. @@ -16,15 +20,20 @@ * @author bbr */ @Configuration +@EnableConfigurationProperties(OkHttpProperties.class) public class CamundaConnectorTestConfiguration { @Bean - public RestTemplate restTemplate(RestTemplateBuilder builder) { - return builder.build(); + RestTemplate restTemplate(RestTemplateBuilder builder, OkHttpProperties okHttpProperties) { + return builder + .setConnectTimeout(Duration.ofMillis(okHttpProperties.getConnectionTimeout())) + .setReadTimeout(Duration.ofMillis(okHttpProperties.getReadTimeout())) + .requestFactory(OkHttp3ClientHttpRequestFactory.class) + .build(); } @Bean - public RestTemplateBuilder restTemplateBuilder() { + RestTemplateBuilder restTemplateBuilder() { return new RestTemplateBuilder(new MockServerRestTemplateCustomizer()); }