Skip to content

Commit 2e0c034

Browse files
authored
Merge pull request #255 from pagopa/feature/SELC-6471
Feature/selc 6471
2 parents f3cd392 + 70cbfaa commit 2e0c034

File tree

20 files changed

+6204
-1
lines changed

20 files changed

+6204
-1
lines changed

apps/user-ms/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,28 @@ To perform local tests of functionalities that involve sending messages to the S
9999
- EVENT_HUB_BASE_PATH
100100
- SHARED_ACCESS_KEY_NAME
101101
- EVENTHUB-SC-USERS-SELFCARE-WO-KEY-LC
102+
103+
## Cucumber Tests
104+
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+
USER-REGISTRY-API-KEY=9fypKNFfVY8jvWHUgABpH23VrChnRzvRpSq5b1ng
112+
USER_REGISTRY_URL=user-registry-mock
113+
STORAGE_CONTAINER_TEMPLATES=resources
114+
STORAGE_CONTAINER_PRODUCT=products
115+
MONGODB-CONNECTION-STRING=mongodb://localhost:27018
116+
JWT-PUBLIC-KEY=-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnpt9gVNzDW6FpBk/TwNCqd+URprAD3tfGhYWhq2sAxDAP5u9GxgHybFQ8XGNY3yeb9rp5lxLqAcxOg5j19i0tvjkK/Q7GUezteY8xpEfRLJxglIaux/sM8M82YiHCwAjgQPF+EmIPboER5fLLnvDXyl+FYzcGhwPc8Z8AGlYjv8mgijrffSpbjtd7FF0I6WxIqKFHFhIsfUMezBa7NTMSIrxp5dACCMetrKkggTK3Yq8DP86nWuSdDsjIGLrIQFuMQOALr46cSafvHMFK5B/iIDfFLAek7Kg2tELHXWdcctjdPwsc38EXb3P2Fi70WOcLg9lAx9EDgizVLaG5obCCQIDAQAB-----END PUBLIC KEY-----
117+
JAVA_TOOL_OPTIONS=-Duser.timezone=GMT -Duser.language=en -Duser.country=US
118+
BLOB-STORAGE-PRODUCT-CONNECTION-STRING=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCD9I1QhZT4gRjAAHEDPazjFIwtg==;BlobEndpoint=http://localhost:10000/devstoreaccount1;
119+
120+
Next, you can proceed to run the Cucumber tests.
121+
122+
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:
123+
it.pagopa.selfcare.user.integration_test.CucumberSuite.
124+
125+
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:
126+
it.pagopa.selfcare.user.integration_test.CucumberSuite.

apps/user-ms/docker-compose.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
version: '3.8'
2+
services:
3+
4+
mongodb:
5+
image: mongo:latest
6+
ports:
7+
- '27018:27017'
8+
volumes:
9+
- "./src/test/resources/db:/docker-entrypoint-initdb.d"
10+
networks:
11+
- develop-network
12+
13+
azurite:
14+
image: mcr.microsoft.com/azure-storage/azurite
15+
container_name: azurite
16+
ports:
17+
- "10000:10000"
18+
command: "azurite --blobHost 0.0.0.0 --inMemoryPersistence"
19+
environment:
20+
- AZURITE_ACCOUNTS=devstoreaccount1:Eby8vdM02xNOcqFlqUwJPLlmEtlCD9I1QhZT4gRjAAHEDPazjFIwtg==
21+
networks:
22+
- develop-network
23+
24+
azure-cli:
25+
build:
26+
context: "../../."
27+
dockerfile: "apps/user-ms/src/test/resources/Dockerfile-azure-cli"
28+
container_name: azure-cli
29+
depends_on:
30+
- azurite
31+
networks:
32+
- develop-network
33+
volumes:
34+
- "./src/test/resources/blobStorageInit/initAzurite.sh:/initAzurite.sh"
35+
environment:
36+
- SELFCARE_INFRA_PRIVATE_ENV=dev
37+
- GITHUB_TOKEN=REPLACE_WITH_TOKEN
38+
39+
mockserver:
40+
image: mockserver/mockserver
41+
ports:
42+
- '1080:1080'
43+
environment:
44+
- MOCKSERVER_INITIALIZATION_JSON_PATH=/config/*.json
45+
- MOCKSERVER_ENABLE_CORS_FOR_API="true"
46+
- MOCKSERVER_ENABLE_CORS_FOR_ALL_RESPONSES="true"
47+
volumes:
48+
- "./src/test/resources/mock:/config"
49+
networks:
50+
- develop-network
51+
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+
68+
networks:
69+
develop-network:
70+
name: selfcare-develop-network

apps/user-ms/pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<surefire-plugin.version>3.1.2</surefire-plugin.version>
2626
<user-sdk.version>0.1.3</user-sdk.version>
2727
<quarkus-openapi-generator.version>2.4.1</quarkus-openapi-generator.version>
28+
<quarkus-cucumber-version>1.3.0</quarkus-cucumber-version>
2829
</properties>
2930
<dependencyManagement>
3031
<dependencies>
@@ -56,6 +57,12 @@
5657
<artifactId>quarkus-junit5</artifactId>
5758
<scope>test</scope>
5859
</dependency>
60+
<dependency>
61+
<groupId>org.junit.platform</groupId>
62+
<artifactId>junit-platform-suite</artifactId>
63+
<version>1.10.1</version>
64+
<scope>test</scope>
65+
</dependency>
5966
<dependency>
6067
<groupId>io.quarkus</groupId>
6168
<artifactId>quarkus-junit5-mockito</artifactId>
@@ -188,11 +195,22 @@
188195
<artifactId>user-sdk-event</artifactId>
189196
<version>0.0.1</version>
190197
</dependency>
198+
<dependency>
199+
<groupId>it.pagopa.selfcare</groupId>
200+
<artifactId>cucumber-sdk</artifactId>
201+
<version>0.0.4</version>
202+
<scope>test</scope>
203+
</dependency>
191204
<dependency>
192205
<groupId>com.microsoft.azure</groupId>
193206
<artifactId>applicationinsights-web</artifactId>
194207
<version>2.6.4</version>
195208
</dependency>
209+
<dependency>
210+
<groupId>io.quarkiverse.cucumber</groupId>
211+
<artifactId>quarkus-cucumber</artifactId>
212+
<version>${quarkus-cucumber-version}</version>
213+
</dependency>
196214
</dependencies>
197215
<build>
198216
<plugins>

apps/user-ms/src/main/java/it/pagopa/selfcare/user/controller/UserController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public Uni<UserResponse> getUserInfo(@PathParam(value = "id") String userId,
101101
return userService.retrievePerson(userId, productId, institutionId);
102102
}
103103

104+
104105
@Operation(description = "Retrieves products info and role which the user is enabled", summary = "Retrieve product information and user roles")
105106
@GET
106107
@Path("/{userId}/institutions")
@@ -294,7 +295,6 @@ public Uni<Void> updateUserProductStatus(@PathParam("id") String userId,
294295
.onItem().transformToUni(loggedUser -> userService.updateUserProductStatus(userId, institutionId, productId, status, productRole, loggedUser));
295296
}
296297

297-
298298
/**
299299
* The createOrUpdateByUserId function is used to update existing user adding userRole.
300300
*

apps/user-ms/src/main/resources/application.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ quarkus.http.limits.max-form-attribute-size=4096
3737
quarkus.mongodb.connection-string = ${MONGODB-CONNECTION-STRING}
3838
quarkus.mongodb.database = selcUser
3939

40+
quarkus.index-dependency.cucumber.group-id=it.pagopa.selfcare
41+
quarkus.index-dependency.cucumber.artifact-id=cucumber-sdk
42+
4043
mp.openapi.extensions.smallrye.operationIdStrategy=METHOD
4144

4245
#quarkus.native.resources.includes=publicKey.pem
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package it.pagopa.selfcare.user.integration_test;
2+
3+
import io.cucumber.java.Before;
4+
import io.quarkiverse.cucumber.CucumberOptions;
5+
import io.quarkiverse.cucumber.CucumberQuarkusTest;
6+
import io.restassured.RestAssured;
7+
import lombok.extern.slf4j.Slf4j;
8+
import org.eclipse.microprofile.config.ConfigProvider;
9+
import org.junit.jupiter.api.AfterAll;
10+
import org.junit.jupiter.api.BeforeAll;
11+
12+
import java.io.IOException;
13+
import java.io.InputStream;
14+
import java.nio.charset.StandardCharsets;
15+
import java.util.Scanner;
16+
17+
@Slf4j
18+
@CucumberOptions(
19+
features = "src/test/resources/features",
20+
glue = {"it.pagopa.selfcare.cucumber.utils", "it.pagopa.selfcare.user.integration_test"},
21+
plugin = {
22+
"html:target/cucumber-report/cucumber.html",
23+
"json:target/cucumber-report/cucumber.json"
24+
})
25+
public class CucumberSuite extends CucumberQuarkusTest {
26+
27+
public static void main(String[] args) {
28+
runMain(CucumberSuite.class, args);
29+
}
30+
31+
@BeforeAll
32+
static void setup() throws IOException {
33+
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
34+
try (InputStream inputStream = classLoader.getResourceAsStream("key/public-key.pub")) {
35+
if (inputStream == null) {
36+
throw new IOException("Public key file not found in classpath");
37+
}
38+
String publicKey = new Scanner(inputStream, StandardCharsets.UTF_8.name()).useDelimiter("\\A").next();
39+
System.setProperty("JWT-PUBLIC-KEY", publicKey);
40+
}
41+
}
42+
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);
47+
}
48+
49+
@AfterAll
50+
static void tearDown() {
51+
log.info("Cucumber tests are finished.");
52+
System.exit(0);
53+
}
54+
55+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package it.pagopa.selfcare.user.integration_test.steps;
2+
3+
import io.cucumber.java.After;
4+
import io.cucumber.java.Scenario;
5+
import it.pagopa.selfcare.user.entity.UserInstitution;
6+
import jakarta.enterprise.context.ApplicationScoped;
7+
import lombok.extern.slf4j.Slf4j;
8+
9+
import java.util.Objects;
10+
11+
@Slf4j
12+
@ApplicationScoped
13+
public class InstitutionSteps {
14+
private final String mockUserId = "35a78332-d038-4bfa-8e85-2cba7f6b7bf7";
15+
private final String mockUserId2 = "97a511a7-2acc-47b9-afed-2f3c65753b4a";
16+
private final String mockInstitutionId2 = "e3a4c8d2-5b79-4f3e-92d7-184a9b6fcd21";
17+
18+
@After("@RemoveUserInstitutions")
19+
public void removeUserInstitutionAfterCreateFromAPI(Scenario scenario) {
20+
UserInstitution.find("institutionId = ?1 and userId = ?2", mockInstitutionId2, mockUserId2)
21+
.firstResult()
22+
.subscribe()
23+
.with(
24+
success -> {
25+
UserInstitution userInstitution = (UserInstitution) success;
26+
if(!Objects.isNull(userInstitution)) {
27+
UserInstitution.deleteById(userInstitution.getId())
28+
.subscribe()
29+
.with(
30+
deleteSuccess -> log.info("Deleted userInstitution with userId {} and institutionId {}", mockUserId2, mockInstitutionId2),
31+
deleteFailure -> log.info("Failed to delete userInstitution with userId {} and institutionId {}: {}", mockUserId2, mockInstitutionId2, deleteFailure.getMessage())
32+
);
33+
} else {
34+
log.info("No userInstitution with userId {} and institutionId {}", mockUserId2, mockInstitutionId2);
35+
}
36+
},
37+
failure -> log.info("Failed to find userInstitution with userId {} and institutionId {}", mockUserId2, mockInstitutionId2)
38+
);
39+
40+
UserInstitution.find("institutionId = ?1 and userId = ?2", mockInstitutionId2, mockUserId)
41+
.firstResult()
42+
.subscribe()
43+
.with(
44+
success -> {
45+
UserInstitution userInstitution = (UserInstitution) success;
46+
if(!Objects.isNull(userInstitution)) {
47+
UserInstitution.deleteById(userInstitution.getId())
48+
.subscribe()
49+
.with(
50+
deleteSuccess -> log.info("Deleted userInstitution with userId {} and institutionId {}", mockUserId, mockInstitutionId2),
51+
deleteFailure -> log.info("Failed to delete userInstitution with userId {} and institutionId {}: {}", mockUserId, mockInstitutionId2, deleteFailure.getMessage())
52+
);
53+
} else {
54+
log.info("No userInstitution with userId {} and institutionId {}", mockUserId, mockInstitutionId2);
55+
}
56+
},
57+
failure -> log.info("Failed to find userInstitution with userId {} and institutionId {}", mockUserId, mockInstitutionId2)
58+
);
59+
}
60+
}

0 commit comments

Comments
 (0)