From 0f38f7745e6f051586faeea9019b694f0063b212 Mon Sep 17 00:00:00 2001 From: Daniel Machado Vasconcelos Date: Sat, 12 Oct 2024 22:37:43 +0200 Subject: [PATCH] BP-008 Fixed the cyclomatic dependency on the tests --- .github/workflows/gradle.yml | 72 ++++++++++++------- README.md | 2 +- src/main/java/com/ead/payments/BaseEvent.java | 8 +-- .../ead/payments/orders/OrderAggregate.java | 1 - .../orders/PlaceOrdersControllerTest.java | 8 ++- 5 files changed, 53 insertions(+), 38 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 94ecb06..0995849 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -15,64 +15,84 @@ permissions: issues: read jobs: + setup: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set up JDK 21 + uses: actions/setup-java@v2 + with: + java-version: '21' + distribution: 'temurin' + cache: gradle + build: runs-on: ubuntu-latest + needs: setup + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Build with Gradle + uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7 + with: + arguments: clean build -Djava.compiler.args="--enable-preview" --info --stacktrace + start-docker: + runs-on: ubuntu-latest + needs: build services: - # Ensure docker-compose dependencies are started postgres: image: postgres:latest ports: - - 5432:5432 # PostgreSQL port + - 5432:5432 kafka: image: bitnami/kafka:latest ports: - - 9092:9092 # Kafka port + - 9092:9092 steps: - # Check Docker Compose Version - - name: Check Docker Compose Version - run: docker compose --version - - # Checkout the repository - name: Checkout Repository uses: actions/checkout@v3 - # Set up JDK 21 - - name: Set up JDK 21 - uses: actions/setup-java@v2 - with: - java-version: '21' - distribution: 'temurin' - cache: gradle - - # Start Docker Compose services - name: Spin up Docker Compose resources run: docker compose up -d timeout-minutes: 5 - # Build and test with Gradle - - name: Build with Gradle + test: + runs-on: ubuntu-latest + needs: start-docker + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Run Tests with Gradle uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7 with: - arguments: clean build -Djava.compiler.args="--enable-preview" --info --stacktrace + arguments: test -Djava.compiler.args="--enable-preview" --info --stacktrace - # Upload test results to GitHub - name: Publish Test Results uses: EnricoMi/publish-unit-test-result-action@v2 if: always() with: - files: '**/build/test-results/test/*.xml' # Make sure Gradle produces JUnit-style XML test reports + files: '**/build/test-results/test/*.xml' - # Archive Test Reports as Artifacts - name: Upload Test Reports if: always() uses: actions/upload-artifact@v3 with: name: Test Reports - path: '**/build/reports/tests/test' # Upload HTML test reports + path: '**/build/reports/tests/test' + + shutdown-docker: + runs-on: ubuntu-latest + needs: test + steps: + - name: Checkout Repository + uses: actions/checkout@v3 - # Clean up Docker Compose resources - name: Clean up Docker Compose - run: docker compose down + run: docker compose down \ No newline at end of file diff --git a/README.md b/README.md index 586d862..6f690dc 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ curl --location --request POST 'localhost:5000/v1/orders' \ Or access the database using the following command: ```bash -//PGPASSWORD=password psql -U user -h localhost orders +PGPASSWORD=password psql -U user -h localhost orders ``` ### Kafka diff --git a/src/main/java/com/ead/payments/BaseEvent.java b/src/main/java/com/ead/payments/BaseEvent.java index 4d10a3a..99ba6d8 100644 --- a/src/main/java/com/ead/payments/BaseEvent.java +++ b/src/main/java/com/ead/payments/BaseEvent.java @@ -1,7 +1,5 @@ package com.ead.payments; -import com.ead.payments.orders.OrderPlacedEvent; -import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeName; import lombok.AllArgsConstructor; @@ -13,11 +11,7 @@ @SuperBuilder @AllArgsConstructor @NoArgsConstructor -@JsonTypeName(value = "type") -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") -@JsonSubTypes({ - @JsonSubTypes.Type(value = OrderPlacedEvent.class, name = "order_placed"), -}) +@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "type") public abstract class BaseEvent extends Message { private int version; } diff --git a/src/main/java/com/ead/payments/orders/OrderAggregate.java b/src/main/java/com/ead/payments/orders/OrderAggregate.java index bb06938..342b514 100644 --- a/src/main/java/com/ead/payments/orders/OrderAggregate.java +++ b/src/main/java/com/ead/payments/orders/OrderAggregate.java @@ -7,7 +7,6 @@ import com.google.common.base.Preconditions; import lombok.Data; import lombok.NoArgsConstructor; -import lombok.With; import org.springframework.security.authorization.method.AuthorizeReturnObject; @Data diff --git a/src/test/java/com/ead/payments/orders/PlaceOrdersControllerTest.java b/src/test/java/com/ead/payments/orders/PlaceOrdersControllerTest.java index bebb935..4f10e47 100644 --- a/src/test/java/com/ead/payments/orders/PlaceOrdersControllerTest.java +++ b/src/test/java/com/ead/payments/orders/PlaceOrdersControllerTest.java @@ -11,8 +11,6 @@ import com.ead.payments.SpringBootIntegrationTest; import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.Set; -import java.util.UUID; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -44,6 +42,10 @@ void shouldReturn201WhenPlaceOrder() throws Exception { // then: the response is 201 response.andDo(print()) .andExpect(status().isCreated()) - .andExpect(jsonPath("$.id", is(notNullValue()))); + .andExpectAll( + jsonPath("$.id", is(notNullValue())), + jsonPath("$.currency", is("USD")), + jsonPath("$.amount", is(100)) + ); } } \ No newline at end of file