| Products | Versions |
|---|---|
| TIBCO Streaming | 11.1 and later |
Environment Variables are not automatically obtained from the test environment, and are not made visible to the EventFlow module being tested.
In order to pass Environment Variables into a test they must be explicitly passed as command-line arguments for the Maven command, and the test code may use them as a Java System Properties or convert them back to Environment Variables for use by the Java test code, the running node, or the Streaming engine running the application.
Consider the case where encrypted configuration settings are used in an EventFlow JUnit Test. The Streaming node needs to have the Java keystore location and password supplied to interpret the encrypted values. If these values are not allowed to be encoded in plaintext in the test or configuration, they must be passed in. Specifically for this use-case, the test 'setupServer()' method must be passed these values from the Maven command-line for use in executing the 'epadmin load secret' command before the test starts. For convenience, these values are stored in environment variables in the test environment.
Note that when running from the StreamBase Studio IDE, the run configuration for the test may contain the location and password values, and the run configuration by default is not saved to version control but kept local in the user's Eclipse Workspace settings. This satisfies the requirement that these sensitive values are not saved to version control in plaintext.
For JUnit tests, the local user environment is not exposed to the test in order to prevent the test from being dependent upon or modified by temporary settings. This means that these are not automatically available to the Streaming node, JVM engine, or application modules being tested.
In our example, the command-line test is started using command:
export KEYSTORE_PATH=/test/keystore.jks
export KEYSTORE_PASSWORD=secret
mvn test -DtestName -DkeystorePath=$KEYSTORE_PATH -DkeystorePassword=$KEYSTORE_PASSWORD
This copies the environment variable values to Java System Properties for use by the test.
Here is an example of the 'setupServer()' method that loads the master secret from the keystore into the node before loading configuration with encrypted values:
01 @BeforeClass
02 public static void setupServer() throws StreamBaseException, ConfigurationException, InterruptedException {
03 server = ServerManagerFactory.getEmbeddedServer();
04 server.startServer();
05 // load the decryption key from the keystore to the server using system properties set on the command-line
06 Map<String, String> parameters = new HashMap<String, String>();
07 parameters.put("keystore", System.getProperty("keystorePath"));
08 parameters.put("keystorepassword", System.getProperty("keystorePassword");
09 Administration admin = new Administration();
10 admin.execute("load", "secret", parameters);
11 // load the configuration afer loading the decryption key
12 Configuration.forFile("engine.conf").load().activate();
13 server.loadApp("com.example.envtest.envtest");
14 } On line 12, the encrypted values in the configuration can only be interpreted if the master key is loaded first.
On line 10, this is the equivalent of running 'epadmin --servicename=A.X load secret --keystore=... --keystorepassword=...' from the command-line.
On lines 07 and 08, these read the Java system properties as named parameters needed for the "load secret" command.
The Java system properties are available to the application and can be read using EventFlow expression systemproperty(name).
Optionally, to also read the values as Environment Variables within the Java test and within the application, create environment variables by adding to the project pom.xml:
<build>
<plugins>
<plugin>
<groupId>com.tibco.ep</groupId>
<artifactId>ep-maven-plugin</artifactId>
<configuration>
<environmentVariables>
<KEYSTOREENV>${keystorePath}</KEYSTOREENV>
<KEYPASSENV>${keystorePassword}</KEYPASSENV>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
This creates in the test environment the environment variables KEYSTOREENV and KEYPASSENV set from the 'mvn test' parameters which may be then read from the test Java with command 'System.getenv(name)' and from EventFlow using expression 'systemenv(name)'.
The above shows how to copy user environment variables into Java system properties for use in the JUnit test and application being tested, and optionally copy them back into environment variables for use within the test JVM, node, and application engine JVM.
In order to pass an Environment Variable into a test it must be explicitly passed as command-line argument into the Maven command, and the test code may use it as a Java System Property or convert it back to an Environment Variable for use by the Java test code, the running node, or Streaming engine running the application.
Maven command reference
Streaming EventFlow JUnit Tests Documentation
ep-maven-plugin