Skip to content

Commit

Permalink
final test, debug msg + default
Browse files Browse the repository at this point in the history
  • Loading branch information
dshimo committed Mar 12, 2024
1 parent 3d3ece0 commit 54545dd
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ public ServerConfigDocument(CommonLoggerI log, File serverXML, File configDir, F
configDirectory = configDir;
if (libertyDirPropertyFiles != null) {
libertyDirectoryPropertyToFile = new HashMap<String, File>(libertyDirPropertyFiles);
if (libertyDirPropertyFiles.containsKey(ServerFeatureUtil.SERVER_CONFIG_DIR)) {
configDirectory = libertyDirPropertyFiles.get(ServerFeatureUtil.SERVER_CONFIG_DIR);
}
} else {
log.warn("The properties for directories are null and could lead to application locations not being resolved correctly.");
libertyDirectoryPropertyToFile = new HashMap<String,File>();
Expand Down Expand Up @@ -314,6 +317,7 @@ public void processJvmOptions() throws FileNotFoundException, Exception {
public void processBootstrapProperties() throws Exception, FileNotFoundException {
File bootstrapFile = getFileFromConfigDirectory("bootstrap.properties");
if (bootstrapFile == null) {
log.debug("bootstrap.properties not found in: " + configDirectory.getAbsolutePath());
return;
}

Expand Down Expand Up @@ -707,7 +711,6 @@ public void parsePropertiesFromFile(File propertiesFile) throws Exception, FileN
if (propertiesFile != null && propertiesFile.exists()) {
parseProperties(new FileInputStream(propertiesFile));
}
log.debug("Ignoring non-existing properties file: " + propertiesFile.getAbsolutePath());
}

private void parseProperties(InputStream ins) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,8 @@
import io.openliberty.tools.common.plugins.util.ServerFeatureUtil;
import io.openliberty.tools.common.plugins.util.VariableUtility;

/*
Docs: https://openliberty.io/docs/latest/reference/config/server-configuration-overview.html
# Variable substitution in increasing order of precedence (7 overrides 1)
1. variable default values in the server.xml file
2. environment variables
3. bootstrap.properties
4. Java system properties
5. Variables loaded from files in the ${server.config.dir}/variables directory or other directories as specified by the VARIABLE_SOURCE_DIRS environment variable
6. variable values declared in the server.xml file
7. variables declared on the command line
*/

// Docs: https://openliberty.io/docs/latest/reference/config/server-configuration-overview.html
public class ServerConfigDocumentOverridesTest {
private final static Path RESOURCES_DIR = Paths.get("src/test/resources/");
private final static Path WLP_DIR = RESOURCES_DIR.resolve("serverConfig/liberty/wlp/");
Expand Down Expand Up @@ -121,7 +111,6 @@ public void serverXmlEnvVarVariationLookup() throws FileNotFoundException, Excep
String resolveUnderscoreToUpper = VariableUtility.resolveVariables(new TestLogger(), "${that.value}",
null, configDocument.getProperties(), configDocument.getDefaultProperties(), libertyDirPropMap);
assertEquals("DEFINED", resolveUnderscoreToUpper);

}

@Test
Expand Down Expand Up @@ -227,23 +216,9 @@ public void CLI() {

}

// TODO: test each overrides layer
// jvm.options override server.env
// bootstrap.properties override jvm.options and server.env
// server.xml override bootstrap.properties, jvm.options, and server.env
@Test
public void overrides() {
File serverConfigDir = SERVER_CONFIG_DIR.toFile();

// server.xml overrides server.env
ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(),
new File(serverConfigDir, "server.xml"), serverConfigDir, new File(serverConfigDir, "bootstrap.properties"),
new HashMap<>(), new File(serverConfigDir, "server.env"), false, null);
assertEquals("new_value", configDocument.getProperties().getProperty("overriden_value"));
}

// Run the method
@Test
public void initializeAppsLocation() {
public void initializeAppsLocationTest() {
File serverConfigDir = SERVER_CONFIG_DIR.toFile();
Map<String, File> libertyDirPropMap = new HashMap<String, File>();
libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverConfigDir);
Expand All @@ -257,13 +232,15 @@ public void initializeAppsLocation() {

// default properties in server.xml
assertEquals(3, defaultProperties.size());

// server.env, wlp/etc and wlp/shared

assertEquals("true", properties.get("etc.unique")); // etc
assertEquals("true", properties.get("shared.overriden")); // shared > etc
assertEquals("1111", properties.get("http.port")); // serverConfig > shared
// bootstrap.properties

assertEquals("true", properties.get("bootstrap.properties.override")); // overrides server.env
// variables dir

assertEquals("true", properties.get("variables.override")); // overrides bootstrap.prop
// configDropins
assertEquals("7777", properties.get("httpPort")); // overrides variable dir
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
extras.filename=extraFeatures.xml
THAT_VALUE=DEFINED
THAT_VALUE=DEFINED
bootstrap.properties.override=true
variables.override=false
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<server description="default server">
<variable name="config.dropins.overrides" value="3"/>
<variable name="httpPort" value="7777"/>
</server>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
keystore_password=C7ANPlAi0MQD154BJ5ZOURn
http.port=1111
overriden_value=old_value
this_value=DEFINED
this_value=DEFINED
bootstrap.properties.override=false
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true

0 comments on commit 54545dd

Please sign in to comment.