Skip to content

Commit ccbdb22

Browse files
[SELC-7078] Running integration tests with github action, testcontainers and docker-compose
2 parents fba0279 + e715ac0 commit ccbdb22

File tree

14 files changed

+2765
-92
lines changed

14 files changed

+2765
-92
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: "Integration Tests (user-ms)"
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
types: [ opened, synchronize, reopened ]
9+
branches:
10+
- main
11+
- releases/*
12+
paths:
13+
- "apps/user-ms/**"
14+
15+
jobs:
16+
integration_tests_ms:
17+
name: 'Integration Tests (user-ms)'
18+
runs-on: ubuntu-24.04
19+
20+
steps:
21+
- name: Set missing library
22+
run: |
23+
wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
24+
sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
25+
26+
- name: Setup Maven Action
27+
uses: s4u/setup-maven-action@fa2c7e4517ed008b1f73e7e0195a9eecf5582cd4
28+
with:
29+
checkout-fetch-depth: 0
30+
java-version: 17
31+
java-distribution: 'temurin'
32+
maven-version: '3.9.5'
33+
cache-enabled: true
34+
35+
- uses: s4u/maven-settings-action@60912582505985be4cc55d2b890eb32767f8de5f # pin@v2.8.0
36+
with:
37+
servers: '[{"id": "selfcare-onboarding", "username": "${{ github.actor }}", "password": "${{ secrets.GITHUB_TOKEN }}"}]'
38+
39+
- name: Run Integration Tests
40+
run: mvn --projects :user-ms --also-make test -Dtest=CucumberSuite -Dsurefire.failIfNoSpecifiedTests=false
41+
shell: bash

apps/user-ms/README.md

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,28 +100,9 @@ To perform local tests of functionalities that involve sending messages to the S
100100
- SHARED_ACCESS_KEY_NAME
101101
- EVENTHUB-SC-USERS-SELFCARE-WO-KEY-LC
102102

103-
## Cucumber Tests
103+
## Cucumber Tests (Integration Tests)
104104

105-
To run the Cucumber tests, first, open the docker-compose.yml file located in the root of user-ms and replace the placeholder REPLACE_WITH_TOKEN with a valid GitHub PAT.
106-
107-
Next, start the docker-compose to run the containers for MongoDB, Azurite, and the mock server.
108-
109-
At this point, launch the user-ms microservice locally with the following environment variables:
110-
111-
```environment variables
112-
USER-REGISTRY-API-KEY=9fypKNFfVY8jvWHUgABpH23VrChnRzvRpSq5b1ng
113-
USER_REGISTRY_URL=http://localhost:1080/user-registry-mock/v1
114-
STORAGE_CONTAINER_TEMPLATES=resources
115-
STORAGE_CONTAINER_PRODUCT=products
116-
MONGODB-CONNECTION-STRING=mongodb://localhost:27018
117-
JWT-PUBLIC-KEY=-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnpt9gVNzDW6FpBk/TwNCqd+URprAD3tfGhYWhq2sAxDAP5u9GxgHybFQ8XGNY3yeb9rp5lxLqAcxOg5j19i0tvjkK/Q7GUezteY8xpEfRLJxglIaux/sM8M82YiHCwAjgQPF+EmIPboER5fLLnvDXyl+FYzcGhwPc8Z8AGlYjv8mgijrffSpbjtd7FF0I6WxIqKFHFhIsfUMezBa7NTMSIrxp5dACCMetrKkggTK3Yq8DP86nWuSdDsjIGLrIQFuMQOALr46cSafvHMFK5B/iIDfFLAek7Kg2tELHXWdcctjdPwsc38EXb3P2Fi70WOcLg9lAx9EDgizVLaG5obCCQIDAQAB-----END PUBLIC KEY-----
118-
JAVA_TOOL_OPTIONS=-Duser.timezone=GMT -Duser.language=en -Duser.country=US
119-
BLOB-STORAGE-PRODUCT-CONNECTION-STRING=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCD9I1QhZT4gRjAAHEDPazjFIwtg==;BlobEndpoint=http://localhost:10000/devstoreaccount1;
120-
```
121-
Next, you can proceed to run the Cucumber tests.
122-
123-
To run all the tests, you can open the CucumberSuite file and execute it by pressing the play button, or you can create a JUnit configuration, specifying in the "Build and run" section, under Class, the following:
124-
it.pagopa.selfcare.user.integration_test.CucumberSuite.
105+
To run the Cucumber tests locally, execute it.pagopa.selfcare.user.integration_test.CucumberSuite
125106

126107
To run a single test or a specific feature file, open the file and press the play button for the corresponding test (or the file). The first execution will fail; you will then need to modify the configuration by setting the main class to:
127-
it.pagopa.selfcare.user.integration_test.CucumberSuite.
108+
it.pagopa.selfcare.user.integration_test.CucumberSuite.

apps/user-ms/docker-compose.yml

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ services:
44
mongodb:
55
image: mongo:latest
66
ports:
7-
- '27018:27017'
7+
- '27017:27017'
88
volumes:
99
- "./src/test/resources/db:/docker-entrypoint-initdb.d"
1010
networks:
1111
- develop-network
1212

1313
azurite:
1414
image: mcr.microsoft.com/azure-storage/azurite
15-
container_name: azurite
1615
ports:
1716
- "10000:10000"
1817
command: "azurite --blobHost 0.0.0.0 --inMemoryPersistence"
@@ -25,16 +24,15 @@ services:
2524
build:
2625
context: "../../."
2726
dockerfile: "apps/user-ms/src/test/resources/Dockerfile-azure-cli"
28-
container_name: azure-cli
2927
depends_on:
3028
- azurite
3129
networks:
3230
- develop-network
3331
volumes:
3432
- "./src/test/resources/blobStorageInit/initAzurite.sh:/initAzurite.sh"
33+
- "./src/test/resources/blobStorageInit/products.json:/workspace/products.json"
3534
environment:
3635
- SELFCARE_INFRA_PRIVATE_ENV=dev
37-
- GITHUB_TOKEN=REPLACE_WITH_TOKEN
3836

3937
mockserver:
4038
image: mockserver/mockserver
@@ -49,22 +47,6 @@ services:
4947
networks:
5048
- develop-network
5149

52-
#user-ms:
53-
# build:
54-
# context: "../../." # Indica il percorso dove si trova il codice del microservizio
55-
# dockerfile: "apps/user-ms/src/test/resources/Dockerfile-cucumber" # Puoi includere un Dockerfile per la build del servizio
56-
# ports:
57-
# - '8080:8080' # Porta del microservizio Quarkus
58-
# environment:
59-
# - USER_REGISTRY_URL=http://localhost:1080/user-registry-mock/v1
60-
# - JWT-PUBLIC-KEY=-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnpt9gVNzDW6FpBk/TwNCqd+URprAD3tfGhYWhq2sAxDAP5u9GxgHybFQ8XGNY3yeb9rp5lxLqAcxOg5j19i0tvjkK/Q7GUezteY8xpEfRLJxglIaux/sM8M82YiHCwAjgQPF+EmIPboER5fLLnvDXyl+FYzcGhwPc8Z8AGlYjv8mgijrffSpbjtd7FF0I6WxIqKFHFhIsfUMezBa7NTMSIrxp5dACCMetrKkggTK3Yq8DP86nWuSdDsjIGLrIQFuMQOALr46cSafvHMFK5B/iIDfFLAek7Kg2tELHXWdcctjdPwsc38EXb3P2Fi70WOcLg9lAx9EDgizVLaG5obCCQIDAQAB-----END PUBLIC KEY-----
61-
# - MONGODB-CONNECTION-STRING=mongodb://localhost:27017
62-
# networks:
63-
# - develop-network
64-
# depends_on:
65-
# - mongodb # Dipende da mongodb
66-
# - mockserver # Dipende anche da mockserver
67-
6850
networks:
6951
develop-network:
7052
name: selfcare-develop-network

apps/user-ms/pom.xml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<user-sdk.version>0.1.3</user-sdk.version>
2727
<quarkus-openapi-generator.version>2.4.1</quarkus-openapi-generator.version>
2828
<quarkus-cucumber-version>1.3.0</quarkus-cucumber-version>
29+
<cucumber-sdk.version>0.0.5</cucumber-sdk.version>
2930
</properties>
3031
<dependencyManagement>
3132
<dependencies>
@@ -84,8 +85,9 @@
8485
<version>1.2.3</version>
8586
</dependency>
8687
<dependency>
87-
<groupId>io.quarkus</groupId>
88-
<artifactId>quarkus-test-mongodb</artifactId>
88+
<groupId>org.apache.httpcomponents</groupId>
89+
<artifactId>httpclient</artifactId>
90+
<version>4.5.14</version>
8991
</dependency>
9092
<dependency>
9193
<groupId>org.projectlombok</groupId>
@@ -190,15 +192,10 @@
190192
<artifactId>microprofile-metrics-api</artifactId>
191193
<version>5.1.1</version>
192194
</dependency>
193-
<dependency>
194-
<groupId>it.pagopa.selfcare</groupId>
195-
<artifactId>user-sdk-event</artifactId>
196-
<version>0.0.1</version>
197-
</dependency>
198195
<dependency>
199196
<groupId>it.pagopa.selfcare</groupId>
200197
<artifactId>cucumber-sdk</artifactId>
201-
<version>0.0.4</version>
198+
<version>${cucumber-sdk.version}</version>
202199
<scope>test</scope>
203200
</dependency>
204201
<dependency>
@@ -210,6 +207,7 @@
210207
<groupId>io.quarkiverse.cucumber</groupId>
211208
<artifactId>quarkus-cucumber</artifactId>
212209
<version>${quarkus-cucumber-version}</version>
210+
<scope>test</scope>
213211
</dependency>
214212
</dependencies>
215213
<build>
@@ -273,6 +271,31 @@
273271
</configuration>
274272
</execution>
275273
</executions>
274+
<configuration>
275+
<systemPropertyVariables>
276+
<user.language>en</user.language>
277+
<user.country>US</user.country>
278+
<user.timezone>GMT</user.timezone>
279+
</systemPropertyVariables>
280+
</configuration>
281+
</plugin>
282+
<plugin>
283+
<artifactId>maven-surefire-plugin</artifactId>
284+
<version>${surefire-plugin.version}</version>
285+
<executions>
286+
<execution>
287+
<goals>
288+
<goal>test</goal>
289+
</goals>
290+
</execution>
291+
</executions>
292+
<configuration>
293+
<systemPropertyVariables>
294+
<user.language>en</user.language>
295+
<user.country>US</user.country>
296+
<user.timezone>GMT</user.timezone>
297+
</systemPropertyVariables>
298+
</configuration>
276299
</plugin>
277300
</plugins>
278301
</build>

apps/user-ms/src/test/java/it/pagopa/selfcare/user/integration_test/CucumberSuite.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package it.pagopa.selfcare.user.integration_test;
22

3-
import io.cucumber.java.Before;
43
import io.quarkiverse.cucumber.CucumberOptions;
54
import io.quarkiverse.cucumber.CucumberQuarkusTest;
65
import io.restassured.RestAssured;
76
import lombok.extern.slf4j.Slf4j;
8-
import org.eclipse.microprofile.config.ConfigProvider;
97
import org.junit.jupiter.api.AfterAll;
108
import org.junit.jupiter.api.BeforeAll;
9+
import org.testcontainers.containers.ComposeContainer;
10+
import org.testcontainers.containers.wait.strategy.Wait;
1111

12+
import java.io.File;
1213
import java.io.IOException;
1314
import java.io.InputStream;
1415
import java.nio.charset.StandardCharsets;
@@ -24,6 +25,8 @@
2425
})
2526
public class CucumberSuite extends CucumberQuarkusTest {
2627

28+
private static ComposeContainer composeContainer;
29+
2730
public static void main(String[] args) {
2831
runMain(CucumberSuite.class, args);
2932
}
@@ -38,18 +41,22 @@ static void setup() throws IOException {
3841
String publicKey = new Scanner(inputStream, StandardCharsets.UTF_8.name()).useDelimiter("\\A").next();
3942
System.setProperty("JWT-PUBLIC-KEY", publicKey);
4043
}
41-
}
4244

43-
@Before
44-
public void setupRestAssured() {
45-
RestAssured.baseURI = ConfigProvider.getConfig().getValue("rest-assured.base-url", String.class);
46-
RestAssured.port = ConfigProvider.getConfig().getValue("cucumber.http.test-port", Integer.class);
45+
// By default, quarkus starts the ms on port 8081
46+
RestAssured.baseURI = "http://localhost";
47+
RestAssured.port = 8081;
48+
49+
composeContainer = new ComposeContainer(new File("docker-compose.yml")).withLocalCompose(true)
50+
.waitingFor("azure-cli", Wait.forLogMessage(".*BLOBSTORAGE INITIALIZED.*\\n", 1));
51+
composeContainer.start();
52+
Runtime.getRuntime().addShutdownHook(new Thread(composeContainer::stop));
53+
54+
log.info("\nLANGUAGE: {}\nCOUNTRY: {}\nTIMEZONE: {}\n", System.getProperty("user.language"), System.getProperty("user.country"), System.getProperty("user.timezone"));
4755
}
4856

4957
@AfterAll
5058
static void tearDown() {
5159
log.info("Cucumber tests are finished.");
52-
System.exit(0);
5360
}
5461

5562
}

apps/user-ms/src/test/java/it/pagopa/selfcare/user/service/UserInfoServiceTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import io.quarkus.mongodb.panache.reactive.ReactivePanacheQuery;
44
import io.quarkus.panache.mock.PanacheMock;
5-
import io.quarkus.test.common.QuarkusTestResource;
65
import io.quarkus.test.junit.QuarkusTest;
7-
import io.quarkus.test.mongodb.MongoTestResource;
86
import io.smallrye.mutiny.Uni;
97
import it.pagopa.selfcare.user.controller.response.UserInfoResponse;
108
import it.pagopa.selfcare.user.entity.UserInfo;
@@ -17,7 +15,6 @@
1715
import static org.mockito.Mockito.when;
1816

1917
@QuarkusTest
20-
@QuarkusTestResource(MongoTestResource.class)
2118
class UserInfoServiceTest {
2219

2320
@Inject

apps/user-ms/src/test/java/it/pagopa/selfcare/user/service/UserInstitutionServiceTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
import io.quarkus.mongodb.reactive.ReactiveMongoCollection;
88
import io.quarkus.panache.mock.PanacheMock;
99
import io.quarkus.test.InjectMock;
10-
import io.quarkus.test.common.QuarkusTestResource;
1110
import io.quarkus.test.junit.QuarkusTest;
12-
import io.quarkus.test.mongodb.MongoTestResource;
1311
import io.smallrye.mutiny.Multi;
1412
import io.smallrye.mutiny.Uni;
1513
import io.smallrye.mutiny.helpers.test.AssertSubscriber;
@@ -43,7 +41,6 @@
4341
import static org.mockito.Mockito.when;
4442

4543
@QuarkusTest
46-
@QuarkusTestResource(MongoTestResource.class)
4744
class UserInstitutionServiceTest {
4845

4946
@Inject

apps/user-ms/src/test/java/it/pagopa/selfcare/user/service/UserRegistryServiceTest.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package it.pagopa.selfcare.user.service;
22

33
import io.quarkus.test.InjectMock;
4-
import io.quarkus.test.common.QuarkusTestResource;
54
import io.quarkus.test.junit.QuarkusTest;
6-
import io.quarkus.test.mongodb.MongoTestResource;
75
import io.smallrye.mutiny.Multi;
86
import io.smallrye.mutiny.Uni;
97
import io.smallrye.mutiny.helpers.test.UniAssertSubscriber;
@@ -19,26 +17,19 @@
1917
import org.junit.jupiter.api.BeforeAll;
2018
import org.junit.jupiter.api.Test;
2119
import org.mockito.ArgumentCaptor;
22-
import org.openapi.quarkus.user_registry_json.model.EmailCertifiableSchema;
23-
import org.openapi.quarkus.user_registry_json.model.FamilyNameCertifiableSchema;
24-
import org.openapi.quarkus.user_registry_json.model.MutableUserFieldsDto;
25-
import org.openapi.quarkus.user_registry_json.model.NameCertifiableSchema;
26-
import org.openapi.quarkus.user_registry_json.model.SaveUserDto;
27-
import org.openapi.quarkus.user_registry_json.model.UserId;
28-
import org.openapi.quarkus.user_registry_json.model.UserResource;
29-
import org.openapi.quarkus.user_registry_json.model.UserSearchDto;
20+
import org.openapi.quarkus.user_registry_json.model.*;
3021

3122
import java.util.List;
3223
import java.util.Map;
3324
import java.util.UUID;
3425

3526
import static io.smallrye.common.constraint.Assert.assertNotNull;
36-
import static org.junit.jupiter.api.Assertions.*;
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
28+
import static org.junit.jupiter.api.Assertions.assertThrows;
3729
import static org.mockito.ArgumentMatchers.*;
3830
import static org.mockito.Mockito.*;
3931

4032
@QuarkusTest
41-
@QuarkusTestResource(MongoTestResource.class)
4233
public class UserRegistryServiceTest {
4334
@Inject
4435
UserRegistryService userRegistryService;

apps/user-ms/src/test/java/it/pagopa/selfcare/user/service/UserServiceTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import io.quarkus.mongodb.panache.reactive.ReactivePanacheQuery;
66
import io.quarkus.panache.mock.PanacheMock;
77
import io.quarkus.test.InjectMock;
8-
import io.quarkus.test.common.QuarkusTestResource;
98
import io.quarkus.test.junit.QuarkusTest;
10-
import io.quarkus.test.mongodb.MongoTestResource;
119
import io.smallrye.common.constraint.Assert;
1210
import io.smallrye.mutiny.Multi;
1311
import io.smallrye.mutiny.Uni;
@@ -67,7 +65,6 @@
6765
import static org.mockito.Mockito.*;
6866

6967
@QuarkusTest
70-
@QuarkusTestResource(MongoTestResource.class)
7168
class UserServiceTest {
7269

7370
@Inject
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
# cucumber.publish.enabled=true
2-
cucumber.http.test-port=8080
3-
cucumber.http.host=http://localhost
4-
quarkus.mongodb.connection-string=mongodb://localhost:27018
1+
# These properties are used to run integration tests
2+
3+
quarkus.mongodb.connection-string=mongodb://localhost:27017
54
quarkus.mongodb.database=selcUser
6-
rest-assured.base-url=http://localhost
7-
rest-assured.port=8080
5+
6+
mp.jwt.verify.publickey=${JWT-PUBLIC-KEY:test}
7+
8+
quarkus.openapi-generator.user_registry_json.auth.api_key.api-key=9fypKNFfVY8jvWHUgABpH23VrChnRzvRpSq5b1ng
9+
quarkus.rest-client."org.openapi.quarkus.user_registry_json.api.UserApi".url=http://localhost:1080/user-registry-mock/v1
10+
11+
user-ms.blob-storage.container-templates=resources
12+
user-ms.blob-storage.container-product=products
13+
user-ms.blob-storage.connection-string-product=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCD9I1QhZT4gRjAAHEDPazjFIwtg==;BlobEndpoint=http://localhost:10000/devstoreaccount1;
14+
user-ms.blob-storage.connection-string-templates=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCD9I1QhZT4gRjAAHEDPazjFIwtg==;BlobEndpoint=http://localhost:10000/devstoreaccount1;

0 commit comments

Comments
 (0)