From: Fiete Ostkamp Date: Thu, 12 Jun 2025 14:36:29 +0000 (+0200) Subject: Add WorkflowController integration test X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;p=sdc%2Fsdc-workflow-designer.git Add WorkflowController integration test - add integration test that tests WorkflowController with full spring context and cassandra backend - use mvn antrun plugin to merge and copy cql files from init module to test for data base initialization Issue-ID: SDC-4737 Change-Id: Ice71adb6c940445f922bb3517b15e85df904c000 Signed-off-by: Fiete Ostkamp --- diff --git a/.gitignore b/.gitignore index 35995a5e..8d88cea1 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ dist *.log *.war .vscode +sdc-workflow-designer-be/src/test/resources/db/*.cql diff --git a/sdc-workflow-designer-be/pom.xml b/sdc-workflow-designer-be/pom.xml index 2833efbe..5919a5c4 100644 --- a/sdc-workflow-designer-be/pom.xml +++ b/sdc-workflow-designer-be/pom.xml @@ -29,6 +29,7 @@ 5.9.1 1.9.0 3.1.10 + 1.19.1 @@ -172,18 +173,6 @@ org.springframework.boot spring-boot-starter-tomcat - - org.springframework - spring-web - - - org.springframework - spring-core - - - org.springframework - spring-webmvc - @@ -384,24 +373,6 @@ org.springframework.boot spring-boot-starter-test test - - - asm - org.ow2.asm - - - junit - junit - - - - org.junit.vintage - junit-vintage-engine - - org.springframework.cloud @@ -617,6 +588,24 @@ zusammen-commons-configuration ${zusammen.version} + + org.testcontainers + testcontainers + ${testcontainers.version} + test + + + org.testcontainers + cassandra + ${testcontainers.version} + test + + + org.testcontainers + junit-jupiter + ${testcontainers.version} + test + @@ -638,6 +627,34 @@ maven-surefire-plugin 3.1.2 + + maven-antrun-plugin + 3.0.0 + + + + generate-sources + + + + + + + + + + + + + run + + + + diff --git a/sdc-workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/ArtifactAssociationHandlerTest.java b/sdc-workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/ArtifactAssociationHandlerTest.java index 131e14be..ba203ef0 100644 --- a/sdc-workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/ArtifactAssociationHandlerTest.java +++ b/sdc-workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/ArtifactAssociationHandlerTest.java @@ -1,5 +1,6 @@ /* * Copyright © 2018 European Support Limited + * Modifications Copyright © 2025 Deutsche Telekom * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,44 +27,26 @@ import java.io.InputStream; import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.Mockito; import org.onap.sdc.workflow.api.types.dto.ArtifactDeliveriesRequestDto; import org.onap.sdc.workflow.persistence.types.ArtifactEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Component; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.web.client.RestTemplate; - -@SpringJUnitConfig( - classes = {ArtifactAssociationHandlerTest.RestBuilderMockProvider.class, ArtifactAssociationService.class}) +@DirtiesContext +@SpringBootTest(classes = {ArtifactAssociationService.class}) @TestPropertySource(locations = "classpath:application-test.properties") -@Component("ArtifactAssociationHandlerTest") public class ArtifactAssociationHandlerTest { - @Configuration - static class RestBuilderMockProvider { - - @Bean - public RestTemplateBuilder templateBuilder() { - return Mockito.mock(RestTemplateBuilder.class); - } - - @Bean - public RestTemplate restTemplate() { - return Mockito.mock(RestTemplate.class); - } - } - private static final String FILE_NAME = "fileName.txt"; private static final String USER_ID = "cs0008"; private static final String END_POINT = @@ -82,7 +65,9 @@ public class ArtifactAssociationHandlerTest { @Value("${sdc.be.external.password}") private String sdcPassword; - @Autowired + @MockBean + private RestTemplateBuilder restTemplateBuilder; + @MockBean private RestTemplate restClientMock; diff --git a/sdc-workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerIntegrationTest.java b/sdc-workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerIntegrationTest.java new file mode 100644 index 00000000..21ea64d9 --- /dev/null +++ b/sdc-workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerIntegrationTest.java @@ -0,0 +1,95 @@ +/* + * Copyright © 2025 Deutsche Telekom + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * 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 org.onap.sdc.workflow.api; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpHeaders; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; +import org.testcontainers.containers.CassandraContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import lombok.SneakyThrows; + +@Testcontainers +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, + properties = { + "spring.data.cassandra.contact-points=localhost", + "spring.data.cassandra.schema-action=CREATE_IF_NOT_EXISTS" +}) +public class WorkflowControllerIntegrationTest { + + @LocalServerPort + int port; + + ObjectMapper mapper = new ObjectMapper(); + + @Autowired + RestTemplateBuilder builder; + RestTemplate restTemplate; + + @BeforeEach + void setup() { + this.restTemplate = builder + .rootUri("http://localhost:" + port) + .defaultHeader(HttpHeaders.ACCEPT, "application/json") + .build(); + } + + + + @Container + private static CassandraContainer cassandraContainer + = new CassandraContainer<>("cassandra:3.11.2") + .withInitScript("db/init.cql") + .withExposedPorts(9042); + + @DynamicPropertySource + static void configureProperties(DynamicPropertyRegistry registry) { + registry.add("spring.data.cassandra.port", () -> cassandraContainer.getFirstMappedPort()); + } + + @Test + @SneakyThrows + public void someTest() { + String baseUrl = "/wf/workflows"; + String queryParams = UriComponentsBuilder + .fromUriString(baseUrl) + .queryParam("sort", "name:asc") + .queryParam("limit", 31) + .queryParam("offset", 0) + .queryParam("archiving", "ACTIVE") + .toUriString(); + + ResponseEntity response = restTemplate.getForEntity(queryParams, String.class); + assert(response.getStatusCode().is2xxSuccessful()); + + } + +}