This is an automated email from the ASF dual-hosted git repository. shuber pushed a commit to branch unomi-1.5.x in repository https://gitbox.apache.org/repos/asf/unomi.git
commit fe4f09cbda13e35f0cd30867ae20990c985e48db Author: Shir <[email protected]> AuthorDate: Mon Jul 20 11:28:44 2020 +0300 Add itests for sending a new event with profile id (cherry picked from commit f83a236a9914ef12af7a455c329c7799b6566f5b) --- .../org/apache/unomi/itests/ContextServletIT.java | 27 ++++++++++++++++++++++ .../java/org/apache/unomi/itests/TestUtils.java | 11 ++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) 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 @@ public class ContextServletIT extends BaseIT { //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 @@ public class TestUtils { 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 class TestUtils { } } + 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");
