This is an automated email from the ASF dual-hosted git repository.
shuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to refs/heads/master by this push:
new d228345 More fixes on integrations tests, but not fully done yet.
d228345 is described below
commit d228345805654a09d9bcc4556b7859e92e171b2f
Author: Serge Huber <[email protected]>
AuthorDate: Fri Jun 5 15:16:30 2020 +0200
More fixes on integrations tests, but not fully done yet.
---
.../java/org/apache/unomi/itests/ContextServletIT.java | 17 +++++++++++++++--
.../test/java/org/apache/unomi/itests/TestUtils.java | 12 +++++++++++-
.../itests/graphql/GraphQLProfilePropertiesIT.java | 15 +++++++--------
.../main/java/org/apache/unomi/web/ContextServlet.java | 6 +++++-
4 files changed, 38 insertions(+), 12 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 2830e29..307a38e 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ContextServletIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ContextServletIT.java
@@ -138,6 +138,7 @@ public class ContextServletIT extends BaseIT {
Event event = new Event(eventId, eventTypeOriginal, session,
profile, scope, null, null, new Date());
profileService.save(profile);
this.eventService.send(event);
+ refreshPersistence();
Thread.sleep(2000);
event.setEventType(eventTypeUpdated); //change the event so we
can see the update effect
@@ -149,6 +150,7 @@ public class ContextServletIT extends BaseIT {
request.addHeader(THIRD_PARTY_HEADER_NAME, UNOMI_KEY);
request.setEntity(new
StringEntity(objectMapper.writeValueAsString(contextRequest),
ContentType.create("application/json")));
TestUtils.executeContextJSONRequest(request, sessionId);
+ refreshPersistence();
Thread.sleep(2000); //Making sure event is updated in DB
//Assert
@@ -171,6 +173,7 @@ public class ContextServletIT extends BaseIT {
Event event = new Event(eventId, eventTypeOriginal, session,
profile, scope, null, null, new Date());
profileService.save(profile);
this.eventService.send(event);
+ refreshPersistence();
Thread.sleep(2000);
event.setEventType(eventTypeUpdated); //change the event so we
can see the update effect
@@ -181,6 +184,7 @@ public class ContextServletIT extends BaseIT {
HttpPost request = new HttpPost(URL + CONTEXT_URL);
request.setEntity(new
StringEntity(objectMapper.writeValueAsString(contextRequest),
ContentType.create("application/json")));
TestUtils.executeContextJSONRequest(request, sessionId);
+ refreshPersistence();
Thread.sleep(2000); //Making sure event is updated in DB
//Assert
@@ -201,6 +205,7 @@ public class ContextServletIT extends BaseIT {
Session session = new Session(sessionId, profile, new Date(),
scope);
Event event = new Event(eventId, eventTypeOriginal, session,
profile, scope, null, null, new Date());
this.eventService.send(event);
+ refreshPersistence();
Thread.sleep(2000);
event.setEventType(eventTypeUpdated); //change the event so we
can see the update effect
@@ -211,6 +216,7 @@ public class ContextServletIT extends BaseIT {
HttpPost request = new HttpPost(URL + CONTEXT_URL);
request.setEntity(new
StringEntity(objectMapper.writeValueAsString(contextRequest),
ContentType.create("application/json")));
TestUtils.executeContextJSONRequest(request, sessionId);
+ refreshPersistence();
Thread.sleep(2000); //Making sure event is updated in DB
//Assert
@@ -236,19 +242,22 @@ public class ContextServletIT extends BaseIT {
HttpPost request = new HttpPost(URL + CONTEXT_URL);
request.setEntity(new
StringEntity(objectMapper.writeValueAsString(contextRequest),
ContentType.create("application/json")));
String cookieHeaderValue =
TestUtils.executeContextJSONRequest(request, sessionId).getCookieHeaderValue();
+ refreshPersistence();
Thread.sleep(1000); //Making sure DB is updated
//Add the context-profile-id cookie to the second event
request.addHeader("Cookie", cookieHeaderValue);
ContextResponse response =
(TestUtils.executeContextJSONRequest(request, sessionId)).getContextResponse();
//second event
+ refreshPersistence();
+
//Assert
assertEquals(1, response.getProfileSegments().size());
assertThat(response.getProfileSegments(),hasItem(SEGMENT_ID));
}
@Test
- public void
testCreateEventWithTimestampParam_pastEvent_profileIsNotAddedToSegment() throws
IOException {
+ public void
testCreateEventWithTimestampParam_pastEvent_profileIsNotAddedToSegment() throws
IOException, InterruptedException {
//Arrange
String sessionId = "test-session-id";
String scope = "test-scope";
@@ -268,17 +277,19 @@ public class ContextServletIT extends BaseIT {
request.setEntity(new
StringEntity(objectMapper.writeValueAsString(contextRequest),
ContentType.create("application/json")));
//The first event is with a default timestamp (now)
String cookieHeaderValue =
TestUtils.executeContextJSONRequest(request, sessionId).getCookieHeaderValue();
+ refreshPersistence();
//The second event is with a customized timestamp
request.setURI(URI.create(customTimestampURI));
request.addHeader("Cookie", cookieHeaderValue);
ContextResponse response =
(TestUtils.executeContextJSONRequest(request, sessionId)).getContextResponse();
//second event
+ refreshPersistence();
//Assert
assertEquals(0,response.getProfileSegments().size());
}
@Test
- public void
testCreateEventWithTimestampParam_futureEvent_profileIsNotAddedToSegment()
throws IOException {
+ public void
testCreateEventWithTimestampParam_futureEvent_profileIsNotAddedToSegment()
throws IOException, InterruptedException {
//Arrange
String sessionId = "test-session-id";
String scope = "test-scope";
@@ -298,10 +309,12 @@ public class ContextServletIT extends BaseIT {
request.setEntity(new
StringEntity(objectMapper.writeValueAsString(contextRequest),
ContentType.create("application/json")));
//The first event is with a default timestamp (now)
String cookieHeaderValue =
TestUtils.executeContextJSONRequest(request, sessionId).getCookieHeaderValue();
+ refreshPersistence();
//The second event is with a customized timestamp
request.setURI(URI.create(customTimestampURI));
request.addHeader("Cookie", cookieHeaderValue);
ContextResponse response =
(TestUtils.executeContextJSONRequest(request, sessionId)).getContextResponse();
//second event
+ refreshPersistence();
//Assert
assertEquals(0,response.getProfileSegments().size());
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 eae0252..6f45456 100644
--- a/itests/src/test/java/org/apache/unomi/itests/TestUtils.java
+++ b/itests/src/test/java/org/apache/unomi/itests/TestUtils.java
@@ -18,6 +18,7 @@
package org.apache.unomi.itests;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
@@ -33,11 +34,14 @@ import org.apache.unomi.api.services.DefinitionsService;
import org.apache.unomi.persistence.spi.CustomObjectMapper;
import org.apache.unomi.persistence.spi.PersistenceService;
import org.junit.Assert;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.IOException;
public class TestUtils {
private static final String JSON_MYME_TYPE = "application/json";
+ private final static Logger LOGGER =
LoggerFactory.getLogger(TestUtils.class);
public static <T> T retrieveResourceFromResponse(HttpResponse response,
Class<T> clazz) throws IOException {
if (response == null) {
@@ -53,6 +57,7 @@ public class TestUtils {
T value = mapper.readValue(jsonFromResponse, clazz);
return value;
} catch (Throwable t) {
+ LOGGER.error("Error parsing response JSON", t);
t.printStackTrace();
}
return null;
@@ -61,7 +66,12 @@ public class TestUtils {
public static RequestResponse executeContextJSONRequest(HttpPost
request, String sessionId) throws IOException {
try (CloseableHttpResponse response =
HttpClientBuilder.create().build().execute(request)) {
// validate mimeType
- String mimeType =
ContentType.getOrDefault(response.getEntity()).getMimeType();
+ HttpEntity entity = response.getEntity();
+ String mimeType =
ContentType.getOrDefault(entity).getMimeType();
+ if (!JSON_MYME_TYPE.equals(mimeType)) {
+ String entityContent =
EntityUtils.toString(entity);
+ LOGGER.warn("Invalid response: " +
entityContent);
+ }
Assert.assertEquals("Response content type should be "
+ JSON_MYME_TYPE, JSON_MYME_TYPE, mimeType);
// validate context
diff --git
a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLProfilePropertiesIT.java
b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLProfilePropertiesIT.java
index c872876..a0ec100 100644
---
a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLProfilePropertiesIT.java
+++
b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLProfilePropertiesIT.java
@@ -28,10 +28,7 @@ import org.ops4j.pax.exam.util.Filter;
import javax.inject.Inject;
import java.time.OffsetDateTime;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
public class GraphQLProfilePropertiesIT extends BaseGraphQLIT {
@@ -77,8 +74,10 @@ public class GraphQLProfilePropertiesIT extends
BaseGraphQLIT {
consent.setTypeIdentifier("newsletter1");
consent.setScope("digitall");
consent.setStatus(ConsentStatus.GRANTED);
-
consent.setStatusDate(DateUtils.toDate(OffsetDateTime.parse("2019-05-15T14:47:28Z")));
-
consent.setRevokeDate(DateUtils.toDate(OffsetDateTime.parse("2021-05-14T14:47:28Z")));
+ Date statusDate =
DateUtils.toDate(OffsetDateTime.parse("2019-05-15T14:47:28Z"));
+ consent.setStatusDate(statusDate);
+ Date revokationDate =
DateUtils.toDate(OffsetDateTime.parse("2021-05-14T14:47:28Z"));
+ consent.setRevokeDate(revokationDate);
final Map<String, Double> interestsAsMap = new HashMap<>();
@@ -102,8 +101,8 @@ public class GraphQLProfilePropertiesIT extends
BaseGraphQLIT {
// assert consent
Assert.assertEquals("GRANTED",
context.getValue("data.cdp.getProfile.cdp_consents[0].status"));
Assert.assertEquals("newsletter1",
context.getValue("data.cdp.getProfile.cdp_consents[0].type"));
- Assert.assertEquals("2019-05-15T17:47:28+03:00",
context.getValue("data.cdp.getProfile.cdp_consents[0].lastUpdate"));
- Assert.assertEquals("2021-05-14T17:47:28+03:00",
context.getValue("data.cdp.getProfile.cdp_consents[0].expiration"));
+ Assert.assertEquals(statusDate,
DateUtils.toDate(OffsetDateTime.parse(context.getValue("data.cdp.getProfile.cdp_consents[0].lastUpdate"))));
+ Assert.assertEquals(revokationDate,
DateUtils.toDate(OffsetDateTime.parse(context.getValue("data.cdp.getProfile.cdp_consents[0].expiration"))));
// assert interests
Assert.assertEquals("interestName",
context.getValue("data.cdp.getProfile.cdp_interests[0].topic"));
diff --git a/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
b/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
index 693c23e..3604162 100644
--- a/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
+++ b/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
@@ -179,7 +179,11 @@ public class ContextServlet extends HttpServlet {
// We must reload the profile with the session ID as
some properties could be missing from the session profile
// #personalIdentifier
profile =
profileService.load(sessionProfile.getItemId());
- HttpUtils.sendProfileCookie(profile, response,
profileIdCookieName, profileIdCookieDomain, profileIdCookieMaxAgeInSeconds);
+ if (profile != null) {
+ HttpUtils.sendProfileCookie(profile, response,
profileIdCookieName, profileIdCookieDomain, profileIdCookieMaxAgeInSeconds);
+ } else {
+ logger.warn("Couldn't load profile {} referenced
in session {}", sessionProfile.getItemId(), session.getItemId());
+ }
}
// Handle anonymous situation