Skip to content

UNOMI-139 UNOMI-878: Platform integration tests#766

Open
sergehuber wants to merge 7 commits into
UNOMI-880-878-shell-dev-commandsfrom
UNOMI-139-878-integration-tests
Open

UNOMI-139 UNOMI-878: Platform integration tests#766
sergehuber wants to merge 7 commits into
UNOMI-880-878-shell-dev-commandsfrom
UNOMI-139-878-integration-tests

Conversation

@sergehuber
Copy link
Copy Markdown
Contributor

Summary

  • Adds TenantIT, SecurityIT, PersonaIT, SchedulerIT, and EventsCollectorIT integration test classes covering multitenancy and core platform flows
  • Fixes TenantIT and EventsCollectorIT test failures (reverted intermediate fix, replaced with stable version)
  • Moves HealthCheckIT to run last in AllITs suite to avoid startup-timing flakiness

Test plan

  • All five new IT classes pass in a full ./build.sh --ci --integration-tests run
  • AllITs suite ordering change does not affect other tests
  • Stacked on PR for UNOMI-880-878-shell-dev-commands — merge that first

🤖 Generated with Claude Code

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.
Avoid heavy concurrent /health/check load immediately before TenantIT.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AllITs to include the new ITs and move HealthCheckIT to 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());
}
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.

2 participants