Équipe 3 – Phase 3: Tests unitaires de régression avec JaCoCo - #49
Merged
Conversation
declaration fix
The previous teams created two independent services (backend and testapi) to run the TestAPI functionality, but only backend-team2 was included in the local deployment configuration. This caused the backend to fail when trying to forward API test execution requests to the testapi service. Changes: - Add testapi-team2 service definition (build from testapi-Service/testapi, port 8082, mapped to host 8086) - Fix TEST_API_SERVICE_PORT for backend-team2 (8080 -> 8082) - Add testapi-team2 to backend-team2 depends_on
The testapi microservice crashed with NullPointerException or unhandled ConnectException when: 1. The target API was unreachable (e.g. DNS resolution failure inside Docker container) 2. The request body was missing optional fields like expectedHeaders Changes: - Add try-catch in execute() to handle ConnectException when the target API is unreachable - Add null check for response in getAnswer() to return a structured error message instead of crashing - Add null check in checkResponseHeaders() for missing expectedHeaders field Before: 500 Internal Server Error with raw stack trace After: Structured JSON response with clear error message
The testapi container could not resolve external domain names due to Docker's internal DNS limitations, causing Rest-Assured API calls to fail with ConnectException. Added Google public DNS (8.8.8.8, 8.8.4.4) to testapi-team2 service to enable external API access from within the container.
Updated field annotations to provide meaningful default values in Swagger UI "Try it out", replacing generic "string" placeholders with realistic examples (method: GET, apiUrl: jsonplaceholder endpoint, statusCode: 200). This makes the Swagger interface more user-friendly for testing and demo purposes.
Java and spring boot version conflict solved
Backend crashes with E11000 duplicate key error on taf.roles collection every time it restarts against an existing MongoDB instance. This happens because Spring Data MongoDB attempts to recreate the unique index on the Role.name field at every startup, conflicting with already existing data. Changed auto-index-creation from true to false in application.yml. The index already exists from the first successful startup, so there is no need to recreate it on every restart.
Multiple .env and config files contained hardcoded external IPs (185.133.251.89, 15.133.251.89, 198.7.119.0) from previous semesters' AWS deployments that no longer exist. These have been replaced with localhost for local development. Changes: - testapi-Service/.env: Fix typos (DOKCER→DOCKER, PASWORD→PASSWORD, PERFORMACE→PERFORMANCE), replace external IPs with localhost, update MongoDB credentials to local defaults - testapi-Service/backend/.env: Replace DB_URI and EUREKA_HOST external IPs with localhost - frontend environment.ts: Update apiUrl from external IP to localhost - build.sh: Sync variable references with corrected spelling - Delete .docker_config.env.old (contained stale plaintext credentials)
- Remove 8 duplicate variables from root .env that already exist in backend/.env (DB_URI, DB_NAME, DB_AUTH, EUREKA_HOST/PORT/USERNAME/PASSWORD, GATEWAY_PORT) - Remove 3 dead variables from root .env never referenced by any config (GATEWAY_HOST, PERFORMANCE_DB_NAME, PERFORMANCE_DB_URI) - Remove 5 lines of commented-out MySQL config from backend/.env containing hardcoded credentials, typos (DATABSE, HIBERNETE) - Root .env now only holds Docker build variables; backend/.env holds all Spring Boot runtime variables
Activate the dormant JWT authentication system and integrate it with Swagger UI for the TAF backend. Changes: Rename AuthController.java_ → AuthController.java to enable /api/auth/signup and /api/auth/signin endpoints Configure WebSecurityConfig to enforce authentication: only auth, swagger, actuator, test, and error paths are public; all other requests require a valid JWT Create OpenApiConfig.java with @Securityscheme (Bearer JWT) and server URLs (localhost:8084, gateway, relative) Add @securityrequirement("bearerAuth") to TestApiController, GatlingApiController, TestSeleniumController, TestController Add @Schema examples to SignupRequest and LoginRequest for better Swagger UI defaults Add jaxb-api:2.3.1 dependency to fix javax.xml.bind.DatatypeConverter ClassNotFoundException with jjwt:0.9.1 on Java 17 Add okhttp:4.12.0 version, upgrade maven-compiler-plugin to 3.13.0 Upgrade spring-boot to 3.5.10, add xstream:1.4.21 to fix CVE-2024-47072 Update settings.json for Java Language Server Maven project recognition
…ests d'API - Ajout table des matières avec ancres - Ajout diagramme de flux du test d'API (Frontend → Backend → TestAPI → API cible) - Ajout section complète Tests d'API : utilisation UI, format requête/réponse JSON, 3 assertions (status code, corps JSON, en-têtes), exemple curl - Compression de la section Authentification (JWT + OAuth2 en résumé) - Réorganisation générale : fonctionnalité principale avant authentification
…s contrôleurs - Ajout @nonnull sur les paramètres de méthodes pour supprimer les avertissements - Fichiers modifiés : DevCorsConfiguration, JwtAuthenticationFilter, UserRepository
- Utiliser le header 'Authorization' au lieu de 'x-access-token' dans l'intercepteur HTTP (compatibilité Spring Boot) - Lire le champ 'token' du service auth en plus de 'accessToken' lors du login (compatibilité avec le microservice auth séparé)
…a EE - Migrer javax.validation vers jakarta.validation (Spring Boot 3.x) - Gérer le cas NullNode dans checkOutput() pour éviter les faux négatifs - Ignorer la vérification du temps de réponse quand non défini (responseTime <= 0) - Optimiser le Dockerfile avec -DskipTests -B pour accélérer le build
- 14 test files covering security (JWT, OAuth2, services), controllers, entities, DTOs - JaCoCo 0.8.12 configured for coverage reporting - security.services and security.oauth2 at 100% branch coverage - Extract @EnableMongoAuditing to MongoAuditingConfig for @WebMvcTest compatibility - Add run-tests-testapi.ps1 one-click test runner - Add TEST-REPORT.md with full test matrix and coverage data - Update CONTRIBUTING.md, README.md, CONVENTIONS.md with test requirements
michelzzw
added a commit
that referenced
this pull request
Mar 11, 2026
cal-lie
self-requested a review
March 11, 2026 22:20
cal-lie
approved these changes
Mar 11, 2026
Valeeeu
self-requested a review
March 11, 2026 23:51
Valeeeu
approved these changes
Mar 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Équipe 3 – Phase 3: Tests unitaires de régression avec JaCoCo
Summary
This PR delivers the Phase 3 milestone for Équipe 3 — Tests unitaires de régression avec couverture JaCoCo. The objective was to create a comprehensive unit test suite for the testapi-Service backend module, ensuring that all code changes from Phase 1 (Diagnostic & Correction) and Phase 2 (JWT + OAuth2 Authentication) are protected by automated regression tests.
When we started Phase 3, the backend module had zero unit tests — only a single
contextLoads()test that required a running MongoDB instance and always failed in CI. There was no test infrastructure, no coverage reporting, and no automated quality gate to prevent regressions.After our changes, the backend has 61 unit tests (60 passing, 1 skipped), a JaCoCo coverage report, a one-click test script, and a pre-push Git hook that blocks pushes when tests fail. All security modules (JWT, OAuth2, Services) achieve 97–100% instruction coverage and 100% branch coverage.
Problems Found & Changes Made
1. No unit tests — zero regression protection
Problem: The backend module had no unit tests at all. The only test file (
TestAutomationFrameworkApplicationTests.java) contained acontextLoads()test that required a running MongoDB instance. Since MongoDB is only available inside Docker (not duringmvn test), this test always failed, making it impossible to run any tests during development.Changes:
security/jwt/—JwtUtilsTest(8),AuthTokenFilterTest(5),AuthEntryPointJwtTest(2)security/oauth2/—OAuth2LoginSuccessHandlerTest(6)security/services/—UserDetailsImplTest(8),UserDetailsServiceImplTest(2)security/—WebSecurityConfigTest(4)controller/—AuthControllerTest(7),OAuth2ControllerTest(1),TestControllerTest(3),TestApiControllerTest(3)entity/+payload/—UserEntityTest(6),JwtResponseTest(3),MessageResponseTest(2)@Disabled("Requires running MongoDB")tocontextLoads()so it no longer blocks the test suite2.
@EnableMongoAuditingon main class prevents@WebMvcTestProblem:
TestAutomationFrameworkApplication.javawas annotated with@EnableMongoAuditing, which triggers Spring Data MongoDB auto-configuration. When using@WebMvcTest(lightweight test slice that only loads MVC components), Spring still tried to create MongoDB beans (mongoTemplate,mappingMongoConverter), causingNoSuchBeanDefinitionException. This made it impossible to test controllers without a full application context and a running MongoDB.Changes:
MongoAuditingConfig.java(config/) — extracted@EnableMongoAuditinginto a separate@ConfigurationclassTestAutomationFrameworkApplication.java— removed@EnableMongoAuditingannotation@WebMvcTestslices to load without triggering MongoDB bean creation, while the full application still gets MongoDB auditing when running with@SpringBootTestor in production3. No coverage reporting tool
Problem: There was no way to measure test coverage. Developers had no visibility into which code paths were tested and which were not.
Changes (
backend/pom.xml):prepare-agent— instruments bytecode before test executionreport— generates HTML/XML coverage report after tests completebackend/target/site/jacoco/index.html4. JUnit version conflict causing test discovery issues
Problem:
backend/pom.xmlhardcoded JUnit Jupiter versions at5.10.2, but Spring Boot 3.5.10 BOM manages JUnit at5.12.2. This version mismatch causedNoSuchMethodErrorat runtime because the JUnit Platform Launcher expected APIs from 5.12.2 but found 5.10.2 classes.Changes (
backend/pom.xml):<version>5.10.2</version>fromjunit-jupiter,junit-jupiter-api, andjunit-jupiter-enginedependencies5. No one-click test execution
Problem: Running tests required knowing the exact Maven command with the correct module flags (
-pl backend -am), and settingJAVA_HOMEto JDK 17 (the development machine has JDK 25 as default, which is incompatible with Lombok 1.18.24).Changes:
run-tests-testapi.ps1— single-command test runner:.git/hooks/pre-push— Git hook that automatically runsmvn testbefore everygit push. If any test fails, the push is blocked. Usegit push --no-verifyto skip.6. No test documentation
Problem: There was no documentation explaining the test suite, how to run tests, what is covered, or why certain packages are not tested.
Changes:
TEST-REPORT.md— comprehensive test report with:CONTRIBUTING.md— added "Tests unitaires" section requiring all tests to pass before merge requestREADME.md— added "Tests unitaires" section with test count and execution commandCONVENTIONS.md— added test naming conventions (<method>_<scenario>_<expected>), annotation guidelines (@WebMvcTestvs@ExtendWith), and@MockitoBeanusageTesting & Validation
Test Execution Results
Coverage Summary
security(WebSecurityConfig)security.servicessecurity.oauth2security.jwtpayload.requestpayload.responsecontrollerPre-push Hook Validation
git push origin feature/UnitTestmvn testautomatically=== All tests passed — pushing ===* [new branch] feature/UnitTest -> feature/UnitTest✅Test Architecture Decisions
@WebMvcTestfor controllers@ExtendWith(MockitoExtension.class)for services@MockitoBean(not@MockBean)@MockBeanis deprecated@AutoConfigureMockMvc(addFilters = false)mvn testFiles Modified
New Files (Test Infrastructure)
backend/src/test/java/.../controller/AuthControllerTest.javabackend/src/test/java/.../controller/OAuth2ControllerTest.javabackend/src/test/java/.../controller/TestControllerTest.javabackend/src/test/java/.../controller/TestApiControllerTest.javabackend/src/test/java/.../security/jwt/JwtUtilsTest.javabackend/src/test/java/.../security/jwt/AuthTokenFilterTest.javabackend/src/test/java/.../security/jwt/AuthEntryPointJwtTest.javabackend/src/test/java/.../security/oauth2/OAuth2LoginSuccessHandlerTest.javabackend/src/test/java/.../security/services/UserDetailsImplTest.javabackend/src/test/java/.../security/services/UserDetailsServiceImplTest.javabackend/src/test/java/.../security/WebSecurityConfigTest.javabackend/src/test/java/.../entity/UserEntityTest.javabackend/src/test/java/.../payload/response/JwtResponseTest.javabackend/src/test/java/.../payload/response/MessageResponseTest.javabackend/src/test/resources/application.ymlbackend/src/main/java/.../config/MongoAuditingConfig.java@EnableMongoAuditingrun-tests-testapi.ps1TEST-REPORT.mdModified Files
backend/pom.xmlbackend/src/main/java/.../TestAutomationFrameworkApplication.java@EnableMongoAuditingbackend/src/test/java/.../TestAutomationFrameworkApplicationTests.java@DisabledCONTRIBUTING.mdREADME.mddocumentation/CONVENTIONS.md.gitignoreCommit History
test: add 61 unit tests with JaCoCo coverage