Skip to content

Commit

Permalink
BP-008 Fixed the cyclomatic dependency on the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMachadoVasconcelos committed Oct 12, 2024
1 parent 448cb2e commit 0f38f77
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 38 deletions.
72 changes: 46 additions & 26 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/com/ead/payments/BaseEvent.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
1 change: 0 additions & 1 deletion src/main/java/com/ead/payments/orders/OrderAggregate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
);
}
}

0 comments on commit 0f38f77

Please sign in to comment.