Add itests for sending a new event with profile id
diff --git a/itests/src/test/java/org/apache/unomi/itests/ContextServletIT.java b/itests/src/test/java/org/apache/unomi/itests/ContextServletIT.java
index 307a38e..0587a21 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ContextServletIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ContextServletIT.java
@@ -319,4 +319,31 @@
//Assert
assertEquals(0,response.getProfileSegments().size());
}
+
+ @Test
+ public void testCreateEventWithProfileId_Success() throws IOException, InterruptedException {
+ //Arrange
+ String eventId = "test-event-id1";
+ String profileId = "test-profile-id";
+ String eventType = "test-event-type";
+ Event event = new Event();
+ event.setEventType(eventType);
+ event.setItemId(eventId);
+
+ ContextRequest contextRequest = new ContextRequest();
+ contextRequest.setProfileId(profileId);
+ contextRequest.setEvents(Arrays.asList(event));
+
+ //Act
+ HttpPost request = new HttpPost(URL + CONTEXT_URL);
+ request.addHeader(THIRD_PARTY_HEADER_NAME, UNOMI_KEY);
+ request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.create("application/json")));
+ TestUtils.executeContextJSONRequest(request);
+ refreshPersistence();
+ Thread.sleep(2000); //Making sure event is updated in DB
+
+ //Assert
+ Profile profile = this.profileService.load(profileId);
+ assertEquals(profileId, profile.getItemId());
+ }
}
diff --git a/itests/src/test/java/org/apache/unomi/itests/TestUtils.java b/itests/src/test/java/org/apache/unomi/itests/TestUtils.java
index 6f45456..5e385f5 100644
--- a/itests/src/test/java/org/apache/unomi/itests/TestUtils.java
+++ b/itests/src/test/java/org/apache/unomi/itests/TestUtils.java
@@ -78,9 +78,10 @@
ContextResponse context = TestUtils.retrieveResourceFromResponse(response, ContextResponse.class);
Assert.assertNotNull("Context should not be null", context);
Assert.assertNotNull("Context profileId should not be null", context.getProfileId());
- Assert.assertEquals("Context sessionId should be the same as the sessionId used to request the context", sessionId,
- context.getSessionId());
-
+ if (sessionId != null) {
+ Assert.assertEquals("Context sessionId should be the same as the sessionId used to request the context", sessionId,
+ context.getSessionId());
+ }
String cookieHeader = null;
if (response.containsHeader("Set-Cookie")) {
cookieHeader = response.getHeaders("Set-Cookie")[0].toString().substring(12);
@@ -89,6 +90,10 @@
}
}
+ public static RequestResponse executeContextJSONRequest(HttpPost request) throws IOException {
+ return executeContextJSONRequest(request, null);
+ }
+
public static boolean removeAllProfiles(DefinitionsService definitionsService, PersistenceService persistenceService) {
Condition condition = new Condition(definitionsService.getConditionType("profilePropertyCondition"));
condition.setParameter("propertyName","itemType");