Upgraded all libraries, switched to npm, upgraded angular and jdk21
Locusworks Team/portal-webapp/pipeline/head There was a failure building this commit
Locusworks Team/portal-webapp/pipeline/head There was a failure building this commit
This commit is contained in:
1 parent
c2f8e20fad
commit
a6df549919
335 files changed
+10923
-12700
No files matched your search
@@ -14,9 +14,6 @@
|
||||
|
||||
<properties>
|
||||
<main.basedir>${project.parent.basedir}</main.basedir>
|
||||
<jackson.version>2.9.4</jackson.version>
|
||||
<leak-preventor.version>2.5.0</leak-preventor.version>
|
||||
<log4j.version>2.9.1</log4j.version>
|
||||
</properties>
|
||||
|
||||
<reporting>
|
||||
@@ -41,12 +38,12 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.5</version>
|
||||
<version>4.5.14</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpmime</artifactId>
|
||||
<version>4.5.5</version>
|
||||
<version>4.5.14</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
@@ -57,12 +54,12 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-dbcp2</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<version>2.14.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
<version>2.6.0</version>
|
||||
<version>2.13.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Apache http client -->
|
||||
@@ -83,4 +80,4 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.locusworks.portal.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -25,8 +26,8 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import net.locusworks.common.logger.ApplicationLogger;
|
||||
import net.locusworks.common.logger.ApplicationLoggerFactory;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||
import net.locusworks.portal.common.services.ConfigurationService;
|
||||
|
||||
/***
|
||||
@@ -40,8 +41,14 @@ public class PortalDataSource {
|
||||
|
||||
private static ApplicationLogger logger = ApplicationLoggerFactory.getLogger(PortalDataSource.class);
|
||||
|
||||
private static final String DRIVER = "com.mysql.cj.jdbc.Driver";
|
||||
private static final String JNDI_STRING = "jdbc:mysql://%s:%d%s";
|
||||
private static final String MYSQL_DRIVER = "com.mysql.cj.jdbc.Driver";
|
||||
private static final String MYSQL_JDBC_URL = "jdbc:mysql://%s:%d%s";
|
||||
private static final String H2_DRIVER = "org.h2.Driver";
|
||||
|
||||
public static final String DATABASE_DRIVER_PROPERTY = "portal.database.driver";
|
||||
public static final String DATABASE_URL_PROPERTY = "portal.database.url";
|
||||
public static final String DATABASE_USERNAME_PROPERTY = "portal.database.username";
|
||||
public static final String DATABASE_PASSWORD_PROPERTY = "portal.database.password";
|
||||
|
||||
private static Map<String, String> mysqlProperties;
|
||||
static {
|
||||
@@ -88,20 +95,22 @@ public class PortalDataSource {
|
||||
* @return A Datasource representing the connection
|
||||
* @throws Exception
|
||||
*/
|
||||
private static DataSource createDataSource(String url, String userName, String password) throws Exception {
|
||||
Class.forName(DRIVER).newInstance();
|
||||
private static DataSource createDataSource(String driver, String url, String userName, String password) throws Exception {
|
||||
Class.forName(driver).getDeclaredConstructor().newInstance();
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty("user", userName);
|
||||
props.setProperty("password", password);
|
||||
|
||||
List<String> params = mysqlProperties
|
||||
.entrySet()
|
||||
.stream()
|
||||
.map(prop -> String.format("%s=%s", prop.getKey(), prop.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
url = String.format("%s?%s", url, StringUtils.join(params, "&"));
|
||||
if (MYSQL_DRIVER.equals(driver)) {
|
||||
List<String> params = mysqlProperties
|
||||
.entrySet()
|
||||
.stream()
|
||||
.map(prop -> String.format("%s=%s", prop.getKey(), prop.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
url = String.format("%s?%s", url, StringUtils.join(params, "&"));
|
||||
}
|
||||
|
||||
//Create a connection factory that the pool will use to create connections
|
||||
ConnectionFactory cf = new DriverManagerConnectionFactory(url, props);
|
||||
@@ -115,7 +124,7 @@ public class PortalDataSource {
|
||||
poolConfig.setMaxTotal(100);
|
||||
|
||||
AbandonedConfig abandonConfig = new AbandonedConfig();
|
||||
abandonConfig.setRemoveAbandonedTimeout(60);
|
||||
abandonConfig.setRemoveAbandonedTimeout(Duration.ofSeconds(60));
|
||||
abandonConfig.setLogAbandoned(false);
|
||||
abandonConfig.setRemoveAbandonedOnBorrow(true);
|
||||
abandonConfig.setRemoveAbandonedOnMaintenance(true);
|
||||
@@ -124,8 +133,8 @@ public class PortalDataSource {
|
||||
GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(pcf, poolConfig);
|
||||
connectionPool.setTestOnBorrow(true);
|
||||
connectionPool.setTestWhileIdle(true);
|
||||
connectionPool.setTimeBetweenEvictionRunsMillis(10000);
|
||||
connectionPool.setMinEvictableIdleTimeMillis(1000);
|
||||
connectionPool.setDurationBetweenEvictionRuns(Duration.ofSeconds(10));
|
||||
connectionPool.setMinEvictableIdleDuration(Duration.ofSeconds(1));
|
||||
connectionPool.setAbandonedConfig(abandonConfig);
|
||||
pcf.setPool(connectionPool);
|
||||
|
||||
@@ -140,13 +149,28 @@ public class PortalDataSource {
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private DataSource createDataSource(Jndi jndi) throws Exception {
|
||||
private DataSource createDataSource(Jndi jndi) throws Exception {
|
||||
|
||||
if (dataSources.containsKey(jndi)) {
|
||||
return dataSources.get(jndi);
|
||||
}
|
||||
|
||||
String tail = null;
|
||||
String configuredUrl = System.getProperty(DATABASE_URL_PROPERTY);
|
||||
if (StringUtils.isNotBlank(configuredUrl)) {
|
||||
String driver = System.getProperty(DATABASE_DRIVER_PROPERTY, "org.h2.Driver");
|
||||
String userName = System.getProperty(DATABASE_USERNAME_PROPERTY, "sa");
|
||||
String password = System.getProperty(DATABASE_PASSWORD_PROPERTY, "");
|
||||
dataSources.put(jndi, createDataSource(driver, configuredUrl, userName, password));
|
||||
return dataSources.get(jndi);
|
||||
}
|
||||
|
||||
if (configurationService.isH2Database()) {
|
||||
dataSources.put(jndi, createDataSource(H2_DRIVER, configurationService.getH2Url(),
|
||||
configurationService.getH2Username(), configurationService.getH2Password()));
|
||||
return dataSources.get(jndi);
|
||||
}
|
||||
|
||||
String tail = null;
|
||||
boolean isRoot = false;
|
||||
switch (jndi) {
|
||||
case PORTAL_ROOT:
|
||||
@@ -163,9 +187,9 @@ public class PortalDataSource {
|
||||
String userName = isRoot ? configurationService.getDatabaseRootUsername() : configurationService.getDatabaseUsername();
|
||||
String passwd = isRoot? configurationService.getDatabaseRootPassword() : configurationService.getDatabasePassword();
|
||||
|
||||
String url = String.format(JNDI_STRING, configurationService.getDatabaseHost(), configurationService.getDatabasePort(), tail);
|
||||
|
||||
dataSources.put(jndi, createDataSource(url, userName, passwd));
|
||||
String url = String.format(MYSQL_JDBC_URL, configurationService.getDatabaseHost(), configurationService.getDatabasePort(), tail);
|
||||
|
||||
dataSources.put(jndi, createDataSource(MYSQL_DRIVER, url, userName, passwd));
|
||||
|
||||
return dataSources.get(jndi);
|
||||
}
|
||||
|
||||
@@ -6,8 +6,12 @@ package net.locusworks.portal.common.enums;
|
||||
* @since 1.0.0-RELEASE
|
||||
* @version 1.0
|
||||
*/
|
||||
public enum Configuration {
|
||||
DB_ROOT_USER("dbRootUser"),
|
||||
public enum Configuration {
|
||||
DB_TYPE("dbType"),
|
||||
H2_URL("h2Url"),
|
||||
H2_USER("h2Username"),
|
||||
H2_PASSWORD("h2Password"),
|
||||
DB_ROOT_USER("dbRootUser"),
|
||||
DB_ROOT_PASSWORD("dbRootPassword"),
|
||||
DB_USER("dbUsername"),
|
||||
DB_PASSWORD("dbPassword"),
|
||||
@@ -105,4 +109,4 @@ public enum Configuration {
|
||||
public static boolean notIn(String value, Configuration... confTypes) {
|
||||
return !in(value, confTypes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@ import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import net.locusworks.common.logger.ApplicationLogger;
|
||||
import net.locusworks.common.logger.ApplicationLoggerFactory;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||
|
||||
/**
|
||||
* Class to handle http(s) connections
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package net.locusworks.portal.common.services;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import net.locusworks.common.crypto.AES;
|
||||
import net.locusworks.crypto.AES;
|
||||
import net.locusworks.common.utils.Utils;
|
||||
import net.locusworks.portal.common.triggers.SeedTrigger;
|
||||
|
||||
@@ -50,9 +50,8 @@ public class AESService implements ApplicationListener<SeedTrigger>{
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
try {
|
||||
confService.init(); //initialize our conf file to pick up the latest changes if any
|
||||
//Check to see if the environment variable is set first
|
||||
try {
|
||||
//Check to see if the environment variable is set first
|
||||
seedLoc = System.getProperty(PORTAL_AES_SEED) == null ? System.getenv(PORTAL_AES_SEED) : System.getProperty(PORTAL_AES_SEED);
|
||||
if (seedLoc == null) {
|
||||
//If it can't find it in the environment variable load it from the properties file
|
||||
@@ -176,6 +175,6 @@ public class AESService implements ApplicationListener<SeedTrigger>{
|
||||
@Override
|
||||
public void onApplicationEvent(SeedTrigger event) {
|
||||
String seed = event.getSeed();
|
||||
this.aes.setSeed(seed);
|
||||
this.aes = AES.createInstance(seed);
|
||||
}
|
||||
}
|
||||
}
|
||||
+81
-39
@@ -1,22 +1,25 @@
|
||||
package net.locusworks.portal.common.services;
|
||||
|
||||
import static net.locusworks.portal.common.utils.Constants.PROPERTIES_FILE;
|
||||
import static net.locusworks.portal.common.utils.Constants.PROPERTIES_FILE;
|
||||
import static net.locusworks.portal.common.utils.Constants.getPortalHome;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Enumeration;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import javax.annotation.PostConstruct;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import net.locusworks.common.configuration.PropertiesManager;
|
||||
import net.locusworks.common.logger.ApplicationLogger;
|
||||
import net.locusworks.common.logger.ApplicationLoggerFactory;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||
import net.locusworks.portal.common.enums.Configuration;
|
||||
import net.locusworks.portal.common.exceptions.PortalException;
|
||||
import net.locusworks.portal.json.ConfigurationRequest;
|
||||
@@ -41,8 +44,9 @@ public final class ConfigurationService {
|
||||
|
||||
private static ApplicationLogger logger = ApplicationLoggerFactory.getLogger(ConfigurationService.class);
|
||||
|
||||
@Autowired
|
||||
private AESService aesService;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private AESService aesService;
|
||||
|
||||
/**
|
||||
* Initialize the configuration service
|
||||
@@ -61,19 +65,14 @@ public final class ConfigurationService {
|
||||
throw ex;
|
||||
}
|
||||
|
||||
// create portalConf File object
|
||||
portalConf = new File(String.format("%s/conf/%s", System.getProperty("catalina.base"), PROPERTIES_FILE));
|
||||
|
||||
//Create a temporary key directory
|
||||
keyDir = String.format("%s/keys", System.getProperty("catalina.base"));
|
||||
File keyDirFile = new File(keyDir);
|
||||
if (!keyDirFile.exists()) {
|
||||
try {
|
||||
keyDirFile.mkdirs();
|
||||
} catch (Exception ex) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
// create portalConf File object
|
||||
File portalHome = getPortalHome().toFile();
|
||||
Files.createDirectories(portalHome.toPath());
|
||||
portalConf = new File(portalHome, PROPERTIES_FILE);
|
||||
|
||||
// Create the directory used for temporary private keys.
|
||||
keyDir = new File(portalHome, "keys").getAbsolutePath();
|
||||
Files.createDirectories(new File(keyDir).toPath());
|
||||
// initial config load
|
||||
loadConf();
|
||||
}
|
||||
@@ -88,7 +87,7 @@ public final class ConfigurationService {
|
||||
// and all default items will be added below and the file created
|
||||
logger.info("Loading config file: " + portalConf);
|
||||
try {
|
||||
configuration = PropertiesManager.loadConfiguration(portalConf);
|
||||
configuration = PropertiesManager.loadConfiguration(portalConf.toPath());
|
||||
} catch (Exception e) {
|
||||
logger.info("Config file: " + portalConf + " will be created from template");
|
||||
configuration = new Properties();
|
||||
@@ -107,7 +106,7 @@ public final class ConfigurationService {
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
PropertiesManager.saveConfiguration(configuration, portalConf, "Patch Repository properties file");
|
||||
PropertiesManager.saveConfiguration(configuration, portalConf.toPath(), "Patch Repository properties file");
|
||||
}
|
||||
|
||||
lastModified = portalConf.lastModified();
|
||||
@@ -118,8 +117,9 @@ public final class ConfigurationService {
|
||||
* @param confs Configuration property values to save
|
||||
* @throws Exception general exception
|
||||
*/
|
||||
public void saveToConf(Properties confs) throws Exception {
|
||||
PropertiesManager.saveConfiguration(confs, portalConf, "Patch Repository properties file");
|
||||
public void saveToConf(Properties confs) throws Exception {
|
||||
Files.createDirectories(portalConf.toPath().getParent());
|
||||
PropertiesManager.saveConfiguration(confs, portalConf.toPath(), "Patch Repository properties file");
|
||||
logger.info("Saved config file: " + portalConf + ", " + confs.size() + " entries");
|
||||
loadConf();
|
||||
}
|
||||
@@ -130,10 +130,35 @@ public final class ConfigurationService {
|
||||
* then checks the patchrepo.properties file
|
||||
* @return root database username
|
||||
*/
|
||||
public String getDatabaseRootUsername() {
|
||||
public String getDatabaseRootUsername() {
|
||||
String rootUser = System.getProperty(DB_ROOT_USER_PROPERTY);
|
||||
return rootUser != null ? rootUser : configuration.getProperty(Configuration.DB_ROOT_USER.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public String getDatabaseType() {
|
||||
String dbType = configuration.getProperty(Configuration.DB_TYPE.getValue(), "h2").trim().toLowerCase();
|
||||
if (!dbType.equals("h2") && !dbType.equals("mysql")) {
|
||||
throw new IllegalArgumentException("Unsupported dbType '" + dbType + "'; expected h2 or mysql");
|
||||
}
|
||||
return dbType;
|
||||
}
|
||||
|
||||
public boolean isH2Database() {
|
||||
return "h2".equals(getDatabaseType());
|
||||
}
|
||||
|
||||
public String getH2Url() {
|
||||
return replaceProperties(configuration.getProperty(Configuration.H2_URL.getValue()));
|
||||
}
|
||||
|
||||
public String getH2Username() {
|
||||
return configuration.getProperty(Configuration.H2_USER.getValue(), "sa");
|
||||
}
|
||||
|
||||
public String getH2Password() {
|
||||
String password = configuration.getProperty(Configuration.H2_PASSWORD.getValue(), "");
|
||||
return StringUtils.isBlank(password) ? "" : aesService.decrypt(password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the database root user password
|
||||
@@ -264,7 +289,19 @@ public final class ConfigurationService {
|
||||
for (Configuration type : types) {
|
||||
String key = type.getValue();
|
||||
String value = this.configuration.getProperty(key);
|
||||
switch(type) {
|
||||
switch(type) {
|
||||
case DB_TYPE:
|
||||
cr.setDbType(value);
|
||||
break;
|
||||
case H2_URL:
|
||||
cr.setH2Url(value);
|
||||
break;
|
||||
case H2_USER:
|
||||
cr.setH2Username(value);
|
||||
break;
|
||||
case H2_PASSWORD:
|
||||
cr.setH2Password(value);
|
||||
break;
|
||||
case CA_CERT_FILE:
|
||||
cr.setCaCertFile(value);
|
||||
break;
|
||||
@@ -330,15 +367,18 @@ public final class ConfigurationService {
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
public void updateEncryption(String newSeed) throws Exception {
|
||||
String newDBRootPassword = aesService.changeEncryptionValue(configuration.getProperty(Configuration.DB_ROOT_PASSWORD.getValue()), newSeed);
|
||||
String newDBPassword = aesService.changeEncryptionValue(configuration.getProperty(Configuration.DB_PASSWORD.getValue()), newSeed);
|
||||
String newCACertPassword = aesService.changeEncryptionValue(configuration.getProperty(Configuration.CA_CERT_PASSWORD.getValue()), newSeed);
|
||||
public void updateEncryption(String newSeed) throws Exception {
|
||||
String newDBRootPassword = aesService.changeEncryptionValue(configuration.getProperty(Configuration.DB_ROOT_PASSWORD.getValue()), newSeed);
|
||||
String newDBPassword = aesService.changeEncryptionValue(configuration.getProperty(Configuration.DB_PASSWORD.getValue()), newSeed);
|
||||
String h2Password = configuration.getProperty(Configuration.H2_PASSWORD.getValue(), "");
|
||||
String newH2Password = StringUtils.isBlank(h2Password) ? "" : aesService.changeEncryptionValue(h2Password, newSeed);
|
||||
String newCACertPassword = aesService.changeEncryptionValue(configuration.getProperty(Configuration.CA_CERT_PASSWORD.getValue()), newSeed);
|
||||
|
||||
ConfigurationRequest cr = getConfigurations(Configuration.values());
|
||||
cr.setCaCertPassword(newCACertPassword);
|
||||
cr.setDbRootPassword(newDBRootPassword);
|
||||
cr.setDbPassword(newDBPassword);
|
||||
cr.setDbRootPassword(newDBRootPassword);
|
||||
cr.setDbPassword(newDBPassword);
|
||||
cr.setH2Password(newH2Password);
|
||||
|
||||
saveConfiguration(cr, false);
|
||||
}
|
||||
@@ -388,7 +428,9 @@ public final class ConfigurationService {
|
||||
|
||||
changed = true;
|
||||
|
||||
fieldValue = encryptCreds && conf.is(Configuration.DB_ROOT_PASSWORD, Configuration.DB_PASSWORD, Configuration.CA_CERT_PASSWORD) ? aesService.encrypt(fieldValue) : fieldValue;
|
||||
fieldValue = encryptCreds && conf.is(Configuration.DB_ROOT_PASSWORD, Configuration.DB_PASSWORD,
|
||||
Configuration.H2_PASSWORD, Configuration.CA_CERT_PASSWORD) && StringUtils.isNotBlank(fieldValue)
|
||||
? aesService.encrypt(fieldValue) : fieldValue;
|
||||
|
||||
props.setProperty(fieldName, fieldValue);
|
||||
}
|
||||
@@ -417,4 +459,4 @@ public final class ConfigurationService {
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.locusworks.portal.common.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
@@ -22,6 +23,21 @@ public class Constants {
|
||||
public static final String TRUST_STORE_PATH = "javax.net.ssl.trustStore";
|
||||
public static final String TRUST_STORE_PASSWORD = "javax.net.ssl.trustStorePassword";
|
||||
|
||||
public static final String PROPERTIES_FILE = "portal.properties";
|
||||
|
||||
}
|
||||
public static final String PROPERTIES_FILE = "portal.properties";
|
||||
|
||||
public static final String PORTAL_HOME_PROPERTY = "portal.home";
|
||||
|
||||
public static final String PORTAL_HOME_ENVIRONMENT = "PORTAL_HOME";
|
||||
|
||||
public static Path getPortalHome() {
|
||||
String portalHome = System.getProperty(PORTAL_HOME_PROPERTY);
|
||||
if (portalHome == null || portalHome.isBlank()) {
|
||||
portalHome = System.getenv(PORTAL_HOME_ENVIRONMENT);
|
||||
}
|
||||
if (portalHome == null || portalHome.isBlank()) {
|
||||
portalHome = Path.of(System.getProperty("user.home"), ".portal").toString();
|
||||
}
|
||||
return Path.of(portalHome).toAbsolutePath().normalize();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package net.locusworks.portal.common;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class PortalDataSourceTest {
|
||||
|
||||
private PortalDataSource portalDataSource;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
System.setProperty(PortalDataSource.DATABASE_DRIVER_PROPERTY, "org.h2.Driver");
|
||||
System.setProperty(PortalDataSource.DATABASE_URL_PROPERTY,
|
||||
"jdbc:h2:mem:portal-test;MODE=MySQL;DATABASE_TO_LOWER=TRUE;DB_CLOSE_DELAY=-1");
|
||||
System.setProperty(PortalDataSource.DATABASE_USERNAME_PROPERTY, "sa");
|
||||
System.setProperty(PortalDataSource.DATABASE_PASSWORD_PROPERTY, "");
|
||||
portalDataSource = new PortalDataSource();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
portalDataSource.closeDataSources();
|
||||
System.clearProperty(PortalDataSource.DATABASE_DRIVER_PROPERTY);
|
||||
System.clearProperty(PortalDataSource.DATABASE_URL_PROPERTY);
|
||||
System.clearProperty(PortalDataSource.DATABASE_USERNAME_PROPERTY);
|
||||
System.clearProperty(PortalDataSource.DATABASE_PASSWORD_PROPERTY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createsInMemoryH2DataSourceForTests() throws Exception {
|
||||
try (Connection connection = portalDataSource.getPortalDataSource().getConnection();
|
||||
Statement statement = connection.createStatement()) {
|
||||
assertTrue(connection.getMetaData().getDatabaseProductName().startsWith("H2"));
|
||||
statement.execute("CREATE TABLE datasource_smoke_test (id INT PRIMARY KEY, name VARCHAR(50))");
|
||||
statement.executeUpdate("INSERT INTO datasource_smoke_test (id, name) VALUES (1, 'portal')");
|
||||
try (ResultSet results = statement.executeQuery("SELECT name FROM datasource_smoke_test WHERE id = 1")) {
|
||||
assertTrue(results.next());
|
||||
assertEquals("portal", results.getString(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user