diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f285a29..ca729cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,20 +3,59 @@ name: "dropwizard-ci-pipeline" on: push: branches: - - main + - main # Trigger on push to main + pull_request: + branches: + - main # Trigger on PRs targeting main + jobs: build-and-test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 + - name: Install Java - uses: actions/setup-java@v1 + uses: actions/setup-java@v4 with: - java-version: 11 + distribution: 'temurin' + java-version: '11' - name: Build with Gradle run: | chmod +x gradlew ./gradlew build -x test + - name: Run tests - run: ./gradlew test \ No newline at end of file + run: ./gradlew test + + system-test: + runs-on: ubuntu-latest + needs: build-and-test + steps: + - uses: actions/checkout@v4 + + - name: Run Docker Compose + run: docker compose up -d --build + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install test dependencies + run: pip install pytest requests + + - name: Wait for server + run: | + for i in $(seq 1 30); do + curl -s http://localhost:8085/hello-world && exit 0 + sleep 2 + done + echo "Server never came up" && exit 1 + + - name: Run system tests + run: pytest + + - name: Bring server down + if: always() + run: docker compose down \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e6499c5..b2a6ae2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ WORKDIR /home/gradle/src RUN gradle shadowJar # Get the Java version 8 image -FROM openjdk:11 +FROM eclipse-temurin:11 WORKDIR /app COPY --from=build /home/gradle/src/build/libs/hello-friends-1.0-SNAPSHOT.jar /app diff --git a/docker-compose.yml b/docker-compose.yml index 6c76a4c..236bcb7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3' + services: # just a random name. oh-my-server: diff --git a/src/main/java/com/example/helloworld/HelloWorldApplication.java b/src/main/java/com/example/helloworld/HelloWorldApplication.java index 92a60b6..4e726a7 100644 --- a/src/main/java/com/example/helloworld/HelloWorldApplication.java +++ b/src/main/java/com/example/helloworld/HelloWorldApplication.java @@ -6,6 +6,9 @@ import io.dropwizard.setup.Bootstrap; import io.dropwizard.setup.Environment; +// Modifying main so that I can commit something for the lab exercise. +// This will be deleted later. + public class HelloWorldApplication extends Application { public static void main(String[] args) throws Exception { new HelloWorldApplication().run(args); diff --git a/src/test/pytest/Test_system.py b/src/test/pytest/Test_system.py new file mode 100644 index 0000000..54ee408 --- /dev/null +++ b/src/test/pytest/Test_system.py @@ -0,0 +1,17 @@ +import json +import requests + +# Verifies that the server correctly returns a status code of 404 (Not Found) +# in the response's JSON payload. +def test_code(): + response=requests.get("http://localhost:8085") + json_response=response.json() + assert(json_response["code"]==404) + + +# Validates that the server returns the expected error message in the "message" +# field of the JSON response. +def test_message(): + response=requests.get("http://localhost:8085") + json_response=response.json() + assert(json_response["message"]=="HTTP 404 Not Found") \ No newline at end of file