UNOMI-139 UNOMI-878: Platform integration tests#766
Open
sergehuber wants to merge 7 commits into
Open
Conversation
Add TenantIT, SecurityIT, PersonaIT, EventsCollectorIT, SchedulerIT and persona test fixture. Register platform ITs in AllITs (including TenantIT, SchedulerIT, EventsCollectorIT for CI coverage per split plan).
- TenantIT: use /cxs/context.json (REST endpoint) instead of legacy /context.json servlet forward that timed out under Pax Exam. - EventCollectorResponse: add Jackson @JsonCreator so IT clients can deserialize the POST /cxs/eventcollector JSON body.
…lures" This reverts commit 958d2fb.
Avoid heavy concurrent /health/check load immediately before TenantIT.
There was a problem hiding this comment.
Pull request overview
Adds new PaxExam-based integration tests to cover multitenancy, security/system execution context behavior, scheduler REST API flows, persona sessions, and event collector authentication; also updates the AllITs suite ordering to include the new tests and run HealthCheckIT last to reduce flakiness.
Changes:
- Added new integration test classes:
TenantIT,SecurityIT,SchedulerIT,PersonaIT,EventsCollectorIT. - Added persona test payload resource for creating a persona with sessions via REST.
- Updated
AllITsto include the new ITs and moveHealthCheckITto the end.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| itests/src/test/resources/persona/persona-with-sessions-payload.json | Adds payload used by persona/session integration test. |
| itests/src/test/java/org/apache/unomi/itests/TenantIT.java | Adds multitenancy and API key/auth integration coverage. |
| itests/src/test/java/org/apache/unomi/itests/SecurityIT.java | Adds system subject/context execution and restoration coverage. |
| itests/src/test/java/org/apache/unomi/itests/SchedulerIT.java | Adds scheduler task REST API integration coverage. |
| itests/src/test/java/org/apache/unomi/itests/PersonaIT.java | Adds persona-with-sessions creation and retrieval coverage. |
| itests/src/test/java/org/apache/unomi/itests/EventsCollectorIT.java | Adds event collector authentication/flags coverage. |
| itests/src/test/java/org/apache/unomi/itests/AllITs.java | Registers new ITs and moves HealthCheckIT to run last. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+121
to
+128
| public void testCancelTask() throws Exception { | ||
| CloseableHttpResponse response = delete("/cxs/tasks/" + testTaskId); | ||
| assertEquals("Response should be No Content", 204, response.getStatusLine().getStatusCode()); | ||
|
|
||
| // Verify task is cancelled | ||
| ScheduledTask task = schedulerService.getTask(testTaskId); | ||
| assertEquals("Task should be cancelled", ScheduledTask.TaskStatus.CANCELLED, task.getStatus()); | ||
| } |
Comment on lines
+140
to
+149
| // Now retry the task | ||
| CloseableHttpResponse response = post("/cxs/tasks/" + testTaskId + "/retry?resetFailureCount=true", null); | ||
| assertEquals("Response should be OK", 200, response.getStatusLine().getStatusCode()); | ||
|
|
||
| String responseBody = EntityUtils.toString(response.getEntity()); | ||
| ScheduledTask task = objectMapper.readValue(responseBody, ScheduledTask.class); | ||
| assertNotNull("Task should not be null", task); | ||
| assertEquals("Task should be scheduled", ScheduledTask.TaskStatus.SCHEDULED, task.getStatus()); | ||
| assertEquals("Failure count should be reset", 0, task.getFailureCount()); | ||
| } |
Comment on lines
+321
to
+342
| // Create two tenants | ||
| Tenant tenant1 = tenantService.createTenant("tenant-1", Collections.emptyMap()); | ||
| Tenant tenant2 = tenantService.createTenant("tenant-2", Collections.emptyMap()); | ||
|
|
||
| // Generate API keys | ||
| ApiKey apiKey1 = tenantService.generateApiKey(tenant1.getItemId(), null); | ||
| ApiKey apiKey2 = tenantService.generateApiKey(tenant2.getItemId(), null); | ||
|
|
||
| // Create profile in tenant1 | ||
| executionContextManager.executeAsTenant(tenant1.getItemId(), () -> { | ||
| Profile profile1 = new Profile(); | ||
| profile1.setItemId("profile1"); | ||
| profile1.setProperty("name", "John"); | ||
| persistenceService.save(profile1); | ||
| }); | ||
|
|
||
| // Try to access profile from tenant2 | ||
| executionContextManager.executeAsTenant(tenant2.getItemId(), () -> { | ||
| Profile loadedProfile = persistenceService.load("profile1", Profile.class); | ||
| Assert.assertNull("Profile should not be accessible from different tenants", loadedProfile); | ||
| }); | ||
| } |
Comment on lines
+388
to
+394
| Tenant tenant = tenantService.createTenant("expired-tenant", Collections.emptyMap()); | ||
| ApiKey apiKey = tenantService.generateApiKey(tenant.getItemId(), 1L); // 1ms validity | ||
|
|
||
| Thread.sleep(2); // Wait for key to expire | ||
|
|
||
| Assert.assertFalse(tenantService.validateApiKey(tenant.getItemId(), apiKey.getItemId())); | ||
| } |
Comment on lines
+121
to
+137
| // Execute request and verify response | ||
| CloseableHttpResponse response = HttpClientThatWaitsForUnomi.doRequest(request, 200); | ||
| String responseContent = EntityUtils.toString(response.getEntity()); | ||
| EventCollectorResponse eventResponse = objectMapper.readValue(responseContent, EventCollectorResponse.class); | ||
| Assert.assertNotNull("Event collector response should not be null", eventResponse); | ||
|
|
||
| // Check that the response indicates the session and profile were updated | ||
| int expectedFlags = EventService.PROFILE_UPDATED | EventService.SESSION_UPDATED; | ||
| Assert.assertEquals("Response should indicate that the session and profile were updated", | ||
| expectedFlags, eventResponse.getUpdated()); | ||
|
|
||
| // Test with invalid API key | ||
| request.removeHeaders("X-Unomi-Api-Key"); // We need to do this since we are reusing the request object since the last call added auth to it. | ||
| HttpClientThatWaitsForUnomi.setTestTenant(null, null, null); | ||
| response = HttpClientThatWaitsForUnomi.doRequest(request, 401); | ||
| Assert.assertEquals("Request with invalid API key should return 401", 401, response.getStatusLine().getStatusCode()); | ||
| } |
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.
Summary
TenantIT,SecurityIT,PersonaIT,SchedulerIT, andEventsCollectorITintegration test classes covering multitenancy and core platform flowsTenantITandEventsCollectorITtest failures (reverted intermediate fix, replaced with stable version)HealthCheckITto run last inAllITssuite to avoid startup-timing flakinessTest plan
./build.sh --ci --integration-testsrunAllITssuite ordering change does not affect other testsUNOMI-880-878-shell-dev-commands— merge that first🤖 Generated with Claude Code