Skip to content

Conversation

@testower
Copy link
Collaborator

@testower testower commented Mar 3, 2025

Closes #102 and #117

@testower testower force-pushed the feature/api-module branch from 4da4b2a to 782a489 Compare May 5, 2025 14:20
@testower testower force-pushed the feature/api-module branch from 73b727c to 6008717 Compare May 9, 2025 21:16
@testower testower force-pushed the feature/api-module branch from e776396 to a13dfc0 Compare May 10, 2025 10:21
google-labs-jules bot and others added 4 commits May 27, 2025 20:34
Extends the OpenAPI schema to include a `systemErrors` field in the `GbfsFile` type. This field is an array of `SystemError` objects, each with an `error` code and a `message`.

This change introduces two distinct internal SystemError types:
- `org.entur.gbfs.validator.loader.SystemError` for file loading issues (e.g., file not found, HTTP connection errors).
- `org.entur.gbfs.validation.model.SystemError` for JSON parsing or stream reading issues within the validator.

Modifications were made to:
- `Loader.java`: To capture loading exceptions and populate them in `LoadedFile.systemErrors`.
- `GbfsJsonValidator.java`: To capture parsing/reading exceptions and populate them in `FileValidationResult.systemErrors`.
- `ValidateApiDelegateHandler.java`: To map both internal `SystemError` types to the OpenAPI `SystemError` model and combine them in the final API response for each file.

Unit tests across all affected modules (`gbfs-validator-java-loader`, `gbfs-validator-java`, `gbfs-validator-java-api`) have been added and updated to verify this new functionality and ensure correct error reporting.
This commit addresses compilation failures that arose after introducing
the systemErrors field to FileValidationResult and modifying related
method signatures.

Fixes include:
- Updating FileValidationResult constructor calls in FileValidator.java
  to include an empty list for systemErrors.
- Ensuring the schema argument passed to FileValidationResult constructors
  in GbfsJsonValidator.java is consistently a String (using .toString()
  on Schema objects).
- Correcting the arguments for the FileValidator.validate call in
  GbfsJsonValidator.java by removing an extraneous originalContent
  argument that did not match the method signature.
This commit addresses several issues that were causing the build to fail:

1.  **Missing Mockito Dependency**: Added `mockito-core` and `mockito-junit-jupiter` (version 5.12.0) to `gbfs-validator-java/pom.xml` to resolve `package org.mockito does not exist` errors during test compilation.

2.  **Constructor Mismatch in ValidationResultTest**: Updated the constructor call for `FileValidationResult` in `ValidationResultTest.java` to include the missing 9th argument (a list of system errors), resolving a compilation error. An empty list is passed for this argument.

3.  **JUnit Test Discovery Failure**:
    *   Added `org.junit.platform:junit-platform-launcher` as a test dependency.
    *   Configured the `maven-surefire-plugin` with `org.junit.platform:junit-platform-surefire-provider` to ensure JUnit 5 tests are discovered and executed correctly.

With these changes, the project now compiles successfully, and all 15 tests in `gbfs-validator-java` pass.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
google-labs-jules bot and others added 10 commits May 28, 2025 09:20
This change adds support for specifying authentication details when fetching GBFS files, as defined in the OpenAPI specification. The loader can now handle Basic Authentication, Bearer Token Authentication, and OAuth 2.0 Client Credentials Grant.

Key changes:

- Added authentication models (`BasicAuth`, `BearerTokenAuth`, `OAuthClientCredentialsGrantAuth`) to the `gbfs-validator-java-loader` module.
- Modified `Loader.java` to accept an `Authentication` object and include appropriate `Authorization` headers in HTTP requests. For OAuth2, it handles fetching the token from the specified token URL.
- Integrated these changes into the `gbfs-validator-java-api` module by updating `ValidateApiDelegateHandler.java` to map API authentication models to the loader's authentication models.
- Ensured backward compatibility by providing an overloaded `load` method in `Loader.java` that defaults to no authentication.

Testing:

- I added comprehensive unit tests for `Loader.java` in `gbfs-validator-java-loader` using WireMock. These tests cover successful authentication for all supported methods, as well as error scenarios like incorrect credentials and token fetch failures.
- I added integration tests in `gbfs-validator-java-api` using `MockMvc` and WireMock. These tests verify the end-to-end authentication flow, from the API request to the `Loader` making authenticated HTTP calls. They ensure that the `/validate` endpoint correctly processes authentication details and that the system behaves as expected under various authentication scenarios.

The tests verify that:
- Files are fetched successfully with valid authentication credentials for each supported method.
- Appropriate `Authorization` headers are added to requests.
- OAuth2 token acquisition works correctly.
- System errors are reported for authentication failures (e.g., HTTP 401 errors due to bad credentials or token issues) rather than causing the validation process to crash.
feat: Implement authentication for fetching GBFS files
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 6, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
23.7% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

google-labs-jules bot and others added 4 commits June 17, 2025 20:08
I configured the spring-boot-maven-plugin in `gbfs-validator-java-api/pom.xml`
to build an executable fat jar. This allows the API module to be run as a
standalone application.

I also made the build process more robust by:
- Adding integrity check for downloaded schema zip in `gbfs-validator-java/bin/gbfs-download-extract.sh`.
- Fixing POM errors in `gbfs-validator-java-api/pom.xml` by removing duplicate dependencies and adding missing versions.

I've verified that the generated fat jar includes all necessary dependencies
and the application starts successfully.
feat: Create fat jar for gbfs-validator-java-api
@testower testower marked this pull request as ready for review October 3, 2025 09:50
@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 3, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot
20.7% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@testower testower merged commit 6b4102e into master Oct 3, 2025
4 of 5 checks passed
@testower testower deleted the feature/api-module branch October 3, 2025 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Implement API

3 participants