Skip to content

Commit

Permalink
Fixes MicroShed#342; Adjust tests for new, defaultServer name
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Kurz <skurz@us.ibm.com>
  • Loading branch information
scottkurz committed Sep 4, 2019
1 parent cc85ef7 commit 0c2d538
Show file tree
Hide file tree
Showing 34 changed files with 394 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void init() {
if ("tomee".equals(runtime)) {
DERBY_JAR = "target/apache-tomee/boost/derby-10.11.1.1.jar";
} else if ("ol".equals(runtime) || "wlp".equals(runtime)) {
DERBY_JAR = "target/liberty/wlp/usr/servers/BoostServer/resources/derby-10.11.1.1.jar";
DERBY_JAR = "target/liberty/wlp/usr/servers/defaultServer/resources/derby-10.11.1.1.jar";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class LibertyFeatureVersionIT {

private static final String JDBC_42_FEATURE = "<feature>jdbc-4.2</feature>";
private static String SERVER_XML = "target/liberty/wlp/usr/servers/BoostServer/server.xml";
private static String SERVER_XML = "target/liberty/wlp/usr/servers/defaultServer/server.xml";

@BeforeClass
public static void init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class LibertyFeatureVersionIT {

private static final String JAXRS_20_FEATURE = "<feature>jaxrs-2.0</feature>";
private static String SERVER_XML = "target/liberty/wlp/usr/servers/BoostServer/server.xml";
private static String SERVER_XML = "target/liberty/wlp/usr/servers/defaultServer/server.xml";

@BeforeClass
public static void init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class LibertyFeatureVersionIT {

private static final String JAXRS_21_FEATURE = "<feature>jaxrs-2.1</feature>";
private static String SERVER_XML = "target/liberty/wlp/usr/servers/BoostServer/server.xml";
private static String SERVER_XML = "target/liberty/wlp/usr/servers/defaultServer/server.xml";

@BeforeClass
public static void init() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Using profiles to configure failsafe to run certain tests
invoker.goals.1 = clean install -PnoEncoding -Dboost.db.databaseName=myCustomDB -Dboost.db.user=user -Dboost.db.password=password -Dboost.aes.key=test
invoker.goals.1 = clean install
#Running aes hashed password test to see if it rehashes
invoker.goals.2 = clean install -Paes -Dboost.db.databaseName=myCustomDB -Dboost.db.user=user -Dboost.db.password="{aes}Lz4sLCgwLTs="
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
import org.junit.BeforeClass;
import org.junit.Test;

import boost.common.config.BoostProperties;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import utils.LibertyConfigFileUtils;

public class Db2PasswordAesIT {

private final String DB_NAME = "myCustomDB";
Expand All @@ -28,39 +32,22 @@ public class Db2PasswordAesIT {

@BeforeClass
public static void init() {
// Liberty specific checking of bootstrap.properties file
// TODO: this should eventually be moved to a unit test
String runtime = System.getProperty("boostRuntime");
org.junit.Assume.assumeTrue("ol".equals(runtime) || "wlp".equals(runtime));
}

@Test
public void checkPropertiesTest() {

Properties bootstrapProperties = new Properties();
InputStream input = null;

try {
input = new FileInputStream("target/liberty/wlp/usr/servers/BoostServer/bootstrap.properties");

bootstrapProperties.load(input);

assertEquals("Incorrect boost.db.user found in bootstrap.properties.", DB_USER,
bootstrapProperties.getProperty("boost.db.user"));
assertEquals("Incorrect boost.db.password found in bootstrap.properties.", ENCODED_DB_PASS,
bootstrapProperties.getProperty("boost.db.password"));
assertEquals("Incorrect boost.db.databaseName found in bootstrap.properties.", DB_NAME,
bootstrapProperties.getProperty("boost.db.databaseName"));
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void checkPropertiesTest() throws Exception {
String variablesXml = "target/liberty/wlp/usr/servers/defaultServer/variables.xml";

assertEquals("Incorrect boost.db.user found in bootstrap.properties.", DB_USER,
LibertyConfigFileUtils.findVariableInXml(variablesXml, BoostProperties.DATASOURCE_USER));

assertEquals("Incorrect boost.db.password found in bootstrap.properties.", ENCODED_DB_PASS,
LibertyConfigFileUtils.findVariableInXml(variablesXml, BoostProperties.DATASOURCE_PASSWORD));

assertEquals("Incorrect boost.db.databaseName found in bootstrap.properties.", DB_NAME,
LibertyConfigFileUtils.findVariableInXml(variablesXml, BoostProperties.DATASOURCE_DATABASE_NAME));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
import org.junit.BeforeClass;
import org.junit.Test;

import boost.common.config.BoostProperties;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import utils.LibertyConfigFileUtils;

public class Db2PropertiesIT {

private final String DB_NAME = "myCustomDB";
Expand All @@ -35,34 +39,18 @@ public static void init() {
}

@Test
public void checkPropertiesTest() {

Properties bootstrapProperties = new Properties();
InputStream input = null;

try {
input = new FileInputStream("target/liberty/wlp/usr/servers/BoostServer/bootstrap.properties");

bootstrapProperties.load(input);

assertEquals("Incorrect boost.db.user found in bootstrap.properties.", DB_USER,
bootstrapProperties.getProperty("boost.db.user"));
assertEquals("Incorrect boost.db.databaseName found in bootstrap.properties.", DB_NAME,
bootstrapProperties.getProperty("boost.db.databaseName"));
// AES hashed password changes so we're just going to look for the
// aes flag.
assertTrue("Incorrect boost.db.password found in bootstrap.properties.",
bootstrapProperties.getProperty("boost.db.password").contains(AES_HASHED_PASSWORD_FLAG));
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void checkPropertiesTest() throws Exception {
String variablesXml = "target/liberty/wlp/usr/servers/defaultServer/variables.xml";

assertEquals("Incorrect boost.db.user found in bootstrap.properties.", DB_USER,
LibertyConfigFileUtils.findVariableInXml(variablesXml, BoostProperties.DATASOURCE_USER));

assertEquals("Incorrect boost.db.databaseName found in bootstrap.properties.", DB_NAME,
LibertyConfigFileUtils.findVariableInXml(variablesXml, BoostProperties.DATASOURCE_DATABASE_NAME));

// AES hashed password changes so we're just going to look for the
// aes flag.
assertTrue("Incorrect boost.db.password found in bootstrap.properties.",
LibertyConfigFileUtils.findVariableInXml(variablesXml, BoostProperties.DATASOURCE_PASSWORD).contains(AES_HASHED_PASSWORD_FLAG));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void init() {
if ("tomee".equals(runtime)) {
DB2_JAR = "target/apache-tomee/boost/db2jcc-db2jcc4.jar";
} else if ("ol".equals(runtime) || "wlp".equals(runtime)) {
DB2_JAR = "target/liberty/wlp/usr/servers/BoostServer/resources/db2jcc-db2jcc4.jar";
DB2_JAR = "target/liberty/wlp/usr/servers/defaultServer/resources/db2jcc-db2jcc4.jar";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class LibertyFeatureVersionIT {

private static final String JDBC_42_FEATURE = "<feature>jdbc-4.2</feature>";
private static String SERVER_XML = "target/liberty/wlp/usr/servers/BoostServer/server.xml";
private static String SERVER_XML = "target/liberty/wlp/usr/servers/defaultServer/server.xml";

@BeforeClass
public static void init() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package utils;

import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class DOMUtils {
// Thanks to:
// https://stackoverflow.com/questions/10689900/get-xml-only-immediate-children-elements-by-name
public static List<Element> getDirectChildrenByTag(Element el, String sTagName) {
List<Element> retVal = new ArrayList<Element>();
NodeList descendants = el.getElementsByTagName(sTagName);
for (int i = 0; i < descendants.getLength(); i++) {
if (descendants.item(i).getParentNode().equals(el)) {
retVal.add((Element) descendants.item(i));
}
}
return retVal;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package utils;

import static utils.DOMUtils.getDirectChildrenByTag;
import static org.junit.Assert.fail;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class LibertyConfigFileUtils {

public static String findVariableInXml(String variablesXmlPath, String variableName)
throws Exception {

String variableValue = null;

File variablesXml = new File(variablesXmlPath);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(variablesXml);

Element serverRoot = doc.getDocumentElement();

List<Element> variablesList = getDirectChildrenByTag(serverRoot, "variable");
for (Element variable : variablesList) {
if (variableName.equals(variable.getAttribute("name"))) {
variableValue = variable.getAttribute("defaultValue");
}
}

return variableValue;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class LibertyFeatureVersionIT {

private static final String JDBC_42_FEATURE = "<feature>jdbc-4.2</feature>";
private static String SERVER_XML = "target/liberty/wlp/usr/servers/BoostServer/server.xml";
private static String SERVER_XML = "target/liberty/wlp/usr/servers/defaultServer/server.xml";

@BeforeClass
public static void init() {
Expand Down
3 changes: 1 addition & 2 deletions boost-maven/boost-maven-plugin/src/it/test-jpa-2.1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<testServerHttpPort>9080</testServerHttpPort>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -165,4 +164,4 @@
</profile>
</profiles>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class LibertyFeatureVersionIT {

private static String SERVER_XML = "target/liberty/wlp/usr/servers/BoostServer/server.xml";
private static String SERVER_XML = "target/liberty/wlp/usr/servers/defaultServer/server.xml";

private static final String JPA_21_FEATURE = "<feature>jpa-2.1</feature>";
private static final String JDBC_42_FEATURE = "<feature>jdbc-4.2</feature>";
Expand Down
3 changes: 1 addition & 2 deletions boost-maven/boost-maven-plugin/src/it/test-jpa-2.2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<testServerHttpPort>9080</testServerHttpPort>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -168,4 +167,4 @@
</profile>
</profiles>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class LibertyFeatureVersionIT {

private static String SERVER_XML = "target/liberty/wlp/usr/servers/BoostServer/server.xml";
private static String SERVER_XML = "target/liberty/wlp/usr/servers/defaultServer/server.xml";

private static final String JPA_22_FEATURE = "<feature>jpa-2.2</feature>";
private static final String JDBC_42_FEATURE = "<feature>jdbc-4.2</feature>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<app.name>LibertyProject</app.name>
<!-- tag::ports[] -->
<testServerHttpPort>9080</testServerHttpPort>
<testServerHttpsPort>9443</testServerHttpsPort>
<!-- end::ports[] -->
<package.file>${project.build.directory}/${app.name}.zip</package.file>
<packaging.type>usr</packaging.type>
</properties>

<pluginRepositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class SystemHealth implements HealthCheck {
@Override
public HealthCheckResponse call() {
if (!System.getProperty("wlp.server.name").equals("BoostServer")) {
if (!System.getProperty("wlp.server.name").equals("defaultServer")) {
return HealthCheckResponse.named(SystemResource.class.getSimpleName())
.withData("default server", "not available").down().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- tag::ports[] -->
<testServerHttpPort>8080</testServerHttpPort>
<testServerHttpsPort>8443</testServerHttpsPort>
<!-- end::ports[] -->
</properties>

<dependencies>
Expand Down
Loading

0 comments on commit 0c2d538

Please sign in to comment.