diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d56a28c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,23 @@ +name: CI + +on: + push: + branches: [main, master] + pull_request: + +jobs: + build: + name: build and test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: "17" + cache: maven + # EnergyServiceIntegrationTest calls the live NESO Carbon Intensity API. + # It is a useful thing to run by hand and a bad thing to gate a merge on: + # an outage upstream would fail a build that has nothing wrong with it. + # `mvn test` locally still runs everything. + - run: ./mvnw -B --no-transfer-progress verify -DexcludedGroups=integration diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a66add1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Jakub Kierznowski + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 087b534..3a80fa0 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ EV charging decision backend that analyzes UK grid carbon-intensity data and recommends the cleanest charging window in the next 48 hours.

+

+ CI +

+

GitHub Java 17 @@ -329,18 +333,24 @@ This simplicity is a strength for a focused API utility service. ## Testing -The Maven configuration includes Spring Boot test support. +18 tests, run on every push by [CI](.github/workflows/ci.yml). -Run tests with: +| Class | Covers | Tests | +| --- | --- | --- | +| `ChargingServiceTest` | the sliding window over half-hourly slots, including ties and short horizons | 10 | +| `EnergyServiceTest` | daily mix aggregation with a mocked client | 6 | +| `CarChargingApplicationTests` | the Spring context loads | 1 | +| `EnergyServiceIntegrationTest` | the real NESO API, end to end | 1 | ```bash -mvn test +mvn test # everything +mvn test -DexcludedGroups=integration # what CI runs ``` -The repository structure also indicates service-level tests such as: -- `ChargingServiceTest` -- `EnergyServiceTest` -- `EnergyServiceIntegrationTest` +The last one is tagged `integration` and left out of CI on purpose. It calls +the live NESO Carbon Intensity API, so an outage upstream would fail a build +that has nothing wrong with it. Worth running by hand when the client or the +response shape changes. --- diff --git a/mvnw b/mvnw old mode 100644 new mode 100755 diff --git a/src/test/java/org/qualv13/carcharging/service/EnergyServiceIntegrationTest.java b/src/test/java/org/qualv13/carcharging/service/EnergyServiceIntegrationTest.java index ccb523e..1e47d4f 100644 --- a/src/test/java/org/qualv13/carcharging/service/EnergyServiceIntegrationTest.java +++ b/src/test/java/org/qualv13/carcharging/service/EnergyServiceIntegrationTest.java @@ -1,6 +1,7 @@ package org.qualv13.carcharging.service; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.qualv13.carcharging.client.CarbonIntensityClient; import org.qualv13.carcharging.model.dto.ChargingWindowDto; @@ -9,6 +10,10 @@ import java.util.List; +// Talks to the live NESO Carbon Intensity API, so it is excluded from CI: +// an outage upstream would fail a build that has nothing wrong with it. +// `mvn test` runs it; `mvn test -DexcludedGroups=integration` does not. +@Tag("integration") class EnergyServiceIntegrationTest { @Test