Skip to content

Commit

Permalink
added integration tests execution in maven
Browse files Browse the repository at this point in the history
  • Loading branch information
candreac committed Nov 12, 2023
1 parent 650710f commit b498ed1
Show file tree
Hide file tree
Showing 12 changed files with 39,390 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
<groupId>io.quarkiverse.amazonservices</groupId>
<artifactId>quarkus-amazon-s3</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>url-connection-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package it.gov.pagopa.atmlayer.service.model.integrationtests;

import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
import io.quarkus.test.junit.QuarkusTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.DockerComposeContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;

import java.io.File;
import java.util.Collections;
import java.util.Map;

@QuarkusTest
public class EnviromentTestServicesResource {
private static final Logger LOGGER = LoggerFactory.getLogger(EnviromentTestServicesResource.class);

public static class DockerCompose implements QuarkusTestResourceLifecycleManager {
private DockerComposeContainer<?> dockerComposeContainer;

@Override
public Map<String, String> start() {

dockerComposeContainer = new DockerComposeContainer<>(new File("src/test/resources/integration-test/docker-compose.yml"))
.withExposedService("minio", 9000)
.withExposedService("postgres-int", 5432)
.withExposedService("mockoon", 3000);

dockerComposeContainer.withLogConsumer("minio", new Slf4jLogConsumer(LOGGER).withPrefix("minio"));
dockerComposeContainer.withLogConsumer("postgres-int", new Slf4jLogConsumer(LOGGER).withPrefix("postgres-int"));
dockerComposeContainer.withLogConsumer("mockoon", new Slf4jLogConsumer(LOGGER).withPrefix("mockoon"));

dockerComposeContainer.start();

return Collections.emptyMap();
}

@Override
public void stop() {
if (dockerComposeContainer != null) {
dockerComposeContainer.stop();
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package it.gov.pagopa.atmlayer.service.model.integrationtests;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.Testcontainers;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy;
import org.testcontainers.images.builder.ImageFromDockerfile;

import java.nio.file.Paths;
import java.time.Duration;

import static org.junit.Assert.assertTrue;

@QuarkusTest
@QuarkusTestResource(value = EnviromentTestServicesResource.DockerCompose.class, restrictToAnnotatedClass = true)
@Slf4j
public class IntegrationTests {

private static final GenericContainer<?> NEWMAN = new GenericContainer<>(new ImageFromDockerfile()
.withDockerfile(Paths.get("src/test/resources/integration-test/Dockerfile-postman")))
.withFileSystemBind("src/test/resources/integration-test/output", "/output", BindMode.READ_WRITE)
.withAccessToHost(true)
.withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofSeconds(120)));

@BeforeAll
static void exposeTestPort() {
Testcontainers.exposeHostPorts(8086);
}

@Test
void executePostmanCollectionWithNewmann() {
NEWMAN.start();
log.info(NEWMAN.getLogs());
assertTrue(NEWMAN.getCurrentContainerInfo().getState().getExitCodeLong() == 0);
}

}
32 changes: 29 additions & 3 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
quarkus.http.test-port=8086
quarkus.log.category."org.jboss.resteasy.reactive.client.logging".level=${REST_CLIENT_LOG_LEVEL:INFO}
quarkus.datasource.db-kind=${MODEL_DB_TYPE:postgresql}
quarkus.datasource.username=${MODEL_DB_USERNAME:user}
quarkus.datasource.password=${MODEL_DB_PASSWORD:password}
quarkus.datasource.reactive.url=${MODEL_DB_URL:postgresql://localhost:5434/test}
quarkus.hibernate-orm.database.generation=${MODEL_DB_SCHEMA_UPDATE_TYPE:drop-and-create}
quarkus.log.console.json=false
quarkus.console.color=true
quarkus.smallrye-openapi.auto-add-server=true
quarkus.s3.endpoint-override=http://127.0.0.1:9100
quarkus.s3.aws.credentials.type=static
quarkus.s3.aws.credentials.static-provider.access-key-id=${OBJECT_STORE_ACCESS_KEY_ID:key}
quarkus.s3.aws.credentials.static-provider.secret-access-key=${OBJECT_STORE_ACCESS_KEY_SECRET:password}
quarkus.s3.aws.region=${MODEL_OBJECT_STORE_REGION:eu-south-1}
quarkus.devservices.enabled=false
quarkus.log.category."software.amazon.awssdk.services.s3".level=DEBUG
quarkus.hibernate-orm.physical-naming-strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
quarkus.rest-client.process-deploy.url=http://localhost:3000
###################
# OBJECT STORE
###################
object-store.type=${MODEL_OBJECT_STORE_TYPE:AWS_S3}
object-store.bucket.name=${MODEL_OBJECT_STORE_BUCKET_NAME:pagopa-dev-atm-layer-s3-model}
object-store.bpmn.path-template=${MODEL_OBJECT_STORE_BPMN_TEMPLATE_PATH:/BPMN/files/UUID/[uuid]/VERSION/[version]}
object-store.bucket.region=${MODEL_OBJECT_STORE_REGION:eu-south-1}
object-store.bucket.name=${MODEL_OBJECT_STORE_BUCKET_NAME:bucket}
object-store.bucket.region=${MODEL_OBJECT_STORE_REGION:eu-south-1}
object-store.bucket.access-key=${OBJECT_STORE_ACCESS_KEY_ID:key}
object-store.bucket.secret-key=${OBJECT_STORE_ACCESS_KEY_SECRET:password}
object-store.bucket.endpoint-override=http://127.0.0.1:9100
object-store.bpmn.path-template=${MODEL_OBJECT_STORE_BPMN_TEMPLATE_PATH:BPMN/files/UUID/[uuid]/VERSION/[version]}
quarkus.resteay-reactive.input-buffer-size=10000

14 changes: 14 additions & 0 deletions src/test/resources/integration-test/Dockerfile-mockoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:14-slim


# Copia il file JSON Mockoon all'interno del container
COPY /integration-test/mockoon/*.json /data

# Installa Mockoon CLI globalmente
RUN npm install -g @mockoon/cli

# Espone la porta su cui Mockoon ascolterà le richieste
EXPOSE 3000

# Esegui Mockoon CLI all'avvio del container
CMD ["mockoon-cli", "start", "-d", "/data", "-p", "3000"]
16 changes: 16 additions & 0 deletions src/test/resources/integration-test/Dockerfile-postman
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:21

COPY /postman /postman
COPY /run-postman.sh /postman

# Installa Newman, il runner di Postman
RUN npm install -g newman
RUN npm install -g newman-reporter-htmlextra

RUN chmod 777 /postman/run-postman.sh \
&& chown -R 1001 /postman/run-postman.sh \
&& chmod -R "g+rwX" /postman/run-postman.sh \
&& chown -R 1001:root /postman/run-postman.sh
# Comando per eseguire la collection Postman
USER 1001
CMD ["/bin/bash","-c","./postman/run-postman.sh"]
37 changes: 37 additions & 0 deletions src/test/resources/integration-test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: '3'

services:
postgres-int:
image: postgres:latest
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: test
ports:
- "5434:5432"
minio:
image: minio/minio
ports:
- "9100:9000"
- "9110:9001"
environment:
MINIO_ACCESS_KEY: key
MINIO_SECRET_KEY: password
command: server /data --console-address ":9001"
createbuckets:
image: minio/mc
depends_on:
- minio
entrypoint: >
/bin/sh -c "
/usr/bin/mc alias set myminio http://minio:9000 key password;
/usr/bin/mc mb myminio/bucket;
/usr/bin/mc policy set public myminio/bucket;
exit 0;
"
mockoon:
ports:
- "3000:3000"
build:
context: ../
dockerfile: ./integration-test/Dockerfile-mockoon
79 changes: 79 additions & 0 deletions src/test/resources/integration-test/mockoon/process-mock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"uuid": "81b580dd-bffd-4b2c-a373-92b8a73782ee",
"lastMigration": 29,
"name": "Atm layer",
"endpointPrefix": "",
"latency": 0,
"port": 3001,
"hostname": "",
"folders": [],
"routes": [
{
"uuid": "5d1ce034-b37a-4556-9c83-2e5ebdc613dd",
"type": "http",
"documentation": "",
"method": "post",
"endpoint": "api/v1/processes/deploy",
"responses": [
{
"uuid": "e8185899-7682-4525-a89f-251c4e6a2392",
"body": "{\n \"links\": [\n {\n \"method\": \"GET\",\n \"href\": \"http://pagopa-dev-atm-layer-alb-ext-1183954062.eu-south-1.elb.amazonaws.com/engine-rest/deployment/ffb8aa67-7708-11ee-b684-b266d188abc5\",\n \"rel\": \"self\"\n }\n ],\n \"id\": \"ffb8aa67-7708-11ee-b684-b266d188abc5\",\n \"name\": \"\",\n \"source\": null,\n \"deploymentTime\": \"2023-10-30T09:45:02.880+0000\",\n \"tenantId\": \"ttenant\",\n \"deployedProcessDefinitions\": {\n \"demo11_06:2:ffbe9dda-7708-11ee-b684-b266d188abc5\": {\n \"id\": \"demo11_06:2:ffbe9dda-7708-11ee-b684-b266d188abc5\",\n \"key\": \"1699262752968West Anabel\",\n \"category\": \"http://bpmn.io/schema/bpmn\",\n \"description\": \"description\",\n \"name\": null,\n \"version\": 2,\n \"resource\": \"DEMO_11_06.bpmn\",\n \"deploymentId\": \"ffb8aa67-7708-11ee-b684-b266d188abc5\",\n \"diagram\": null,\n \"suspended\": false,\n \"tenantId\": \"ttenant\",\n \"versionTag\": null,\n \"historyTimeToLive\": 180,\n \"startableInTasklist\": true\n }\n },\n \"deployedCaseDefinitions\": null,\n \"deployedDecisionDefinitions\": null,\n \"deployedDecisionRequirementsDefinitions\": null\n}",
"latency": 0,
"statusCode": 200,
"label": "",
"headers": [],
"bodyType": "INLINE",
"filePath": "",
"databucketID": "",
"sendFileAsBody": false,
"rules": [],
"rulesOperator": "OR",
"disableTemplating": false,
"fallbackTo404": false,
"default": true,
"crudKey": "id"
}
],
"enabled": true,
"responseMode": null
}
],
"rootChildren": [
{
"type": "route",
"uuid": "5d1ce034-b37a-4556-9c83-2e5ebdc613dd"
}
],
"proxyMode": false,
"proxyHost": "",
"proxyRemovePrefix": false,
"tlsOptions": {
"enabled": false,
"type": "CERT",
"pfxPath": "",
"certPath": "",
"keyPath": "",
"caPath": "",
"passphrase": ""
},
"cors": true,
"headers": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"proxyReqHeaders": [
{
"key": "",
"value": ""
}
],
"proxyResHeaders": [
{
"key": "",
"value": ""
}
],
"data": []
}
Loading

0 comments on commit b498ed1

Please sign in to comment.