Skip to content

Commit

Permalink
Read properties file in Java code to avoid having to set environment
Browse files Browse the repository at this point in the history
variables when running tests from the IDE.
  • Loading branch information
kaklakariada committed Oct 20, 2021
1 parent 9049e72 commit 5949a72
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
1 change: 0 additions & 1 deletion tableau-server-GUI-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemPropertiesFile>${project.basedir}/src/test/resources/credentials.properties</systemPropertiesFile>
<systemPropertyVariables>
<java.util.logging.config.file>src/test/resources/logging.properties</java.util.logging.config.file>
</systemPropertyVariables>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
package com.exasol.tableau;

import java.io.*;
import java.util.Properties;

class TableauServerConfiguration {
static final int TABLEAU_PORT = 8080;
static final int TABLEAU_MAPPED_PORT = 33445;
static final int EXASOL_PORT = 8563;
static final int EXASOL_MAPPED_PORT = 33446;
static final String TABLEAU_SERVER_DOCKER_IMAGE = "tablau_server_with_exasol_drivers:latest";
static final String TABLEAU_USERNAME = System.getProperty("TABLEAU_USERNAME");
static final String TABLEAU_PASSWORD = System.getProperty("TABLEAU_PASSWORD");
static final String TABLEAU_LICENSE_KEY = System.getProperty("TABLEAU_LICENSE_KEY");

private static final Properties PROPERTIES = readProperties("/credentials.properties");

static final String TABLEAU_USERNAME = PROPERTIES.getProperty("TABLEAU_USERNAME");
static final String TABLEAU_PASSWORD = PROPERTIES.getProperty("TABLEAU_PASSWORD");
static final String TABLEAU_LICENSE_KEY = PROPERTIES.getProperty("TABLEAU_LICENSE_KEY");

private static Properties readProperties(final String resource) {
final Properties properties = new Properties();
try (InputStream stream = TableauServerConfiguration.class.getResourceAsStream(resource)) {
if (stream == null) {
throw new AssertionError("Resource '" + resource + "' not found on classpath");
}
properties.load(stream);
} catch (final IOException exception) {
throw new UncheckedIOException("Error reading resource " + resource + " from classpath", exception);
}
return properties;
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.exasol.tableau;

import static com.exasol.tableau.TableauServerConfiguration.*;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.nio.file.*;
import java.time.Duration;
import java.util.logging.Logger;

Expand All @@ -16,6 +18,9 @@ public class TableauServerSetUp {
private static final Logger LOGGER = Logger.getLogger(TableauServerSetUp.class.getName());
private static final String REQUESTED_LEASE_TIME_IN_SECONDS = "60";

private static final Path ODBC_CONNECTOR_FILE = Paths.get("target/exasol_odbc.taco").toAbsolutePath();
private static final Path JDBC_CONNECTOR_FILE = Paths.get("target/exasol_jdbc.taco").toAbsolutePath();

public static GenericContainer<?> TABLEAU_SERVER_CONTAINER = new GenericContainer<>(TABLEAU_SERVER_DOCKER_IMAGE)
.withExposedPorts(TABLEAU_PORT)//
.withCreateContainerCmdModifier(cmd -> cmd.withHostConfig(new HostConfig().withPortBindings(
Expand All @@ -25,14 +30,21 @@ public class TableauServerSetUp {
.withEnv("LICENSE_KEY", TABLEAU_LICENSE_KEY) //
.withEnv("REQUESTED_LEASE_TIME", REQUESTED_LEASE_TIME_IN_SECONDS) //
.waitingFor(Wait.forLogMessage(".*INFO exited: run-tableau-server.*", 1)) //
// INFO exited: run-tableau-server (exit status 0; expected)
.withStartupTimeout(Duration.ofMinutes(40)) //
.withReuse(true);

public static void setUpServer() throws UnsupportedOperationException, IOException, InterruptedException {
checkPreconditions();
startContainer();
setUpConnector();
}

private static void checkPreconditions() {
assertFileExists(ODBC_CONNECTOR_FILE);
assertFileExists(JDBC_CONNECTOR_FILE);
}

private static void startContainer() {
TABLEAU_SERVER_CONTAINER.start();
}
Expand All @@ -45,12 +57,19 @@ private static void setUpConnector() throws UnsupportedOperationException, IOExc

private static void copyConnectorsToServer() {
LOGGER.info("Copying the connectors to Tableau Server");
TABLEAU_SERVER_CONTAINER.copyFileToContainer(MountableFile.forHostPath("target/exasol_odbc.taco"),
assertFileExists(ODBC_CONNECTOR_FILE);
assertFileExists(JDBC_CONNECTOR_FILE);
TABLEAU_SERVER_CONTAINER.copyFileToContainer(MountableFile.forHostPath(ODBC_CONNECTOR_FILE),
"/var/opt/tableau/tableau_server/data/tabsvc/vizqlserver/Connectors/exasol_odbc.taco");
TABLEAU_SERVER_CONTAINER.copyFileToContainer(MountableFile.forHostPath("target/exasol_jdbc.taco"),
TABLEAU_SERVER_CONTAINER.copyFileToContainer(MountableFile.forHostPath(JDBC_CONNECTOR_FILE),
"/var/opt/tableau/tableau_server/data/tabsvc/vizqlserver/Connectors/exasol_jdbc.taco");
}

private static void assertFileExists(final Path path) {
assertTrue(Files.exists(path),
"Connector not found at " + path + ". Run 'package_connector.sh' to generate it.");
}

private static void disableConnectorSignatureVerification() throws IOException, InterruptedException {
LOGGER.info("Disabling connectors signature");
TABLEAU_SERVER_CONTAINER.execInContainer("tsm", "configuration", "set", "-k",
Expand Down

0 comments on commit 5949a72

Please sign in to comment.