This is an automated email from the ASF dual-hosted git repository. jkevan pushed a commit to branch migrationTests in repository https://gitbox.apache.org/repos/asf/unomi.git
commit b63144ac63a3a8770a22912e9208a41b06e7bebc Author: Kevan <ke...@jahia.com> AuthorDate: Mon Jul 25 16:48:48 2022 +0200 UNOMI-203: improve integration test to use KarafTestSupport --- itests/pom.xml | 138 ++++++++++----------- .../test/java/org/apache/unomi/itests/BaseIT.java | 132 +++++++------------- .../test/java/org/apache/unomi/itests/BasicIT.java | 32 +++-- .../org/apache/unomi/itests/ContextServletIT.java | 64 +++++----- .../org/apache/unomi/itests/InputValidationIT.java | 34 ++--- .../java/org/apache/unomi/itests/JSONSchemaIT.java | 6 +- .../itests/ProfileServiceWithoutOverwriteIT.java | 2 +- .../java/org/apache/unomi/itests/SecurityIT.java | 4 +- .../apache/unomi/itests/graphql/BaseGraphQLIT.java | 10 +- .../unomi/itests/graphql/GraphQLEventIT.java | 8 +- .../unomi/itests/graphql/GraphQLProfileIT.java | 4 +- .../unomi/itests/graphql/GraphQLSegmentIT.java | 2 +- .../unomi/itests/graphql/GraphQLSourceIT.java | 2 +- .../unomi/itests/graphql/GraphQLTopicIT.java | 2 +- .../unomi/itests/graphql/GraphQLWebSocketIT.java | 4 +- .../ElasticSearchPersistenceServiceImpl.java | 11 -- pom.xml | 1 + 17 files changed, 195 insertions(+), 261 deletions(-) diff --git a/itests/pom.xml b/itests/pom.xml index b65bce832..c808b5c63 100644 --- a/itests/pom.xml +++ b/itests/pom.xml @@ -28,127 +28,112 @@ <name>Apache Unomi :: Integration Tests</name> <description>Apache Unomi Context Server integration tests</description> + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.karaf</groupId> + <artifactId>karaf-bom</artifactId> + <version>${karaf.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + <dependencies> + <!-- Provide the KarafTestSupport --> <dependency> - <groupId>org.apache.unomi</groupId> - <artifactId>unomi</artifactId> - <version>${project.version}</version> - <type>tar.gz</type> + <groupId>org.apache.karaf.itests</groupId> + <artifactId>common</artifactId> + <version>${karaf.version}</version> <scope>test</scope> </dependency> + <!-- Define the Apache Karaf version to download and use for the test --> + <!-- We use a released version here to avoid SNAPSHOT resolution --> <dependency> <groupId>org.apache.unomi</groupId> - <artifactId>unomi-router-karaf-feature</artifactId> - <classifier>features</classifier> + <artifactId>unomi</artifactId> <version>${project.version}</version> - <type>xml</type> + <type>tar.gz</type> <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.apache.karaf</groupId> + <artifactId>org.apache.karaf.client</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient-osgi</artifactId> + </exclusion> + </exclusions> </dependency> + <!-- Required to use shell commands in the tests --> <dependency> - <groupId>org.apache.unomi</groupId> - <artifactId>cdp-graphql-feature</artifactId> - <classifier>features</classifier> - <version>${project.version}</version> - <type>xml</type> + <groupId>org.apache.karaf.shell</groupId> + <artifactId>org.apache.karaf.shell.core</artifactId> <scope>test</scope> </dependency> + <!-- Provide the PaxExam Karaf support --> <dependency> - <groupId>org.apache.unomi</groupId> - <artifactId>unomi-persistence-spi</artifactId> - <version>${project.version}</version> - <scope>provided</scope> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-container-karaf</artifactId> + <scope>test</scope> </dependency> + <!-- Provide the PaxExam JUnit extension --> <dependency> - <groupId>org.apache.unomi</groupId> - <artifactId>unomi-wab</artifactId> - <version>${project.version}</version> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-junit4</artifactId> <scope>test</scope> </dependency> <dependency> - <groupId>org.apache.unomi</groupId> - <artifactId>unomi-lifecycle-watcher</artifactId> - <version>${project.version}</version> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-atinject_1.0_spec</artifactId> + <version>1.2</version> <scope>test</scope> </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <scope>provided</scope> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> </dependency> <dependency> - <groupId>org.codehaus.groovy</groupId> - <artifactId>groovy</artifactId> - <version>${groovy.version}</version> - <scope>provided</scope> + <groupId>org.apache.servicemix.bundles</groupId> + <artifactId>org.apache.servicemix.bundles.hamcrest</artifactId> + <version>1.3_1</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient-osgi</artifactId> - <type>bundle</type> + <version>4.5.5</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore-osgi</artifactId> + <version>4.4.9</version> </dependency> <dependency> <groupId>org.eclipse.jetty.websocket</groupId> <artifactId>websocket-client</artifactId> <version>9.4.28.v20200408</version> - <type>bundle</type> - </dependency> - - - <!-- Dependencies for pax exam karaf container --> - <dependency> - <groupId>org.ops4j.pax.exam</groupId> - <artifactId>pax-exam-container-karaf</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.ops4j.pax.exam</groupId> - <artifactId>pax-exam-junit4</artifactId> - <scope>test</scope> </dependency> <dependency> - <groupId>org.ops4j.pax.exam</groupId> - <artifactId>pax-exam</artifactId> + <groupId>org.apache.unomi</groupId> + <artifactId>unomi-lifecycle-watcher</artifactId> + <version>${project.version}</version> <scope>test</scope> </dependency> <dependency> - <groupId>org.ops4j.pax.url</groupId> - <artifactId>pax-url-aether</artifactId> + <groupId>org.apache.unomi</groupId> + <artifactId>unomi-persistence-spi</artifactId> + <version>${project.version}</version> <scope>test</scope> </dependency> <dependency> - <groupId>javax.inject</groupId> - <artifactId>javax.inject</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>osgi.core</artifactId> + <groupId>org.codehaus.groovy</groupId> + <artifactId>groovy</artifactId> + <version>${groovy.version}</version> <scope>provided</scope> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - <version>1.6.6</version> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.ops4j.pax.url</groupId> - <artifactId>pax-url-wrap</artifactId> - <classifier>uber</classifier> - <version>2.5.4</version> - <scope>test</scope> - </dependency> </dependencies> <profiles> @@ -249,6 +234,9 @@ <includes> <include>**/*AllITs.java</include> </includes> + <systemPropertyVariables> + <my.system.property>foo</my.system.property> + </systemPropertyVariables> </configuration> <executions> <execution> 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 0c400b920..ea632da58 100644 --- a/itests/src/test/java/org/apache/unomi/itests/BaseIT.java +++ b/itests/src/test/java/org/apache/unomi/itests/BaseIT.java @@ -42,6 +42,7 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.karaf.itests.KarafTestSupport; import org.apache.unomi.api.Item; import org.apache.unomi.api.conditions.Condition; import org.apache.unomi.api.rules.Rule; @@ -58,14 +59,11 @@ import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.CoreOptions; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; -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.extra.VMOption; import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; import org.ops4j.pax.exam.spi.reactors.PerSuite; import org.ops4j.pax.exam.util.Filter; -import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceEvent; import org.osgi.framework.ServiceListener; @@ -81,9 +79,6 @@ import javax.net.ssl.X509TrustManager; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; @@ -97,15 +92,10 @@ import java.util.Objects; import java.util.concurrent.CountDownLatch; import java.util.function.Predicate; import java.util.function.Supplier; +import java.util.stream.Stream; -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.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; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.*; /** * Base class for integration tests. @@ -114,13 +104,10 @@ import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceCo */ @RunWith(PaxExam.class) @ExamReactorStrategy(PerSuite.class) -public abstract class BaseIT { +public abstract class BaseIT extends KarafTestSupport { private final static Logger LOGGER = LoggerFactory.getLogger(BaseIT.class); - protected static final String HTTP_PORT = "8181"; - protected static final String URL = "http://localhost:" + HTTP_PORT; - protected static final String KARAF_DIR = "target/exam"; protected static final String UNOMI_KEY = "670c26d1cc413346c3b2fd9ce65dab41"; protected static final ContentType JSON_CONTENT_TYPE = ContentType.create("application/json"); protected static final String BASE_URL = "http://localhost"; @@ -198,55 +185,53 @@ public abstract class BaseIT { Thread.sleep(1000); } - @Configuration - public Option[] config() throws InterruptedException { - - MavenArtifactUrlReference karafUrl = maven().groupId("org.apache.unomi").artifactId("unomi").type("tar.gz").versionAsInProject(); - - List<Option> options = new ArrayList<>(); + @Override + public MavenArtifactUrlReference getKarafDistribution() { + return CoreOptions.maven().groupId("org.apache.unomi").artifactId("unomi").versionAsInProject().type("tar.gz"); + } - Option[] commonOptions = new Option[] { - karafDistributionConfiguration().frameworkUrl(karafUrl).unpackDirectory(new File(KARAF_DIR)).useDeployFolder(true), + @Configuration + public Option[] config() { + System.out.println("==== Configuring container"); + Option[] options = new Option[]{ replaceConfigurationFile("etc/org.apache.unomi.router.cfg", new File("src/test/resources/org.apache.unomi.router.cfg")), replaceConfigurationFile("data/tmp/1-basic-test.csv", new File("src/test/resources/1-basic-test.csv")), replaceConfigurationFile("data/tmp/recurrent_import/2-surfers-test.csv", new File("src/test/resources/2-surfers-test.csv")), - replaceConfigurationFile("data/tmp/recurrent_import/3-surfers-overwrite-test.csv", - new File("src/test/resources/3-surfers-overwrite-test.csv")), - replaceConfigurationFile("data/tmp/recurrent_import/4-surfers-delete-test.csv", - new File("src/test/resources/4-surfers-delete-test.csv")), + replaceConfigurationFile("data/tmp/recurrent_import/3-surfers-overwrite-test.csv", new File("src/test/resources/3-surfers-overwrite-test.csv")), + replaceConfigurationFile("data/tmp/recurrent_import/4-surfers-delete-test.csv", new File("src/test/resources/4-surfers-delete-test.csv")), replaceConfigurationFile("data/tmp/recurrent_import/5-ranking-test.csv", new File("src/test/resources/5-ranking-test.csv")), replaceConfigurationFile("data/tmp/recurrent_import/6-actors-test.csv", new File("src/test/resources/6-actors-test.csv")), replaceConfigurationFile("data/tmp/testLogin.json", new File("src/test/resources/testLogin.json")), replaceConfigurationFile("data/tmp/testCopyProperties.json", new File("src/test/resources/testCopyProperties.json")), - replaceConfigurationFile("data/tmp/testCopyPropertiesWithoutSystemTags.json", - new File("src/test/resources/testCopyPropertiesWithoutSystemTags.json")), - replaceConfigurationFile("data/tmp/testLoginEventCondition.json", - new File("src/test/resources/testLoginEventCondition.json")), - replaceConfigurationFile("data/tmp/testClickEventCondition.json", - new File("src/test/resources/testClickEventCondition.json")), + replaceConfigurationFile("data/tmp/testCopyPropertiesWithoutSystemTags.json", new File("src/test/resources/testCopyPropertiesWithoutSystemTags.json")), + replaceConfigurationFile("data/tmp/testLoginEventCondition.json", new File("src/test/resources/testLoginEventCondition.json")), + replaceConfigurationFile("data/tmp/testClickEventCondition.json", new File("src/test/resources/testClickEventCondition.json")), replaceConfigurationFile("data/tmp/testRuleGroovyAction.json", new File("src/test/resources/testRuleGroovyAction.json")), - replaceConfigurationFile("data/tmp/groovy/UpdateAddressAction.groovy", - new File("src/test/resources/groovy/UpdateAddressAction.groovy")), keepRuntimeFolder(), - // configureConsole().ignoreLocalConsole(), - logLevel(LogLevel.INFO), - editConfigurationFilePut("etc/custom.system.properties", "org.apache.unomi.graphql.feature.activated", "true"), + replaceConfigurationFile("data/tmp/groovy/UpdateAddressAction.groovy", new File("src/test/resources/groovy/UpdateAddressAction.groovy")), + editConfigurationFilePut("etc/org.ops4j.pax.logging.cfg", "log4j2.rootLogger.level", "INFO"), editConfigurationFilePut("etc/org.apache.karaf.features.cfg", "serviceRequirements", "disable"), - // editConfigurationFilePut("etc/org.ops4j.pax.web.cfg", "org.osgi.service.http.port", HTTP_PORT), - // systemProperty("org.osgi.service.http.port").value(HTTP_PORT), + editConfigurationFilePut("etc/system.properties", "my.system.property", System.getProperty("my.system.property")), + editConfigurationFilePut("etc/custom.system.properties", "org.apache.unomi.graphql.feature.activated", "true"), + editConfigurationFilePut("etc/custom.system.properties", "org.apache.unomi.elasticsearch.cluster.name", "contextElasticSearchITests"), + editConfigurationFilePut("etc/custom.system.properties", "org.apache.unomi.elasticsearch.addresses", "localhost:9400"), + editConfigurationFilePut("etc/custom.system.properties", "org.apache.unomi.elasticsearch.index.prefix", "itest"), + systemProperty("org.ops4j.pax.exam.rbc.rmi.port").value("1199"), - systemProperty("org.apache.unomi.itests.elasticsearch.transport.port").value("9500"), - systemProperty("org.apache.unomi.itests.elasticsearch.cluster.name").value("contextElasticSearchITests"), - systemProperty("org.apache.unomi.itests.elasticsearch.http.port").value("9400"), - systemProperty("org.apache.unomi.itests.elasticsearch.bootstrap.seccomp").value("false"), systemProperty("org.apache.unomi.hazelcast.group.name").value("cellar"), systemProperty("org.apache.unomi.hazelcast.group.password").value("pass"), systemProperty("org.apache.unomi.hazelcast.network.port").value("5701"), 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"), CoreOptions.bundleStartLevel(100), CoreOptions.frameworkStartLevel(100) }; + systemProperty("unomi.autoStart").value("true"), - options.addAll(Arrays.asList(commonOptions)); + logLevel(LogLevel.INFO), + keepRuntimeFolder(), + CoreOptions.bundleStartLevel(100), + CoreOptions.frameworkStartLevel(100) + }; + List<Option> karafOptions = new ArrayList<>(); + karafOptions.addAll(Arrays.asList(options)); String karafDebug = System.getProperty("it.karaf.debug"); if (karafDebug != null) { @@ -265,52 +250,17 @@ public abstract class BaseIT { } } } - options.add(0, debugConfiguration(port, hold)); - } - - // Jacoco setup - final String agentFile = System.getProperty("user.dir") + "/target/jacoco/lib/jacocoagent.jar"; - Path path = Paths.get(agentFile); - if (Files.exists(path)) { - final String jacocoOption = "-javaagent:" + agentFile + "=destfile=" + System.getProperty("user.dir") - + "/target/jacoco.exec,includes=org.apache.unomi.*"; - LOGGER.info("set jacoco java agent: {}", jacocoOption); - options.add(new VMOption(jacocoOption)); - } else { - LOGGER.warn("Unable to set jacoco agent as {} was not found", agentFile); + karafOptions.add(0, debugConfiguration(port, hold)); } String customLogging = System.getProperty("it.karaf.customLogging"); if (customLogging != null) { String[] customLoggingParts = customLogging.split(":"); - options.add(editConfigurationFilePut("etc/org.ops4j.pax.logging.cfg", "log4j2.logger.customLogging.name", customLoggingParts[0])); - options.add(editConfigurationFilePut("etc/org.ops4j.pax.logging.cfg", "log4j2.logger.customLogging.level", customLoggingParts[1])); - } - - if (JavaVersionUtil.getMajorVersion() >= 9) { - Option[] jdk9PlusOptions = new Option[] { new VMOption("--add-reads=java.xml=java.logging"), - new VMOption("--add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED"), - new VMOption("--patch-module"), - new VMOption("java.base=lib/endorsed/org.apache.karaf.specs.locator-" + System.getProperty("karaf.version") + ".jar"), - new VMOption("--patch-module"), - new VMOption("java.xml=lib/endorsed/org.apache.karaf.specs.java.xml-" + System.getProperty("karaf.version") + ".jar"), - new VMOption("--add-opens"), new VMOption("java.base/java.security=ALL-UNNAMED"), new VMOption("--add-opens"), - new VMOption("java.base/java.net=ALL-UNNAMED"), new VMOption("--add-opens"), - new VMOption("java.base/java.lang=ALL-UNNAMED"), new VMOption("--add-opens"), - new VMOption("java.base/java.util=ALL-UNNAMED"), new VMOption("--add-opens"), - new VMOption("java.naming/javax.naming.spi=ALL-UNNAMED"), new VMOption("--add-opens"), - new VMOption("java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED"), - new VMOption("--add-exports=java.base/sun.net.www.protocol.http=ALL-UNNAMED"), - new VMOption("--add-exports=java.base/sun.net.www.protocol.https=ALL-UNNAMED"), - new VMOption("--add-exports=java.base/sun.net.www.protocol.jar=ALL-UNNAMED"), - new VMOption("--add-exports=jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED"), new VMOption("-classpath"), - new VMOption("lib/jdk9plus/*" + File.pathSeparator + "lib/boot/*") - - }; - options.addAll(Arrays.asList(jdk9PlusOptions)); + karafOptions.add(editConfigurationFilePut("etc/org.ops4j.pax.logging.cfg", "log4j2.logger.customLogging.name", customLoggingParts[0])); + karafOptions.add(editConfigurationFilePut("etc/org.ops4j.pax.logging.cfg", "log4j2.logger.customLogging.level", customLoggingParts[1])); } - return options.toArray(new Option[0]); + return Stream.of(super.config(), karafOptions.toArray(new Option[karafOptions.size()])).flatMap(Stream::of).toArray(Option[]::new); } protected <T> T keepTrying(String failMessage, Supplier<T> call, Predicate<T> predicate, int timeout, int retries) @@ -355,7 +305,11 @@ public abstract class BaseIT { protected String bundleResourceAsString(final String resourcePath) throws IOException { final java.net.URL url = bundleContext.getBundle().getResource(resourcePath); if (url != null) { - return IOUtils.toString(url); + try (InputStream stream = url.openStream()) { + return IOUtils.toString(stream); + } catch (final Exception e) { + throw new RuntimeException(e); + } } else { return null; } @@ -445,7 +399,7 @@ public abstract class BaseIT { } public String getFullUrl(String url) throws Exception { - return BASE_URL + ":" + HTTP_PORT + url; + return BASE_URL + ":" + getHttpPort() + url; } protected <T> T get(final String url, Class<T> clazz) { diff --git a/itests/src/test/java/org/apache/unomi/itests/BasicIT.java b/itests/src/test/java/org/apache/unomi/itests/BasicIT.java index 819ce4495..8abdf0284 100644 --- a/itests/src/test/java/org/apache/unomi/itests/BasicIT.java +++ b/itests/src/test/java/org/apache/unomi/itests/BasicIT.java @@ -113,9 +113,15 @@ public class BasicIT extends BaseIT { } @Test - public void testContextJS() throws IOException { + public void simpleTest() throws Exception { + System.out.println("==== System Property in probe bundle: " + System.getProperty("my.system.property")); + assertContains("foo", System.getProperty("my.system.property")); + } + + @Test + public void testContextJS() throws Exception { LOGGER.info("Start test testContextJS"); - HttpUriRequest request = new HttpGet(URL + "/cxs/context.js?sessionId=" + SESSION_ID_0); + HttpUriRequest request = new HttpGet(getFullUrl("/cxs/context.js?sessionId=" + SESSION_ID_0)); request.setHeader("Content-Type", "application/json"); // The underlying HTTP connection is still held by the response object // to allow the response content to be streamed directly from the network socket. @@ -137,10 +143,10 @@ public class BasicIT extends BaseIT { } @Test - public void testContextJSONWithUrlParameter() throws IOException, InterruptedException { + public void testContextJSONWithUrlParameter() throws Exception { LOGGER.info("Start test testContextJSONWithUrlParameter"); ContextRequest contextRequest = new ContextRequest(); - HttpPost request = new HttpPost(URL + "/cxs/context.json?sessionId=" + SESSION_ID_1); + HttpPost request = new HttpPost(getFullUrl("/cxs/context.json?sessionId=" + SESSION_ID_1)); request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.create("application/json"))); executeContextJSONRequest(request, SESSION_ID_1); @@ -148,11 +154,11 @@ public class BasicIT extends BaseIT { } @Test - public void testContextJSON() throws IOException, InterruptedException { + public void testContextJSON() throws Exception { LOGGER.info("Start test testContextJSON"); ContextRequest contextRequest = new ContextRequest(); contextRequest.setSessionId(SESSION_ID_2); - HttpPost request = new HttpPost(URL + "/cxs/context.json"); + HttpPost request = new HttpPost(getFullUrl("/cxs/context.json")); request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.create("application/json"))); executeContextJSONRequest(request, SESSION_ID_2); @@ -160,7 +166,7 @@ public class BasicIT extends BaseIT { } @Test - public void testMultipleLoginOnSameBrowser() throws IOException, InterruptedException { + public void testMultipleLoginOnSameBrowser() throws Exception { LOGGER.info("Start test testMultipleLoginOnSameBrowser"); // Add login event condition @@ -180,7 +186,7 @@ public class BasicIT extends BaseIT { // First page view with the first visitor aka VISITOR_1 and SESSION_ID_3 ContextRequest contextRequestPageViewSession1 = getContextRequestWithPageViewEvent(sourceSite, SESSION_ID_3); - HttpPost requestPageView1 = new HttpPost(URL + "/cxs/context.json"); + HttpPost requestPageView1 = new HttpPost(getFullUrl("/cxs/context.json")); requestPageView1.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequestPageViewSession1), ContentType.create("application/json"))); TestUtils.RequestResponse requestResponsePageView1 = executeContextJSONRequest(requestPageView1, SESSION_ID_3); @@ -198,7 +204,7 @@ public class BasicIT extends BaseIT { // Create login event with VISITOR_1 ContextRequest contextRequestLoginVisitor1 = getContextRequestWithLoginEvent(sourceSite, loginEventPropertiesVisitor1, EMAIL_VISITOR_1, SESSION_ID_3); - HttpPost requestLoginVisitor1 = new HttpPost(URL + "/cxs/context.json"); + HttpPost requestLoginVisitor1 = new HttpPost(getFullUrl("/cxs/context.json")); requestLoginVisitor1.addHeader("Cookie", requestResponsePageView1.getCookieHeaderValue()); requestLoginVisitor1.addHeader("X-Unomi-Peer", UNOMI_KEY); requestLoginVisitor1.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequestLoginVisitor1), @@ -212,7 +218,7 @@ public class BasicIT extends BaseIT { Thread.sleep(1000); // Lets add a page view with VISITOR_1 to simulate reloading the page after login and be able to check the profile properties - HttpPost requestPageView2 = new HttpPost(URL + "/cxs/context.json"); + HttpPost requestPageView2 = new HttpPost(getFullUrl("/cxs/context.json")); requestPageView2.addHeader("Cookie", requestResponsePageView1.getCookieHeaderValue()); requestPageView2.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequestPageViewSession1), ContentType.create("application/json"))); @@ -227,7 +233,7 @@ public class BasicIT extends BaseIT { // Lets simulate a logout by requesting the context with a new page view event and a new session id // but we will send the cookie of the profile id from VISITOR_1 ContextRequest contextRequestPageViewSession2 = getContextRequestWithPageViewEvent(sourceSite, SESSION_ID_4); - HttpPost requestPageView3 = new HttpPost(URL + "/cxs/context.json"); + HttpPost requestPageView3 = new HttpPost(getFullUrl("/cxs/context.json")); requestPageView3.addHeader("Cookie", requestResponsePageView1.getCookieHeaderValue()); requestPageView3.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequestPageViewSession2), ContentType.create("application/json"))); @@ -252,7 +258,7 @@ public class BasicIT extends BaseIT { // Create login event with VISITOR_2 ContextRequest contextRequestLoginVisitor2 = getContextRequestWithLoginEvent(sourceSite, loginEventPropertiesVisitor2, EMAIL_VISITOR_2, SESSION_ID_4); - HttpPost requestLoginVisitor2 = new HttpPost(URL + "/cxs/context.json"); + HttpPost requestLoginVisitor2 = new HttpPost(getFullUrl("/cxs/context.json")); requestLoginVisitor2.addHeader("Cookie", requestResponsePageView1.getCookieHeaderValue()); requestLoginVisitor2.addHeader("X-Unomi-Peer", UNOMI_KEY); requestLoginVisitor2.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequestLoginVisitor2), @@ -266,7 +272,7 @@ public class BasicIT extends BaseIT { Thread.sleep(1000); // Lets add a page view with VISITOR_2 to simulate reloading the page after login - HttpPost requestPageView4 = new HttpPost(URL + "/cxs/context.json"); + HttpPost requestPageView4 = new HttpPost(getFullUrl("/cxs/context.json")); requestPageView4.addHeader("Cookie", requestResponseLoginVisitor2.getCookieHeaderValue()); requestPageView4.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequestPageViewSession2), ContentType.create("application/json"))); 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 830e995e7..edc09bb2b 100644 --- a/itests/src/test/java/org/apache/unomi/itests/ContextServletIT.java +++ b/itests/src/test/java/org/apache/unomi/itests/ContextServletIT.java @@ -179,7 +179,7 @@ public class ContextServletIT extends BaseIT { } @Test - public void testUpdateEventFromContextAuthorizedThirdParty_Success() throws IOException, InterruptedException { + public void testUpdateEventFromContextAuthorizedThirdParty_Success() throws Exception { //Arrange String eventId = "test-event-id-" + System.currentTimeMillis(); String sessionId = "test-session-id"; @@ -205,7 +205,7 @@ public class ContextServletIT extends BaseIT { ContextRequest contextRequest = new ContextRequest(); contextRequest.setSessionId(session.getItemId()); contextRequest.setEvents(Arrays.asList(event)); - HttpPost request = new HttpPost(URL + CONTEXT_URL); + HttpPost request = new HttpPost(getFullUrl(CONTEXT_URL)); request.addHeader(THIRD_PARTY_HEADER_NAME, UNOMI_KEY); request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.APPLICATION_JSON)); TestUtils.executeContextJSONRequest(request, sessionId); @@ -217,7 +217,7 @@ public class ContextServletIT extends BaseIT { } @Test - public void testUpdateEventFromContextUnAuthorizedThirdParty_Fail() throws IOException, InterruptedException { + public void testUpdateEventFromContextUnAuthorizedThirdParty_Fail() throws Exception { //Arrange String eventId = "test-event-id-" + System.currentTimeMillis(); String sessionId = "test-session-id"; @@ -244,7 +244,7 @@ public class ContextServletIT extends BaseIT { ContextRequest contextRequest = new ContextRequest(); contextRequest.setSessionId(session.getItemId()); contextRequest.setEvents(Arrays.asList(event)); - HttpPost request = new HttpPost(URL + CONTEXT_URL); + HttpPost request = new HttpPost(getFullUrl(CONTEXT_URL)); request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.APPLICATION_JSON)); TestUtils.executeContextJSONRequest(request, sessionId); @@ -255,7 +255,7 @@ public class ContextServletIT extends BaseIT { } @Test - public void testUpdateEventFromContextAuthorizedThirdPartyNoItemID_Fail() throws IOException, InterruptedException { + public void testUpdateEventFromContextAuthorizedThirdPartyNoItemID_Fail() throws Exception { //Arrange String eventId = "test-event-id-" + System.currentTimeMillis(); String sessionId = "test-session-id"; @@ -276,7 +276,7 @@ public class ContextServletIT extends BaseIT { ContextRequest contextRequest = new ContextRequest(); contextRequest.setSessionId(session.getItemId()); contextRequest.setEvents(Arrays.asList(event)); - HttpPost request = new HttpPost(URL + CONTEXT_URL); + HttpPost request = new HttpPost(getFullUrl(CONTEXT_URL)); request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.APPLICATION_JSON)); TestUtils.executeContextJSONRequest(request, sessionId); @@ -288,7 +288,7 @@ public class ContextServletIT extends BaseIT { } @Test - public void testCreateEventsWithNoTimestampParam_profileAddedToSegment() throws IOException, InterruptedException { + public void testCreateEventsWithNoTimestampParam_profileAddedToSegment() throws Exception { //Arrange String sessionId = "test-session-id"; String scope = TEST_SCOPE; @@ -301,7 +301,7 @@ public class ContextServletIT extends BaseIT { contextRequest.setSessionId(sessionId); contextRequest.setRequireSegments(true); contextRequest.setEvents(Arrays.asList(event)); - HttpPost request = new HttpPost(URL + CONTEXT_URL); + HttpPost request = new HttpPost(getFullUrl(CONTEXT_URL)); request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.APPLICATION_JSON)); String cookieHeaderValue = TestUtils.executeContextJSONRequest(request, sessionId).getCookieHeaderValue(); @@ -320,14 +320,14 @@ public class ContextServletIT extends BaseIT { } @Test - public void testCreateEventWithTimestampParam_pastEvent_profileIsNotAddedToSegment() throws IOException, InterruptedException { + public void testCreateEventWithTimestampParam_pastEvent_profileIsNotAddedToSegment() throws Exception { //Arrange String sessionId = "test-session-id"; String scope = TEST_SCOPE; Event event = new Event(); event.setEventType(TEST_EVENT_TYPE); event.setScope(scope); - String regularURI = URL + CONTEXT_URL; + String regularURI = getFullUrl(CONTEXT_URL); long oldTimestamp = LocalDateTime.now(ZoneId.of("UTC")).minusDays(SEGMENT_NUMBER_OF_DAYS + 1).toInstant(ZoneOffset.UTC) .toEpochMilli(); String customTimestampURI = regularURI + "?timestamp=" + oldTimestamp; @@ -353,14 +353,14 @@ public class ContextServletIT extends BaseIT { } @Test - public void testCreateEventWithTimestampParam_futureEvent_profileIsNotAddedToSegment() throws IOException, InterruptedException { + public void testCreateEventWithTimestampParam_futureEvent_profileIsNotAddedToSegment() throws Exception { //Arrange String sessionId = "test-session-id"; String scope = TEST_SCOPE; Event event = new Event(); event.setEventType(TEST_EVENT_TYPE); event.setScope(scope); - String regularURI = URL + CONTEXT_URL; + String regularURI = getFullUrl(CONTEXT_URL); long futureTimestamp = LocalDateTime.now(ZoneId.of("UTC")).plusDays(1).toInstant(ZoneOffset.UTC).toEpochMilli(); String customTimestampURI = regularURI + "?timestamp=" + futureTimestamp; @@ -386,7 +386,7 @@ public class ContextServletIT extends BaseIT { } @Test - public void testCreateEventWithProfileId_Success() throws IOException, InterruptedException { + public void testCreateEventWithProfileId_Success() throws Exception { //Arrange String eventId = "test-event-id-" + System.currentTimeMillis(); String eventType = "test-event-type"; @@ -399,7 +399,7 @@ public class ContextServletIT extends BaseIT { contextRequest.setEvents(Arrays.asList(event)); //Act - HttpPost request = new HttpPost(URL + CONTEXT_URL); + HttpPost request = new HttpPost(getFullUrl(CONTEXT_URL)); request.addHeader(THIRD_PARTY_HEADER_NAME, UNOMI_KEY); request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.APPLICATION_JSON)); TestUtils.executeContextJSONRequest(request); @@ -409,7 +409,7 @@ public class ContextServletIT extends BaseIT { } @Test - public void testCreateEventWithPropertiesValidation_Success() throws IOException, InterruptedException { + public void testCreateEventWithPropertiesValidation_Success() throws Exception { //Arrange String eventId = "valid-event-id-" + System.currentTimeMillis(); String profileId = "valid-profile-id"; @@ -426,7 +426,7 @@ public class ContextServletIT extends BaseIT { contextRequest.setEvents(Arrays.asList(event)); //Act - HttpPost request = new HttpPost(URL + CONTEXT_URL); + HttpPost request = new HttpPost(getFullUrl(CONTEXT_URL)); request.addHeader(THIRD_PARTY_HEADER_NAME, UNOMI_KEY); request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.APPLICATION_JSON)); TestUtils.executeContextJSONRequest(request); @@ -439,7 +439,7 @@ public class ContextServletIT extends BaseIT { } @Test - public void testCreateEventWithPropertyValueValidation_Failure() throws IOException, InterruptedException { + public void testCreateEventWithPropertyValueValidation_Failure() throws Exception { //Arrange String eventId = "invalid-event-value-id-" + System.currentTimeMillis(); String profileId = "invalid-profile-id"; @@ -456,7 +456,7 @@ public class ContextServletIT extends BaseIT { contextRequest.setEvents(Arrays.asList(event)); //Act - HttpPost request = new HttpPost(URL + CONTEXT_URL); + HttpPost request = new HttpPost(getFullUrl(CONTEXT_URL)); request.addHeader(THIRD_PARTY_HEADER_NAME, UNOMI_KEY); request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.APPLICATION_JSON)); TestUtils.executeContextJSONRequest(request); @@ -467,7 +467,7 @@ public class ContextServletIT extends BaseIT { } @Test - public void testCreateEventWithPropertyNameValidation_Failure() throws IOException, InterruptedException { + public void testCreateEventWithPropertyNameValidation_Failure() throws Exception { //Arrange String eventId = "invalid-event-prop-id-" + System.currentTimeMillis(); String profileId = "invalid-profile-id"; @@ -483,7 +483,7 @@ public class ContextServletIT extends BaseIT { contextRequest.setEvents(Arrays.asList(event)); //Act - HttpPost request = new HttpPost(URL + CONTEXT_URL); + HttpPost request = new HttpPost(getFullUrl(CONTEXT_URL)); request.addHeader(THIRD_PARTY_HEADER_NAME, UNOMI_KEY); request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.APPLICATION_JSON)); TestUtils.executeContextJSONRequest(request); @@ -494,7 +494,7 @@ public class ContextServletIT extends BaseIT { } @Test - public void testOGNLVulnerability() throws IOException, InterruptedException { + public void testOGNLVulnerability() throws Exception { File vulnFile = new File("target/vuln-file.txt"); if (vulnFile.exists()) { @@ -505,7 +505,7 @@ public class ContextServletIT extends BaseIT { Map<String, String> parameters = new HashMap<>(); parameters.put("VULN_FILE_PATH", vulnFileCanonicalPath); - HttpPost request = new HttpPost(URL + CONTEXT_URL); + HttpPost request = new HttpPost(getFullUrl(CONTEXT_URL)); request.setEntity( new StringEntity(getValidatedBundleJSON("security/ognl-payload-1.json", parameters), ContentType.APPLICATION_JSON)); TestUtils.executeContextJSONRequest(request); @@ -515,7 +515,7 @@ public class ContextServletIT extends BaseIT { } @Test - public void testMVELVulnerability() throws IOException, InterruptedException { + public void testMVELVulnerability() throws Exception { File vulnFile = new File("target/vuln-file.txt"); if (vulnFile.exists()) { @@ -526,7 +526,7 @@ public class ContextServletIT extends BaseIT { Map<String, String> parameters = new HashMap<>(); parameters.put("VULN_FILE_PATH", vulnFileCanonicalPath); - HttpPost request = new HttpPost(URL + CONTEXT_URL); + HttpPost request = new HttpPost(getFullUrl(CONTEXT_URL)); request.setEntity( new StringEntity(getValidatedBundleJSON("security/mvel-payload-1.json", parameters), ContentType.APPLICATION_JSON)); TestUtils.executeContextJSONRequest(request); @@ -536,21 +536,21 @@ public class ContextServletIT extends BaseIT { } @Test - public void testPersonalization() throws IOException, InterruptedException { + public void testPersonalization() throws Exception { Map<String, String> parameters = new HashMap<>(); - HttpPost request = new HttpPost(URL + CONTEXT_URL); + HttpPost request = new HttpPost(getFullUrl(CONTEXT_URL)); request.setEntity(new StringEntity(getValidatedBundleJSON("personalization.json", parameters), ContentType.APPLICATION_JSON)); TestUtils.RequestResponse response = TestUtils.executeContextJSONRequest(request); assertEquals("Invalid response code", 200, response.getStatusCode()); } @Test - public void testPersonalizationWithControlGroup() throws IOException, InterruptedException { + public void testPersonalizationWithControlGroup() throws Exception { Map<String, String> parameters = new HashMap<>(); parameters.put("storeInSession", "false"); - HttpPost request = new HttpPost(URL + CONTEXT_URL); + HttpPost request = new HttpPost(getFullUrl(CONTEXT_URL)); request.setEntity( new StringEntity(getValidatedBundleJSON("personalization-controlgroup.json", parameters), ContentType.APPLICATION_JSON)); TestUtils.RequestResponse response = TestUtils.executeContextJSONRequest(request); @@ -576,7 +576,7 @@ public class ContextServletIT extends BaseIT { // now let's test with session storage parameters.put("storeInSession", "true"); - request = new HttpPost(URL + CONTEXT_URL); + request = new HttpPost(getFullUrl(CONTEXT_URL)); request.setEntity( new StringEntity(getValidatedBundleJSON("personalization-controlgroup.json", parameters), ContentType.APPLICATION_JSON)); response = TestUtils.executeContextJSONRequest(request); @@ -627,7 +627,7 @@ public class ContextServletIT extends BaseIT { } @Test - public void testRequireScoring() throws IOException, InterruptedException { + public void testRequireScoring() throws Exception { Map<String, String> parameters = new HashMap<>(); String scoringSource = getValidatedBundleJSON("score1.json", parameters); @@ -639,7 +639,7 @@ public class ContextServletIT extends BaseIT { // first let's make sure everything works without the requireScoring parameter parameters = new HashMap<>(); - HttpPost request = new HttpPost(URL + CONTEXT_URL); + HttpPost request = new HttpPost(getFullUrl(CONTEXT_URL)); request.setEntity(new StringEntity(getValidatedBundleJSON("withoutRequireScores.json", parameters), ContentType.APPLICATION_JSON)); TestUtils.RequestResponse response = TestUtils.executeContextJSONRequest(request); assertEquals("Invalid response code", 200, response.getStatusCode()); @@ -650,7 +650,7 @@ public class ContextServletIT extends BaseIT { // now let's test adding it. parameters = new HashMap<>(); - request = new HttpPost(URL + CONTEXT_URL); + request = new HttpPost(getFullUrl(CONTEXT_URL)); request.setEntity(new StringEntity(getValidatedBundleJSON("withRequireScores.json", parameters), ContentType.APPLICATION_JSON)); response = TestUtils.executeContextJSONRequest(request); assertEquals("Invalid response code", 200, response.getStatusCode()); diff --git a/itests/src/test/java/org/apache/unomi/itests/InputValidationIT.java b/itests/src/test/java/org/apache/unomi/itests/InputValidationIT.java index 3ca188796..8eed7b4c9 100644 --- a/itests/src/test/java/org/apache/unomi/itests/InputValidationIT.java +++ b/itests/src/test/java/org/apache/unomi/itests/InputValidationIT.java @@ -82,25 +82,25 @@ public class InputValidationIT extends BaseIT { } @Test - public void test_param_EventsCollectorRequestNotNull() throws IOException { + public void test_param_EventsCollectorRequestNotNull() throws Exception { doPOSTRequestTest(EVENT_COLLECTOR_URL, null, null, 400, ERROR_MESSAGE_INVALID_DATA_RECEIVED); doGETRequestTest(EVENT_COLLECTOR_URL, null, null, 400, ERROR_MESSAGE_INVALID_DATA_RECEIVED); } @Test - public void test_param_EventsNotEmpty() throws IOException { + public void test_param_EventsNotEmpty() throws Exception { doPOSTRequestTest(EVENT_COLLECTOR_URL, null, "/validation/eventcollector_emptyEvents.json", 400, ERROR_MESSAGE_INVALID_DATA_RECEIVED); doGETRequestTest(EVENT_COLLECTOR_URL, null, "/validation/eventcollector_emptyEvents.json", 400, ERROR_MESSAGE_INVALID_DATA_RECEIVED); } @Test - public void test_param_SessionIDPattern() throws IOException { + public void test_param_SessionIDPattern() throws Exception { doPOSTRequestTest(EVENT_COLLECTOR_URL, null, "/validation/eventcollector_invalidSessionId.json", 400, ERROR_MESSAGE_INVALID_DATA_RECEIVED); doGETRequestTest(EVENT_COLLECTOR_URL, null, "/validation/eventcollector_invalidSessionId.json", 400, ERROR_MESSAGE_INVALID_DATA_RECEIVED); } @Test - public void test_eventCollector_valid() throws IOException, InterruptedException { + public void test_eventCollector_valid() throws Exception { // needed schema for event to be valid during tests schemaService.saveSchema(resourceAsString("schemas/schema-dummy.json")); schemaService.saveSchema(resourceAsString("schemas/schema-dummy-properties.json")); @@ -122,7 +122,7 @@ public class InputValidationIT extends BaseIT { } @Test - public void test_contextRequest_SessionIDPattern() throws IOException { + public void test_contextRequest_SessionIDPattern() throws Exception { doPOSTRequestTest(CONTEXT_JSON_URL, null, "/validation/contextRequest_invalidSessionId.json", 400, ERROR_MESSAGE_INVALID_DATA_RECEIVED); doPOSTRequestTest(CONTEXT_JS_URL, null, "/validation/contextRequest_invalidSessionId.json", 400, ERROR_MESSAGE_INVALID_DATA_RECEIVED); doGETRequestTest(CONTEXT_JSON_URL, null, "/validation/contextRequest_invalidSessionId.json", 400, ERROR_MESSAGE_INVALID_DATA_RECEIVED); @@ -130,7 +130,7 @@ public class InputValidationIT extends BaseIT { } @Test - public void test_contextRequest_ProfileIDPattern() throws IOException { + public void test_contextRequest_ProfileIDPattern() throws Exception { doPOSTRequestTest(CONTEXT_JSON_URL, null, "/validation/contextRequest_invalidProfileId.json", 400, ERROR_MESSAGE_INVALID_DATA_RECEIVED); doPOSTRequestTest(CONTEXT_JS_URL, null, "/validation/contextRequest_invalidProfileId.json", 400, ERROR_MESSAGE_INVALID_DATA_RECEIVED); doGETRequestTest(CONTEXT_JSON_URL, null, "/validation/contextRequest_invalidProfileId.json", 400, ERROR_MESSAGE_INVALID_DATA_RECEIVED); @@ -138,7 +138,7 @@ public class InputValidationIT extends BaseIT { } @Test - public void test_contextRequest_valid() throws IOException { + public void test_contextRequest_valid() throws Exception { doPOSTRequestTest(CONTEXT_JSON_URL, null, "/validation/contextRequest_valid.json", 200, null); doPOSTRequestTest(CONTEXT_JS_URL, null, "/validation/contextRequest_valid.json", 200, null); doGETRequestTest(CONTEXT_JSON_URL, null, "/validation/contextRequest_valid.json", 200, null); @@ -146,7 +146,7 @@ public class InputValidationIT extends BaseIT { } @Test - public void test_eventCollector_request_size_exceed_limit() throws IOException, InterruptedException { + public void test_eventCollector_request_size_exceed_limit() throws Exception { // needed schema for event to be valid during tests schemaService.saveSchema(resourceAsString("schemas/schema-dummy.json")); schemaService.saveSchema(resourceAsString("schemas/schema-dummy-properties.json")); @@ -168,7 +168,7 @@ public class InputValidationIT extends BaseIT { } @Test - public void test_contextJSON_SessionIDPattern() throws IOException { + public void test_contextJSON_SessionIDPattern() throws Exception { String baseUrl = CONTEXT_JS_URL; String queryString = "?sessionId=" + URLEncoder.encode("<script>alert();</script>", StandardCharsets.UTF_8.toString()); doPOSTRequestTest(baseUrl + queryString, null, null, 400, ERROR_MESSAGE_INVALID_DATA_RECEIVED); @@ -189,7 +189,7 @@ public class InputValidationIT extends BaseIT { } @Test - public void test_contextJSON_PersonaIdPattern() throws IOException { + public void test_contextJSON_PersonaIdPattern() throws Exception { String baseUrl = CONTEXT_JS_URL; String queryString = "?personaId=" + URLEncoder.encode("<script>alert();</script>", StandardCharsets.UTF_8.toString()); doPOSTRequestTest(baseUrl + queryString, null, null, 400, ERROR_MESSAGE_INVALID_DATA_RECEIVED); @@ -210,7 +210,7 @@ public class InputValidationIT extends BaseIT { } @Test - public void test_cookie_profileIdPattern() throws IOException { + public void test_cookie_profileIdPattern() throws Exception { Map<String, String> headers = new HashMap<>(); headers.put("Cookie", "context-profile-id=<script>alert();</script>"); doPOSTRequestTest(CONTEXT_JSON_URL, headers, null, 400, ERROR_MESSAGE_INVALID_DATA_RECEIVED); @@ -225,11 +225,11 @@ public class InputValidationIT extends BaseIT { doGETRequestTest(CONTEXT_JS_URL, headers, null, 200, null); } - private void doGETRequestTest(String uri, Map<String, String> headers, String entityResourcePath, int expectedHTTPStatusCode, String expectedErrorMessage) throws IOException { + private void doGETRequestTest(String uri, Map<String, String> headers, String entityResourcePath, int expectedHTTPStatusCode, String expectedErrorMessage) throws Exception { // test old servlets - performGETRequestTest(URL + uri, headers, entityResourcePath, expectedHTTPStatusCode, expectedErrorMessage); + performGETRequestTest(getFullUrl(uri), headers, entityResourcePath, expectedHTTPStatusCode, expectedErrorMessage); // test directly CXS endpoints - performGETRequestTest(URL + "/cxs" + uri, headers, entityResourcePath, expectedHTTPStatusCode, expectedErrorMessage); + performGETRequestTest(getFullUrl("/cxs" + uri), headers, entityResourcePath, expectedHTTPStatusCode, expectedErrorMessage); } private void performGETRequestTest(String url, Map<String, String> headers, String entityResourcePath, int expectedHTTPStatusCode, String expectedErrorMessage) throws IOException { @@ -240,11 +240,11 @@ public class InputValidationIT extends BaseIT { performRequest(new HttpGet(url), headers, expectedHTTPStatusCode, expectedErrorMessage); } - private void doPOSTRequestTest(String uri, Map<String, String> headers, String entityResourcePath, int expectedHTTPStatusCode, String expectedErrorMessage) throws IOException { + private void doPOSTRequestTest(String uri, Map<String, String> headers, String entityResourcePath, int expectedHTTPStatusCode, String expectedErrorMessage) throws Exception { // test old servlets - performPOSTRequestTest(URL + uri, headers, entityResourcePath, expectedHTTPStatusCode, expectedErrorMessage); + performPOSTRequestTest(getFullUrl(uri), headers, entityResourcePath, expectedHTTPStatusCode, expectedErrorMessage); // test directly CXS endpoints - performPOSTRequestTest(URL + "/cxs" + uri, headers, entityResourcePath, expectedHTTPStatusCode, expectedErrorMessage); + performPOSTRequestTest(getFullUrl("/cxs" + uri), headers, entityResourcePath, expectedHTTPStatusCode, expectedErrorMessage); } private void performPOSTRequestTest(String url, Map<String, String> headers, String entityResourcePath, int expectedHTTPStatusCode, String expectedErrorMessage) throws IOException { diff --git a/itests/src/test/java/org/apache/unomi/itests/JSONSchemaIT.java b/itests/src/test/java/org/apache/unomi/itests/JSONSchemaIT.java index 75f7d1310..0bf7b53ae 100644 --- a/itests/src/test/java/org/apache/unomi/itests/JSONSchemaIT.java +++ b/itests/src/test/java/org/apache/unomi/itests/JSONSchemaIT.java @@ -329,7 +329,7 @@ public class JSONSchemaIT extends BaseIT { } } - private Event sendEventAndWaitItsIndexed(String eventResourcePath) throws IOException, InterruptedException { + private Event sendEventAndWaitItsIndexed(String eventResourcePath) throws Exception { // build event collector request String eventMarker = UUID.randomUUID().toString(); HashMap<String, String> eventReplacements = new HashMap<>(); @@ -353,8 +353,8 @@ public class JSONSchemaIT extends BaseIT { return events.get(0); } - private void eventCollectorPost(String eventCollectorRequest) { - HttpPost request = new HttpPost(URL + EVENT_COLLECTOR_URL); + private void eventCollectorPost(String eventCollectorRequest) throws Exception { + HttpPost request = new HttpPost(getFullUrl(EVENT_COLLECTOR_URL)); request.addHeader("Content-Type", "application/json"); request.setEntity(new StringEntity(eventCollectorRequest, ContentType.create("application/json"))); CloseableHttpResponse response; diff --git a/itests/src/test/java/org/apache/unomi/itests/ProfileServiceWithoutOverwriteIT.java b/itests/src/test/java/org/apache/unomi/itests/ProfileServiceWithoutOverwriteIT.java index aa3a34c2d..32f442d9c 100644 --- a/itests/src/test/java/org/apache/unomi/itests/ProfileServiceWithoutOverwriteIT.java +++ b/itests/src/test/java/org/apache/unomi/itests/ProfileServiceWithoutOverwriteIT.java @@ -49,7 +49,7 @@ public class ProfileServiceWithoutOverwriteIT extends BaseIT { private final static String TEST_PROFILE_ID = "test-profile-id"; @Configuration - public Option[] config() throws InterruptedException { + public Option[] config() { List<Option> options = new ArrayList<>(); options.addAll(Arrays.asList(super.config())); options.add(systemProperty("org.apache.unomi.elasticsearch.throwExceptions").value("true")); diff --git a/itests/src/test/java/org/apache/unomi/itests/SecurityIT.java b/itests/src/test/java/org/apache/unomi/itests/SecurityIT.java index f76c61231..69f64d6d8 100644 --- a/itests/src/test/java/org/apache/unomi/itests/SecurityIT.java +++ b/itests/src/test/java/org/apache/unomi/itests/SecurityIT.java @@ -54,7 +54,7 @@ public class SecurityIT extends BaseIT { } @Test - public void testOGNLInjection() throws IOException { + public void testOGNLInjection() throws Exception { ContextRequest contextRequest = new ContextRequest(); List<PersonalizationService.PersonalizationRequest> personalizations = new ArrayList<>(); PersonalizationService.PersonalizationRequest personalizationRequest = new PersonalizationService.PersonalizationRequest(); @@ -92,7 +92,7 @@ public class SecurityIT extends BaseIT { contextRequest.setPersonalizations(personalizations); contextRequest.setSessionId(SESSION_ID); - HttpPost request = new HttpPost(URL + "/cxs/context.json"); + HttpPost request = new HttpPost(getFullUrl("/cxs/context.json")); request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.create("application/json"))); TestUtils.RequestResponse response = executeContextJSONRequest(request, SESSION_ID); diff --git a/itests/src/test/java/org/apache/unomi/itests/graphql/BaseGraphQLIT.java b/itests/src/test/java/org/apache/unomi/itests/graphql/BaseGraphQLIT.java index 9b8ff09cf..f1c4a077a 100644 --- a/itests/src/test/java/org/apache/unomi/itests/graphql/BaseGraphQLIT.java +++ b/itests/src/test/java/org/apache/unomi/itests/graphql/BaseGraphQLIT.java @@ -44,25 +44,23 @@ import java.util.regex.Pattern; @ExamReactorStrategy(PerSuite.class) public abstract class BaseGraphQLIT extends BaseIT { - protected static final String GRAPHQL_ENDPOINT = URL + "/graphql"; - protected static final ContentType JSON_CONTENT_TYPE = ContentType.create("application/json"); @Inject protected BundleContext bundleContext; - protected CloseableHttpResponse postAnonymous(final String resource) throws IOException { + protected CloseableHttpResponse postAnonymous(final String resource) throws Exception { return postAs(resource, null, null); } - protected CloseableHttpResponse post(final String resource) throws IOException { + protected CloseableHttpResponse post(final String resource) throws Exception { return postAs(resource, "karaf", "karaf"); } - protected CloseableHttpResponse postAs(final String resource, final String username, final String password) throws IOException { + protected CloseableHttpResponse postAs(final String resource, final String username, final String password) throws Exception { final String resourceAsString = resourceAsString(resource); - final HttpPost request = new HttpPost(GRAPHQL_ENDPOINT); + final HttpPost request = new HttpPost(getFullUrl("/graphql")); request.setEntity(new StringEntity(resourceAsString, JSON_CONTENT_TYPE)); diff --git a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLEventIT.java b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLEventIT.java index 5c9e02d0c..bd7e0e526 100644 --- a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLEventIT.java +++ b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLEventIT.java @@ -61,7 +61,7 @@ public class GraphQLEventIT extends BaseGraphQLIT { @Test - public void testGetEvent_notExists() throws IOException { + public void testGetEvent_notExists() throws Exception { try (CloseableHttpResponse response = post("graphql/event/get-event-not-exists.json")) { final ResponseContext context = ResponseContext.parse(response.getEntity()); @@ -70,7 +70,7 @@ public class GraphQLEventIT extends BaseGraphQLIT { } @Test - public void testGetEvent() throws IOException, InterruptedException { + public void testGetEvent() throws Exception { final Event event = createEvent(eventID, profile); refreshPersistence(); @@ -84,7 +84,7 @@ public class GraphQLEventIT extends BaseGraphQLIT { } @Test - public void testFindEvents() throws IOException, InterruptedException { + public void testFindEvents() throws Exception { createEvent(eventID, profile); createEvent("event-2", profile); final Profile profile2 = new Profile("profile-2"); @@ -102,7 +102,7 @@ public class GraphQLEventIT extends BaseGraphQLIT { } @Test - public void testProcessEvents() throws IOException { + public void testProcessEvents() throws Exception { final Profile originalProfile = persistenceService.load(profileID, Profile.class); Assert.assertNull(originalProfile.getProperty("firstName")); Assert.assertNull(originalProfile.getProperty("lastName")); diff --git a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLProfileIT.java b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLProfileIT.java index 867b6543e..1ea820509 100644 --- a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLProfileIT.java +++ b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLProfileIT.java @@ -40,7 +40,7 @@ public class GraphQLProfileIT extends BaseGraphQLIT { } @Test - public void testGetProfile_WithoutCreation() throws IOException { + public void testGetProfile_WithoutCreation() throws Exception { try (CloseableHttpResponse response = post("graphql/profile/get-profile-without-creation.json")) { final ResponseContext context = ResponseContext.parse(response.getEntity()); @@ -49,7 +49,7 @@ public class GraphQLProfileIT extends BaseGraphQLIT { } @Test - public void testGetProfile_WithCreation() throws IOException { + public void testGetProfile_WithCreation() throws Exception { try (CloseableHttpResponse response = post("graphql/profile/get-profile-with-creation.json")) { final ResponseContext context = ResponseContext.parse(response.getEntity()); diff --git a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLSegmentIT.java b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLSegmentIT.java index bed6367b4..5b6b9f88b 100644 --- a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLSegmentIT.java +++ b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLSegmentIT.java @@ -48,7 +48,7 @@ public class GraphQLSegmentIT extends BaseGraphQLIT { } @Test - public void testCreateThenGetAndDeleteSegment() throws IOException, InterruptedException { + public void testCreateThenGetAndDeleteSegment() throws Exception { try (CloseableHttpResponse response = post("graphql/segment/create-or-update-segment.json")) { final ResponseContext context = ResponseContext.parse(response.getEntity()); diff --git a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLSourceIT.java b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLSourceIT.java index a5a828fb3..a1d433135 100644 --- a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLSourceIT.java +++ b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLSourceIT.java @@ -33,7 +33,7 @@ public class GraphQLSourceIT extends BaseGraphQLIT { ScopeService scopeService; @Test - public void testCRUD() throws IOException, InterruptedException { + public void testCRUD() throws Exception { try (CloseableHttpResponse response = post("graphql/source/create-source.json")) { final ResponseContext context = ResponseContext.parse(response.getEntity()); diff --git a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLTopicIT.java b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLTopicIT.java index 96274c4b7..954d5c1b4 100644 --- a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLTopicIT.java +++ b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLTopicIT.java @@ -32,7 +32,7 @@ public class GraphQLTopicIT extends BaseGraphQLIT { protected TopicService topicService; @Test - public void testCRUD() throws IOException, InterruptedException { + public void testCRUD() throws Exception { try (CloseableHttpResponse response = post("graphql/topic/create-topic.json")) { final ResponseContext context = ResponseContext.parse(response.getEntity()); diff --git a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLWebSocketIT.java b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLWebSocketIT.java index 74a4ad8a4..bcef7ebc0 100644 --- a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLWebSocketIT.java +++ b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLWebSocketIT.java @@ -42,8 +42,6 @@ public class GraphQLWebSocketIT extends BaseGraphQLIT { private final static Logger LOGGER = LoggerFactory.getLogger(GraphQLWebSocketIT.class); - private static final String SUBSCRIPTION_ENDPOINT = "ws://localhost:" + HTTP_PORT + "/graphql"; - @Test public void testWebSocketConnectionSegment() throws Exception { WebSocketClient client = new WebSocketClient(); @@ -52,7 +50,7 @@ public class GraphQLWebSocketIT extends BaseGraphQLIT { LOGGER.info("Starting web socket client..."); client.start(); - URI echoUri = new URI(SUBSCRIPTION_ENDPOINT); + URI echoUri = new URI("ws://localhost:" + getHttpPort() + "/graphql"); ClientUpgradeRequest request = new ClientUpgradeRequest(); Future<Session> onConnected = client.connect(socket, echoUri, request); diff --git a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java index bf6efd9fa..cd5183232 100644 --- a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java +++ b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java @@ -459,17 +459,6 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService, bulkProcessorFlushInterval = System.getProperty(BULK_PROCESSOR_FLUSH_INTERVAL, bulkProcessorFlushInterval); bulkProcessorBackoffPolicy = System.getProperty(BULK_PROCESSOR_BACKOFF_POLICY, bulkProcessorBackoffPolicy); itemsMonthlyIndexed = itemsMonthlyIndexedOverride.equals("none") ? Collections.emptyList() : Arrays.asList(System.getProperty(MONTHLY_INDEX_ITEMS_MONTHLY_INDEXED, itemsMonthlyIndexedOverride).split(",").clone()); - // this property is used for integration tests, to make sure we don't conflict with an already running ElasticSearch instance. - if (System.getProperty("org.apache.unomi.itests.elasticsearch.http.port") != null) { - elasticSearchAddressList.clear(); - elasticSearchAddressList.add("localhost:" + System.getProperty("org.apache.unomi.itests.elasticsearch.http.port")); - logger.info("Overriding ElasticSearch address list from system property=" + elasticSearchAddressList); - } - // this property is used for integration tests, to make sure we don't conflict with an already running ElasticSearch instance. - if (System.getProperty("org.apache.unomi.itests.elasticsearch.cluster.name") != null) { - clusterName = System.getProperty("org.apache.unomi.itests.elasticsearch.cluster.name"); - logger.info("Overriding cluster name from system property=" + clusterName); - } buildClient(); diff --git a/pom.xml b/pom.xml index f9d867ca9..e801b3085 100644 --- a/pom.xml +++ b/pom.xml @@ -63,6 +63,7 @@ <inceptionYear>2014</inceptionYear> <properties> + <karaf.version>4.2.15</karaf.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <cxf.version>3.3.11</cxf.version> <version.jackson.core>2.10.5</version.jackson.core>