I have a Containerized application which uses other containerized apps in environment to consume REST apis.After performing the business logic, it creates file and send it to a remote server using sftp.
Prod Config file looks like this:
app1:
api:
url: http://app1:8090
app2:
api:
url: http://app2:9339
app3:
api:
url: http://app3:8080
remote:
hostname: test.abc.org
port: 22
To create the integration tests, I can think of two options:-
1. Using TestContainer for Each dependency
Create separate test container for containerized apps which are exposing apis as well as remote host for file transfer. Wiremock Json mapping files will be passed as volumes in docker-compose and need to update the application-test.yml for test containers reference to localhost.
DockerComposeContainer CONTAINER = new DockerComposeContainer(new File("docker-compose.yml"))
.withExposedService("app1", 2929, waitStrategy).withLogConsumer("app1",logConsumer)
.withExposedService("app2", 8065, waitStrategy).withLogConsumer("app2",logConsumer)
.withExposedService("app3", 8090, waitStrategy).withLogConsumer("app23",logConsumer)
.withExposedService("sshserver_1", 2222, waitStrategy).withLogConsumer("sshserver_1",logConsumer)
.withLocalCompose(true);
docker-compose.yml:
version: "3.8"
services:
app3:
image: rodolpheche/wiremock:2.25.1
ports:
- "8090:8090"
command: --port 8090 --global-response-templating
volumes:
- ./mocks/app3-api:/home/wiremock
app2:
image: rodolpheche/wiremock:2.25.1
ports:
- "8065:8065"
command: --port 8065 --global-response-templating
volumes:
- ./mocks/app2-api:/home/wiremock
sshserver:
build:
context: mocks/remote
ports:
- "2222:2222"
volumes:
- ./mocks/remote/files:/files
app1:
image: rodolpheche/wiremock:2.25.1
ports:
- "2929:2929"
command: --port 2929 --global-response-templating
volumes:
- ./mocks/app1-api:/home/wiremock
2. Create single Wiremock Server for All APIs and Separate TestContainer for Remote Server
create single wiremock server by passing all mapping directories to wiremock configuration object and point all api server in test yml to localhost wiremock port. Although still in this case I belive I have to create a testcontainer for ssh remote server as I have to test file transfer.
WireMockConfiguration configuration = WireMockConfiguration.options()
.port(8085)
.usingFilesUnderDirectory("./mocks/app1/files") // Load mappings from "mappings/api1"
.usingFilesUnderDirectory("./mocks/app2/files")
.usingFilesUnderDirectory("./mocks/app3/files") // Load mappings from "mappings/api1"
// Start WireMock server with the configured options
wireMockServer = new WireMockServer(configuration);
wireMockServer.start();
I am seeking suggestions on below:
-
While both seems equivalent to me in terms of functioning, I want to understand if there’s a significant difference in both approaches that can impact testing or performance.
-
which one is recommended ?
9