You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by sh...@apache.org on 2020/07/27 08:04:33 UTC
[unomi] 01/11: Porting ITest fixes
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 deb906fad6b106200e75c69728394071fa3fc4dc
Author: Serge Huber <sh...@jahia.com>
AuthorDate: Mon Jul 27 09:53:27 2020 +0200
Porting ITest fixes
---
.../test/java/org/apache/unomi/itests/BaseIT.java | 43 +++++++++++++++++-----
.../org/apache/unomi/itests/ContextServletIT.java | 42 ++++++++++++++++-----
.../apache/unomi/itests/ProfileImportActorsIT.java | 33 +++++++++++++----
.../unomi/itests/ProfileImportRankingIT.java | 22 ++++++++---
.../unomi/itests/ProfileImportSurfersIT.java | 33 +++++++++++------
.../java/org/apache/unomi/itests/TestUtils.java | 12 +++++-
.../java/org/apache/unomi/web/ContextServlet.java | 6 ++-
7 files changed, 145 insertions(+), 46 deletions(-)
diff --git a/itests/src/test/java/org/apache/unomi/itests/BaseIT.java b/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
index 6651562..f6c35e4 100644
--- a/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
@@ -17,6 +17,10 @@
package org.apache.unomi.itests;
+import org.apache.unomi.api.Item;
+import org.apache.unomi.api.conditions.Condition;
+import org.apache.unomi.api.services.DefinitionsService;
+import org.apache.unomi.persistence.spi.PersistenceService;
import org.junit.Assert;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.CoreOptions;
@@ -24,9 +28,10 @@ import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.karaf.container.internal.JavaVersionUtil;
import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
-import org.ops4j.pax.exam.options.MavenUrlReference;
import org.ops4j.pax.exam.options.extra.VMOption;
+import org.ops4j.pax.exam.util.Filter;
+import javax.inject.Inject;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
@@ -36,7 +41,12 @@ import java.util.function.Supplier;
import static org.ops4j.pax.exam.CoreOptions.maven;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.*;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.debugConfiguration;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
/**
* Base class for integration tests.
@@ -50,6 +60,27 @@ public abstract class BaseIT {
protected static final String KARAF_DIR = "target/exam";
protected static final String UNOMI_KEY = "670c26d1cc413346c3b2fd9ce65dab41";
+ @Inject
+ @Filter(timeout = 600000)
+ protected PersistenceService persistenceService;
+
+ @Inject
+ @Filter(timeout = 600000)
+ protected DefinitionsService definitionsService;
+
+ protected void removeItems(final Class<? extends Item> ...classes) throws InterruptedException {
+ Condition condition = new Condition(definitionsService.getConditionType("matchAllCondition"));
+ for (Class<? extends Item> aClass : classes) {
+ persistenceService.removeByQuery(condition, aClass);
+ }
+ refreshPersistence();
+ }
+
+ protected void refreshPersistence() throws InterruptedException {
+ persistenceService.refresh();
+ Thread.sleep(1000);
+ }
+
@Configuration
public Option[] config() throws InterruptedException {
@@ -59,13 +90,6 @@ public abstract class BaseIT {
.type("tar.gz")
.versionAsInProject();
- MavenUrlReference routerRepo = maven()
- .groupId("org.apache.unomi")
- .artifactId("unomi-router-karaf-feature")
- .classifier("features")
- .type("xml")
- .versionAsInProject();
-
List<Option> options = new ArrayList<>();
Option[] commonOptions = new Option[]{
@@ -109,7 +133,6 @@ public abstract class BaseIT {
systemProperty("org.apache.unomi.hazelcast.tcp-ip.members").value("127.0.0.1"),
systemProperty("org.apache.unomi.hazelcast.tcp-ip.interface").value("127.0.0.1"),
systemProperty("unomi.autoStart").value("true"),
- features(routerRepo, "unomi-router-karaf-feature"),
CoreOptions.bundleStartLevel(100),
CoreOptions.frameworkStartLevel(100)
};
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 926627b..307a38e 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ContextServletIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ContextServletIT.java
@@ -21,7 +21,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
-import org.apache.unomi.api.*;
+import org.apache.unomi.api.ContextRequest;
+import org.apache.unomi.api.ContextResponse;
+import org.apache.unomi.api.Event;
+import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.Profile;
+import org.apache.unomi.api.Session;
import org.apache.unomi.api.conditions.Condition;
import org.apache.unomi.api.segments.Segment;
import org.apache.unomi.api.services.DefinitionsService;
@@ -87,6 +92,8 @@ public class ContextServletIT extends BaseIT {
@Filter(timeout = 600000)
protected SegmentService segmentService;
+ private Profile profile;
+
@Before
public void setUp() throws InterruptedException {
//Create a past-event segment
@@ -100,7 +107,12 @@ public class ContextServletIT extends BaseIT {
segmentCondition.setParameter("eventCondition",pastEventEventCondition);
segment.setCondition(segmentCondition);
segmentService.setSegmentDefinition(segment);
- Thread.sleep(2000);
+
+ String profileId = "test-profile-id";
+ profile = new Profile(profileId);
+ profileService.save(profile);
+
+ refreshPersistence();
}
@After
@@ -108,8 +120,8 @@ public class ContextServletIT extends BaseIT {
TestUtils.removeAllEvents(definitionsService, persistenceService);
TestUtils.removeAllSessions(definitionsService, persistenceService);
TestUtils.removeAllProfiles(definitionsService, persistenceService);
+ profileService.delete(profile.getItemId(), false);
segmentService.removeSegmentDefinition(SEGMENT_ID,false);
- persistenceService.refresh();
}
@Test
@@ -126,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
@@ -137,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
@@ -159,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
@@ -169,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
@@ -182,16 +198,14 @@ public class ContextServletIT extends BaseIT {
public void testUpdateEventFromContextAuthorizedThirdPartyNoItemID_Fail() throws IOException, InterruptedException {
//Arrange
String eventId = "test-event-id3";
- String profileId = "test-profile-id";
String sessionId = "test-session-id";
String scope = "test-scope";
String eventTypeOriginal = "test-event-type-original";
String eventTypeUpdated = "test-event-type-updated";
- Profile profile = new Profile(profileId);
Session session = new Session(sessionId, profile, new Date(), scope);
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
@@ -202,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
@@ -211,7 +226,7 @@ public class ContextServletIT extends BaseIT {
}
@Test
- public void testCreateEventsWithNoTimestampParam_profileAddedToSegment() throws IOException {
+ public void testCreateEventsWithNoTimestampParam_profileAddedToSegment() throws IOException, InterruptedException {
//Arrange
String sessionId = "test-session-id";
String scope = "test-scope";
@@ -227,17 +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";
@@ -257,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";
@@ -287,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/ProfileImportActorsIT.java b/itests/src/test/java/org/apache/unomi/itests/ProfileImportActorsIT.java
index 677ccbc..0d31b7f 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileImportActorsIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileImportActorsIT.java
@@ -34,7 +34,12 @@ import org.ops4j.pax.exam.util.Filter;
import javax.inject.Inject;
import java.io.File;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
/**
* Created by amidani on 14/08/2017.
@@ -43,9 +48,11 @@ import java.util.*;
@ExamReactorStrategy(PerSuite.class)
public class ProfileImportActorsIT extends BaseIT {
- @Inject @Filter(value="(configDiscriminator=IMPORT)", timeout = 600000)
+ @Inject
+ @Filter(value = "(configDiscriminator=IMPORT)", timeout = 600000)
protected ImportExportConfigurationService<ImportConfiguration> importConfigurationService;
- @Inject @Filter(timeout = 600000)
+ @Inject
+ @Filter(timeout = 600000)
protected ProfileService profileService;
@Test
@@ -66,11 +73,17 @@ public class ProfileImportActorsIT extends BaseIT {
profileService.setPropertyType(propertyTypeTwitterId);
profileService.setPropertyType(propertyTypeActorsGenres);
- PropertyType propTwitterId = profileService.getPropertyType("twitterId");
- Assert.assertNotNull(propTwitterId);
+ PropertyType propTwitterId = keepTrying("Failed waiting for property type 'twitterId'",
+ () -> profileService.getPropertyType("twitterId"),
+ Objects::nonNull,
+ 1000,
+ 100);
- PropertyType propActorsGenre = profileService.getPropertyType("movieGenres");
- Assert.assertNotNull(propActorsGenre);
+ PropertyType propActorsGenre = keepTrying("Failed waiting for property type 'movieGenres'",
+ () -> profileService.getPropertyType("movieGenres"),
+ Objects::nonNull,
+ 1000,
+ 100);
/*** Actors Test ***/
@@ -101,7 +114,11 @@ public class ProfileImportActorsIT extends BaseIT {
importConfigurationService.save(importConfigActors, true);
//Wait for data to be processed
- keepTrying("Failed waiting for actors initial import to complete", ()-> profileService.findProfilesByPropertyValue("properties.city", "hollywood", 0, 10, null), (p)->p.getTotalSize() == 6, 1000, 200);
+ keepTrying("Failed waiting for actors initial import to complete",
+ () -> profileService.findProfilesByPropertyValue("properties.city", "hollywood", 0, 10, null),
+ (p) -> p.getTotalSize() == 6,
+ 1000,
+ 200);
List<ImportConfiguration> importConfigurations = importConfigurationService.getAll();
Assert.assertEquals(1, importConfigurations.size());
diff --git a/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java b/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java
index 9694598..9159426 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java
@@ -38,6 +38,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
/**
* Created by amidani on 09/08/2017.
@@ -71,11 +72,17 @@ public class ProfileImportRankingIT extends BaseIT {
profileService.setPropertyType(propertyTypeRank);
- PropertyType propUciId = profileService.getPropertyType("uciId");
- Assert.assertNotNull(propUciId);
+ PropertyType propUciId = keepTrying("Failed waiting for property type 'uciId'",
+ () -> profileService.getPropertyType("uciId"),
+ Objects::nonNull,
+ 1000,
+ 100);
- PropertyType propRankId = profileService.getPropertyType("rank");
- Assert.assertNotNull(propRankId);
+ PropertyType propRankId = keepTrying("Failed waiting for property type 'rank'",
+ () -> profileService.getPropertyType("rank"),
+ Objects::nonNull,
+ 1000,
+ 100);
/*** Surfers Test ***/
@@ -108,8 +115,11 @@ public class ProfileImportRankingIT extends BaseIT {
//Wait for data to be processed
keepTrying("Failed waiting for ranking import to complete", ()->profileService.findProfilesByPropertyValue("properties.city", "rankingCity", 0, 50, null), (p)->p.getTotalSize() == 25, 1000, 200);
- List<ImportConfiguration> importConfigurations = importConfigurationService.getAll();
- Assert.assertEquals(1, importConfigurations.size());
+ List<ImportConfiguration> importConfigurations = keepTrying("Failed waiting for import configurations list with 1 item",
+ () -> importConfigurationService.getAll(),
+ (list) -> Objects.nonNull(list) && list.size() == 1,
+ 1000,
+ 100);
PartialList<Profile> gregProfileList = profileService.findProfilesByPropertyValue("properties.uciId", "10004451371", 0, 10, null);
Assert.assertEquals(1, gregProfileList.getList().size());
diff --git a/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersIT.java b/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersIT.java
index e4bbf69..01ea0fe 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersIT.java
@@ -40,8 +40,8 @@ import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
+import java.util.Objects;
/**
* Created by amidani on 09/08/2017.
@@ -67,11 +67,13 @@ public class ProfileImportSurfersIT extends BaseIT {
profileService.setPropertyType(propertyType);
- PropertyType propAlive = profileService.getPropertyType("alive");
+ keepTrying("Failed waiting for property type 'alive'",
+ () -> profileService.getPropertyType("alive"),
+ Objects::nonNull,
+ 1000,
+ 100);
- Assert.assertNotNull("Alive property should not be null", propAlive);
-
- propAlive = RouterUtils.getPropertyTypeById(profileService.getTargetPropertyTypes("profiles"), "alive");
+ PropertyType propAlive = RouterUtils.getPropertyTypeById(profileService.getTargetPropertyTypes("profiles"), "alive");
Assert.assertNotNull("Lookup of alive property through profiles target has failed !", propAlive);
@@ -107,8 +109,11 @@ public class ProfileImportSurfersIT extends BaseIT {
//Wait for data to be processed
keepTrying("Failed waiting for surfers initial import to complete", ()->profileService.findProfilesByPropertyValue("properties.city", "surfersCity", 0, 50, null), (p)->p.getTotalSize() == 34, 1000, 100);
- List<ImportConfiguration> importConfigurations = importConfigurationService.getAll();
- Assert.assertEquals(1, importConfigurations.size());
+ keepTrying("Failed waiting for import configurations list with 1 item",
+ () -> importConfigurationService.getAll(),
+ (list) -> Objects.nonNull(list) && list.size() == 1,
+ 1000,
+ 100);
//Profile not to delete
PartialList<Profile> jordyProfile = profileService.findProfilesByPropertyValue("properties.email", "jordy@smith.com", 0, 10, null);
@@ -152,8 +157,11 @@ public class ProfileImportSurfersIT extends BaseIT {
//Wait for data to be processed
keepTrying("Failed waiting for surfers overwrite import to complete", ()->profileService.findProfilesByPropertyValue("properties.city", "surfersCity", 0, 50, null), (p)->p.getTotalSize() == 36, 1000, 100);
- importConfigurations = importConfigurationService.getAll();
- Assert.assertEquals(1, importConfigurations.size());
+ keepTrying("Failed waiting for import configurations list with 1 item",
+ () -> importConfigurationService.getAll(),
+ (list) -> Objects.nonNull(list) && list.size() == 1,
+ 1000,
+ 100);
//Profile not to delete
PartialList<Profile> aliveProfiles = profileService.findProfilesByPropertyValue("properties.alive", "true", 0, 50, null);
@@ -191,8 +199,11 @@ public class ProfileImportSurfersIT extends BaseIT {
//Wait for data to be processed
keepTrying("Failed waiting for surfers delete import to complete", ()->profileService.findProfilesByPropertyValue("properties.city", "surfersCity", 0, 50, null), (p)->p.getTotalSize() == 0, 1000, 100);
- importConfigurations = importConfigurationService.getAll();
- Assert.assertEquals(1, importConfigurations.size());
+ keepTrying("Failed waiting for import configurations list with 1 item",
+ () -> importConfigurationService.getAll(),
+ (list) -> Objects.nonNull(list) && list.size() == 1,
+ 1000,
+ 100);
PartialList<Profile> jordyProfileDelete = profileService.findProfilesByPropertyValue("properties.email", "jordy@smith.com", 0, 10, null);
Assert.assertEquals(0, jordyProfileDelete.getList().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/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