Skip to content
Snippets Groups Projects
Commit 427ca618 authored by srosse's avatar srosse
Browse files

OO-1523: pass the environment variables to maven -> arquillian -> openolat in the selenium tests

parent 8820af58
No related branches found
No related tags found
No related merge requests found
......@@ -65,11 +65,11 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<targetJdk>1.7</targetJdk>
<org.springframework.version>3.2.13.RELEASE</org.springframework.version>
<org.hibernate.version>4.3.8.Final</org.hibernate.version>
<org.hibernate.version>4.3.9.Final</org.hibernate.version>
<com.sun.jersey.version>1.17.1</com.sun.jersey.version>
<jackson.version>1.9.2</jackson.version>
<org.mysql.version>5.1.34</org.mysql.version>
<org.postgresql.version>9.4-1200-jdbc41</org.postgresql.version>
<org.postgresql.version>9.4-1201-jdbc41</org.postgresql.version>
<org.infinispan.version>6.0.2.Final</org.infinispan.version>
<lucene.version>4.8.0</lucene.version>
<version.selenium>2.43.1</version.selenium>
......@@ -1260,6 +1260,15 @@
<forkMode>always</forkMode>
<systemProperties>
<profile>${test.env}</profile>
<test.env.db.name>${test.env.db.name}</test.env.db.name>
<test.env.db.user>${test.env.db.user}</test.env.db.user>
<test.env.db.pass>${test.env.db.pass}</test.env.db.pass>
<test.env.db.host.port>${test.env.db.host.port}</test.env.db.host.port>
<test.env.db.postgresql.user>${test.env.db.postgresql.user}</test.env.db.postgresql.user>
<test.env.db.postgresql.pass>${test.env.db.postgresql.pass}</test.env.db.postgresql.pass>
<test.env.db.postgresql.host.port>${test.env.db.postgresql.host.port}</test.env.db.postgresql.host.port>
<test.env.instance.id>${test.env.instance.id}</test.env.instance.id>
<test.env.jmx.rmi.port.0>${test.env.jmx.rmi.port.0}</test.env.jmx.rmi.port.0>
<arquillian.launch>tomcat-7-managed</arquillian.launch>
</systemProperties>
<testNGArtifactName>none:none</testNGArtifactName>
......
......@@ -197,8 +197,6 @@
<constructor-arg>
<props>
<prop key="hibernate.connection.provider_class">com.zaxxer.hikari.hibernate.HikariConnectionProvider</prop>
<!-- Min pool size -->
<prop key="hibernate.hikari.minimumPoolSize">${db.hibernate.hikari.minsize}</prop>
<!-- Max pool size , mysql-default value is 100, If you need to support more connections, you should set a larger value for this variable in mysql config -->
<prop key="hibernate.hikari.maximumPoolSize">${db.hibernate.hikari.maxsize}</prop>
<prop key="hibernate.hikari.minimumIdle">4</prop>
......
......@@ -21,11 +21,21 @@ package org.olat.test;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.jboss.shrinkwrap.api.ArchivePath;
import org.jboss.shrinkwrap.api.Filter;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.springframework.util.PropertyPlaceholderHelper;
public class ArquillianDeployments {
......@@ -52,14 +62,42 @@ public class ArquillianDeployments {
addResourceRecursive(new File(MAIN_JAVA), null, new JavaResourcesFilter(), archive);
addResourceRecursive(new File(MAIN_RSRC), null, new AllFileFilter(), archive);
addWebResourceRecursive(new File(WEBAPP), "static", new StaticFileFilter(), archive);
addOlatLocalProperties(archive);
archive.setWebXML(new File(WEBINF_TOMCAT, "web.xml"));
return archive;
}
public static WebArchive addOlatLocalProperties(WebArchive archive) {
String profile = System.getProperty("profile");
if(profile == null || profile.isEmpty()) {
profile = "mysql";
}
archive.addAsResource(new File("src/test/profile/" + profile, "olat.local.properties"), "olat.local.properties");
archive.setWebXML(new File(WEBINF_TOMCAT, "web.xml"));
return archive;
File barebonePropertiesFile = new File("src/test/profile/" + profile, "olat.local.properties");
PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}", ":", true);
Asset propertiesAsset = null;
try(InputStream inStream = new FileInputStream(barebonePropertiesFile)) {
Properties properties = new Properties();
properties.load(inStream);
List<String> propNames = new ArrayList<>(properties.stringPropertyNames());
Properties updatedProperties = new Properties();
for(String name:propNames) {
String value = properties.getProperty(name);
String replacedValue = helper.replacePlaceholders(value, new PropertyPlaceholderResolver(properties));
updatedProperties.setProperty(name, replacedValue);
}
StringWriter writer = new StringWriter();
updatedProperties.store(writer, "Replaced for Arquillian deployements");
propertiesAsset = new StringAsset(writer.toString());
} catch (IOException e) {
e.printStackTrace();
}
return archive.addAsResource(propertiesAsset, "olat.local.properties");
}
public static WebArchive addLibraries(WebArchive archive) {
......@@ -202,4 +240,31 @@ public class ArquillianDeployments {
return !exclude;
}
}
private static class PropertyPlaceholderResolver implements PropertyPlaceholderHelper.PlaceholderResolver {
private final Properties properties;
public PropertyPlaceholderResolver(Properties properties) {
this.properties = properties;
}
public String resolvePlaceholder(String placeholderName) {
try {
String propVal = System.getProperty(placeholderName);
if (propVal == null) {
// Fall back to searching the system environment.
propVal = System.getenv(placeholderName);
if(propVal == null) {
propVal = properties.getProperty(placeholderName);
}
}
return propVal;
}
catch (Throwable ex) {
System.err.println("Could not resolve placeholder '" + placeholderName + "' in as system property: " + ex);
return null;
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment