Skip to content

Commit f69464e

Browse files
authored
add integration tests (#2489)
* add integration tests * cleanup
1 parent 6423184 commit f69464e

9 files changed

Lines changed: 1835 additions & 1 deletion

.github/workflows/auth-integration-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
run: |
3131
# Create test results directory
3232
mkdir -p docker/auth-test/test-results
33-
chmod 777 docker/auth-test/test-results
33+
chmod 755 docker/auth-test/test-results
3434
3535
- name: Start infrastructure
3636
working-directory: docker/auth-test
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Integration Tests
2+
3+
on:
4+
push:
5+
branches: [master, webapi-3.0]
6+
pull_request:
7+
branches: [master, webapi-3.0]
8+
workflow_dispatch:
9+
10+
env:
11+
DOCKER_BUILDKIT: 1
12+
COMPOSE_DOCKER_CLI_BUILD: 1
13+
14+
jobs:
15+
integration-test:
16+
name: CDM Integration Tests
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 45
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Build WebAPI Docker image
25+
working-directory: docker/integration-test
26+
run: |
27+
docker compose build webapi
28+
29+
- name: Set up test environment
30+
run: |
31+
# Create test results directory
32+
mkdir -p docker/integration-test/test-results
33+
chmod 755 docker/integration-test/test-results
34+
35+
- name: Start infrastructure
36+
working-directory: docker/integration-test
37+
run: |
38+
docker compose up -d postgres cdm-db mock-oauth2
39+
40+
echo "Waiting for PostgreSQL to be ready..."
41+
timeout 60 bash -c 'until docker compose exec -T postgres pg_isready -U postgres > /dev/null 2>&1; do sleep 2; done'
42+
echo "PostgreSQL is ready!"
43+
44+
echo "Waiting for CDM database to be ready..."
45+
timeout 60 bash -c 'until docker compose exec -T cdm-db pg_isready -U postgres > /dev/null 2>&1; do sleep 2; done'
46+
echo "CDM database is ready!"
47+
48+
- name: Start WebAPI
49+
working-directory: docker/integration-test
50+
run: |
51+
docker compose up -d webapi
52+
53+
echo "Waiting for WebAPI to be healthy..."
54+
timeout 300 bash -c 'until curl -sf http://localhost:18080/WebAPI/info > /dev/null 2>&1; do sleep 10; echo "Waiting for WebAPI..."; done'
55+
echo "WebAPI is ready!"
56+
57+
- name: Setup test data
58+
working-directory: docker/integration-test
59+
run: |
60+
docker compose up db-setup
61+
echo "Test data created!"
62+
63+
- name: Run Newman tests
64+
working-directory: docker/integration-test
65+
run: |
66+
# Run tests using Newman docker container
67+
docker compose up newman
68+
69+
# Check test results
70+
if [ -f test-results/integration-test-results.xml ]; then
71+
echo "Test results generated successfully"
72+
else
73+
echo "Warning: Test results file not found"
74+
fi
75+
76+
- name: Upload test results
77+
uses: actions/upload-artifact@v4
78+
if: always()
79+
with:
80+
name: integration-test-results
81+
path: docker/integration-test/test-results/
82+
retention-days: 30
83+
84+
- name: Publish test results
85+
uses: mikepenz/action-junit-report@v4
86+
if: always()
87+
with:
88+
report_paths: 'docker/integration-test/test-results/*.xml'
89+
check_name: 'Integration Test Results'
90+
fail_on_failure: true
91+
92+
- name: Show logs on failure
93+
if: failure()
94+
working-directory: docker/integration-test
95+
run: |
96+
echo "=== WebAPI Logs ==="
97+
docker compose logs webapi --tail=200
98+
echo ""
99+
echo "=== CDM Database Logs ==="
100+
docker compose logs cdm-db --tail=50
101+
echo ""
102+
echo "=== mock-oauth2 Logs ==="
103+
docker compose logs mock-oauth2 --tail=100
104+
echo ""
105+
echo "=== Newman Logs ==="
106+
docker compose logs newman --tail=100
107+
echo ""
108+
echo "=== DB Setup Logs ==="
109+
docker compose logs db-setup --tail=50
110+
111+
- name: Cleanup
112+
if: always()
113+
working-directory: docker/integration-test
114+
run: |
115+
docker compose down -v --remove-orphans
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Integration Test Environment Configuration
2+
# Copy to .env and modify as needed
3+
4+
# Database credentials
5+
POSTGRES_PASSWORD=postgres
6+
CDM_PASSWORD=mypass
7+
8+
# OAuth2 configuration
9+
OIDC_CLIENT_SECRET=webapi-secret
10+
11+
# Test user credentials (must match bcrypt hashes in setup-test-data.sql)
12+
TEST_USER_PASSWORD=testpass123

docker/integration-test/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Test results (generated during test runs)
2+
test-results/*.xml
3+
test-results/*.json
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
services:
2+
postgres:
3+
image: postgres:15-alpine
4+
container_name: webapi-postgres
5+
environment:
6+
POSTGRES_USER: postgres
7+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
8+
POSTGRES_DB: ohdsi
9+
healthcheck:
10+
test: ["CMD-SHELL", "pg_isready -U postgres"]
11+
interval: 5s
12+
timeout: 5s
13+
retries: 10
14+
networks:
15+
- webapi-network
16+
17+
cdm-db:
18+
image: ohdsi/broadsea-atlasdb:2.3.0
19+
container_name: cdm-db
20+
healthcheck:
21+
test: ["CMD-SHELL", "pg_isready -U postgres"]
22+
interval: 5s
23+
timeout: 5s
24+
retries: 10
25+
networks:
26+
- webapi-network
27+
28+
cdm-db-debug:
29+
image: ohdsi/broadsea-atlasdb:2.3.0
30+
container_name: cdm-db-debug
31+
profiles: ["debug"]
32+
healthcheck:
33+
test: ["CMD-SHELL", "pg_isready -U postgres"]
34+
interval: 5s
35+
timeout: 5s
36+
retries: 10
37+
ports:
38+
- "5433:5432"
39+
networks:
40+
- webapi-network
41+
42+
mock-oauth2:
43+
image: ghcr.io/navikt/mock-oauth2-server:2.1.10
44+
container_name: mock-oauth2
45+
environment:
46+
- SERVER_PORT=9090
47+
- JSON_CONFIG={"interactiveLogin":true,"httpServer":"NettyWrapper","tokenCallbacks":[{"issuerId":"default","tokenExpiry":3600,"requestMappings":[{"requestParam":"grant_type","match":"*","claims":{"sub":"testuser","email":"testuser@example.com","name":"Test User"}}]}]}
48+
ports:
49+
- "9090:9090"
50+
networks:
51+
- webapi-network
52+
53+
webapi:
54+
build:
55+
context: ../..
56+
dockerfile: Dockerfile
57+
container_name: webapi
58+
restart: on-failure:3
59+
depends_on:
60+
postgres:
61+
condition: service_healthy
62+
cdm-db:
63+
condition: service_healthy
64+
mock-oauth2:
65+
condition: service_started
66+
environment:
67+
- SPRING_DATASOURCE_HIKARI_CONNECTIONTIMEOUT=60000
68+
- SPRING_DATASOURCE_HIKARI_INITIALIZATIONFAILTIMEOUT=60000
69+
- DATASOURCE_URL=jdbc:postgresql://postgres:5432/ohdsi
70+
- DATASOURCE_USERNAME=postgres
71+
- DATASOURCE_PASSWORD=${POSTGRES_PASSWORD:-postgres}
72+
- DATASOURCE_OHDSI_SCHEMA=webapi
73+
- SPRING_JPA_PROPERTIES_HIBERNATE_DEFAULT_SCHEMA=webapi
74+
- SPRING_BATCH_REPOSITORY_TABLEPREFIX=webapi.BATCH_
75+
- SPRING_FLYWAY_URL=jdbc:postgresql://postgres:5432/ohdsi
76+
- SPRING_FLYWAY_USER=postgres
77+
- SPRING_FLYWAY_PASSWORD=${POSTGRES_PASSWORD:-postgres}
78+
- SPRING_FLYWAY_SCHEMAS=webapi
79+
- SPRING_FLYWAY_PLACEHOLDERS_OHDSISCHEMA=webapi
80+
- SECURITY_PROVIDER=AtlasRegularSecurity
81+
- SECURITY_AUTH_OPENID_ENABLED=true
82+
- SECURITY_AUTH_JDBC_ENABLED=true
83+
- SECURITY_AUTH_LDAP_ENABLED=false
84+
- SECURITY_AUTH_AD_ENABLED=false
85+
- SECURITY_AUTH_CAS_ENABLED=false
86+
- SECURITY_AUTH_WINDOWS_ENABLED=false
87+
- SECURITY_AUTH_KERBEROS_ENABLED=false
88+
- SECURITY_AUTH_GOOGLE_ENABLED=false
89+
- SECURITY_AUTH_FACEBOOK_ENABLED=false
90+
- SECURITY_AUTH_GITHUB_ENABLED=false
91+
- SECURITY_OID_CLIENTID=webapi-client
92+
- SECURITY_OID_APISECRET=${OIDC_CLIENT_SECRET:-webapi-secret}
93+
- SECURITY_OID_URL=http://mock-oauth2:9090/default/.well-known/openid-configuration
94+
- SECURITY_OID_EXTERNALURL=http://localhost:9090/default
95+
- SECURITY_OID_LOGOUTURL=http://localhost:9090/default/endsession
96+
- SECURITY_OID_EXTRASCOPES=profile email
97+
- SECURITY_OAUTH_CALLBACK_UI=http://localhost:18080/WebAPI/#/welcome
98+
- SECURITY_OAUTH_CALLBACK_API=http://localhost:18080/WebAPI/user/oauth/callback
99+
- SECURITY_OAUTH_CALLBACK_URLRESOLVER=query
100+
- SECURITY_DB_DATASOURCE_URL=jdbc:postgresql://postgres:5432/ohdsi
101+
- SECURITY_DB_DATASOURCE_DRIVERCLASSNAME=org.postgresql.Driver
102+
- SECURITY_DB_DATASOURCE_USERNAME=postgres
103+
- SECURITY_DB_DATASOURCE_PASSWORD=${POSTGRES_PASSWORD:-postgres}
104+
- SECURITY_DB_DATASOURCE_SCHEMA=webapi
105+
- SECURITY_DB_DATASOURCE_AUTHENTICATIONQUERY=select password from webapi.users where lower(login) = lower(?)
106+
ports:
107+
- "18080:8080"
108+
healthcheck:
109+
test: ["CMD", "curl", "-f", "http://localhost:8080/WebAPI/info"]
110+
interval: 10s
111+
timeout: 5s
112+
retries: 30
113+
start_period: 120s
114+
networks:
115+
- webapi-network
116+
117+
db-setup:
118+
image: postgres:15-alpine
119+
container_name: db-setup
120+
depends_on:
121+
webapi:
122+
condition: service_healthy
123+
volumes:
124+
- ./setup-test-data.sql:/setup-test-data.sql:ro
125+
environment:
126+
PGPASSWORD: ${POSTGRES_PASSWORD:-postgres}
127+
command: >
128+
psql -h postgres -U postgres -d ohdsi -f /setup-test-data.sql
129+
networks:
130+
- webapi-network
131+
132+
newman:
133+
image: postman/newman:6-alpine
134+
container_name: newman
135+
depends_on:
136+
webapi:
137+
condition: service_healthy
138+
db-setup:
139+
condition: service_completed_successfully
140+
volumes:
141+
- ./postman:/etc/newman
142+
- ./test-results:/results
143+
command:
144+
- run
145+
- /etc/newman/integration-tests.postman_collection.json
146+
- --environment
147+
- /etc/newman/integration-test-env.postman_environment.json
148+
- --reporters
149+
- cli,junit
150+
- --reporter-junit-export
151+
- /results/integration-test-results.xml
152+
- --timeout-request
153+
- "60000"
154+
networks:
155+
- webapi-network
156+
157+
networks:
158+
webapi-network:
159+
driver: bridge
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"id": "webapi-integration-test-env",
3+
"name": "WebAPI Integration Test Environment",
4+
"values": [
5+
{
6+
"key": "base_url",
7+
"value": "http://webapi:8080/WebAPI",
8+
"type": "default",
9+
"enabled": true
10+
},
11+
{
12+
"key": "oidc_url",
13+
"value": "http://mock-oauth2:9090/default",
14+
"type": "default",
15+
"enabled": true
16+
},
17+
{
18+
"key": "oidc_client_id",
19+
"value": "webapi-client",
20+
"type": "default",
21+
"enabled": true
22+
},
23+
{
24+
"key": "oidc_client_secret",
25+
"value": "webapi-secret",
26+
"type": "secret",
27+
"enabled": true
28+
},
29+
{
30+
"key": "jdbc_user_email",
31+
"value": "testuser@example.com",
32+
"type": "default",
33+
"enabled": true
34+
},
35+
{
36+
"key": "jdbc_user_password",
37+
"value": "testpass123",
38+
"type": "secret",
39+
"enabled": true
40+
},
41+
{
42+
"key": "cdm_db_host",
43+
"value": "cdm-db",
44+
"type": "default",
45+
"enabled": true
46+
},
47+
{
48+
"key": "cdm_db_port",
49+
"value": "5432",
50+
"type": "default",
51+
"enabled": true
52+
},
53+
{
54+
"key": "cdm_schema",
55+
"value": "demo_cdm",
56+
"type": "default",
57+
"enabled": true
58+
},
59+
{
60+
"key": "results_schema",
61+
"value": "demo_cdm_results",
62+
"type": "default",
63+
"enabled": true
64+
}
65+
],
66+
"_postman_variable_scope": "environment"
67+
}

0 commit comments

Comments
 (0)