From 267059f69d2622b2c8c5b1b6cd7a09bc974ac243 Mon Sep 17 00:00:00 2001 From: dshimo Date: Mon, 11 Mar 2024 15:31:01 -0500 Subject: [PATCH] interface, switch to libertyDirPropMap usage --- .../plugins/config/ServerConfigDocument.java | 192 ++++++++---------- ...=> ServerConfigDocumentOverridesTest.java} | 130 ++++++++---- .../configDropins/defaults/server.xml | 5 + .../configDropins/overrides/server.xml | 3 + .../wlp/usr/servers/defaultServer/server.xml | 3 +- 5 files changed, 183 insertions(+), 150 deletions(-) rename src/test/java/io/openliberty/tools/common/config/{ServerConfigDocumentTest.java => ServerConfigDocumentOverridesTest.java} (62%) create mode 100644 src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/defaults/server.xml create mode 100644 src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/overrides/server.xml diff --git a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java index 5c53ebc7..34566d4f 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java +++ b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java @@ -123,7 +123,7 @@ public File getServerXML() { } /** - * + * Deprecated. Migrate to the simpler constructor. * @param log * @param serverXML * @param configDir @@ -131,29 +131,40 @@ public File getServerXML() { * @param bootstrapProp * @param serverEnvFile * @param giveConfigDirPrecedence - * @param libertyDirPropertyFiles - Contains a property to file mapping of direcdty locations + * @param libertyDirPropertyFiles - Contains a property to file mapping of directory locations */ public ServerConfigDocument(CommonLoggerI log, File serverXML, File configDir, File bootstrapFile, Map bootstrapProp, File serverEnvFile, boolean giveConfigDirPrecedence, Map libertyDirPropertyFiles) { - initializeAppsLocation(log, serverXML, configDir, bootstrapFile, bootstrapProp, serverEnvFile, giveConfigDirPrecedence, libertyDirPropertyFiles); - } - - public ServerConfigDocument() { - - } + this.log = log; + serverXMLFile = serverXML; + configDirectory = configDir; + if (libertyDirPropertyFiles != null) { + libertyDirectoryPropertyToFile = new HashMap(libertyDirPropertyFiles); + } else { + log.warn("The properties for directories are null and could lead to application locations not being resolved correctly."); + libertyDirectoryPropertyToFile = new HashMap(); + } + locations = new HashSet(); + names = new HashSet(); + namelessLocations = new HashSet(); + locationsAndNames = new HashMap(); + props = new Properties(); + defaultProps = new Properties(); - // LCLS constructor - public ServerConfigDocument(CommonLoggerI log) { - // TODO: populate libertyDirectoryPropertyToFile with workspace information - initializeFields(log, null, null, null); + initializeAppsLocation(); } - public void initializeFields(CommonLoggerI log, File serverXML, File configDir, Map libertyDirPropertyFiles) { + /** + * Adapt when ready. Expects the libertyDirPropertyFiles to be populated + * @param log + * @param libertyDirPropertyFiles + */ + public ServerConfigDocument(CommonLoggerI log, Map libertyDirPropertyFiles) { this.log = log; - serverXMLFile = serverXML; - configDirectory = configDir; if (libertyDirPropertyFiles != null) { libertyDirectoryPropertyToFile = new HashMap(libertyDirPropertyFiles); + configDirectory = libertyDirectoryPropertyToFile.get(ServerFeatureUtil.SERVER_CONFIG_DIR); + serverXMLFile = getFileFromConfigDirectory("server.xml"); } else { log.warn("The properties for directories are null and could lead to application locations not being resolved correctly."); libertyDirectoryPropertyToFile = new HashMap(); @@ -164,6 +175,14 @@ public void initializeFields(CommonLoggerI log, File serverXML, File configDir, locationsAndNames = new HashMap(); props = new Properties(); defaultProps = new Properties(); + + // initializeAppsLocation(); + } + + // LCLS constructor + // TODO: populate libertyDirectoryPropertyToFile with workspace information + public ServerConfigDocument(CommonLoggerI log) { + this(log, null); } private DocumentBuilder getDocumentBuilder() { @@ -186,38 +205,35 @@ private DocumentBuilder getDocumentBuilder() { return docBuilder; } - private void initializeAppsLocation(CommonLoggerI log, File serverXML, File configDir, File bootstrapFile, - Map bootstrapProp, File serverEnvFile, boolean giveConfigDirPrecedence, Map libertyDirPropertyFiles) { + /** + // Server variable precedence in ascending order if defined in multiple locations. + // 1. variable default values in the server.xml file + // 2. environment variables + // server.env + // a. ${wlp.install.dir}/etc/ + // b. ${wlp.user.dir}/shared/ + // c. ${server.config.dir}/ + // jvm.options + // a. ${wlp.user.dir}/shared/jvm.options + // b. ${server.config.dir}/configDropins/defaults/ + // c. ${server.config.dir}/ + // d. ${server.config.dir}/configDropins/overrides/ + // 3. bootstrap.properties + // a. additional references by bootstrap.include + // 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 + // a. ${server.config.dir}/configDropins/defaults/ + // b. ${server.config.dir}/server.xml + // c. ${server.config.dir}/configDropins/overrides/ + // 7. variables declared on the command line + */ + public void initializeAppsLocation() { try { - initializeFields(log, serverXML, configDir, libertyDirPropertyFiles); - + // 1. Need to parse variables in the server.xml for default values before trying to + // find the include files in case one of the variables is used in the location. Document doc = parseDocument(serverXMLFile); - - // Server variable precedence in ascending order if defined in multiple locations. - // 1. variable default values in the server.xml file - // 2. environment variables - // server.env - // a. ${wlp.install.dir}/etc/ - // b. ${wlp.user.dir}/shared/ - // c. ${server.config.dir}/ - // jvm.options - // a. ${wlp.user.dir}/shared/jvm.options - // b. ${server.config.dir}/configDropins/defaults/ - // c. ${server.config.dir}/ - // d. ${server.config.dir}/configDropins/overrides/ - // 3. bootstrap.properties - // a. additional references by bootstrap.include - // 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 - // a. ${server.config.dir}/configDropins/defaults/ - // b. ${server.config.dir}/server.xml - // c. ${server.config.dir}/configDropins/overrides/ - // 7. variables declared on the command line - - // 1. Need to parse variables in the server.xml for default values before trying to find the include files in case one of the variables is used - // in the location. parseVariablesForDefaultValues(doc); // 2. get variables from server.env @@ -235,45 +251,23 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf // 5. Variables loaded from 'variables' directory processVariablesDirectory(); - // 6. variable values declared in server.xml - // resolve variable references along the way - // configDropins/defaults - // server.xml - // configDropins/overrides + // 6. variable values declared in server.xml(s) + processServerXml(doc); // 7. variables delcared on the command line // configured in Maven/Gradle - // TODO: cleanup rest - // current code parses the includes section for a list of files to iterate through - // includes section needs to resolve the variables because it's in the server.xml - // after includes is determined, configDropins are analyzed - // 4. parse variables from include files (both default and non-default values - which we store separately) - - parseIncludeVariables(doc); - - // 5. variables from configDropins/defaults/ - parseConfigDropinsDirVariables("defaults"); - - // 6. variables defined in server.xml - non-default values - parseVariablesForValues(doc); - - // 7. variables from configDropins/overrides/ - parseConfigDropinsDirVariables("overrides"); - parseApplication(doc, XPATH_SERVER_APPLICATION); parseApplication(doc, XPATH_SERVER_WEB_APPLICATION); parseApplication(doc, XPATH_SERVER_ENTERPRISE_APPLICATION); parseNames(doc, "/server/application | /server/webApplication | /server/enterpriseApplication"); parseInclude(doc); parseConfigDropinsDir(); - } catch (Exception e) { e.printStackTrace(); } } - /** * server.env file read order * 1. {wlp.install.dir}/etc/ @@ -289,8 +283,7 @@ public void processServerEnv() throws Exception, FileNotFoundException { "etc" + File.separator + serverEnvString)); parsePropertiesFromFile(new File(libertyDirectoryPropertyToFile.get(ServerFeatureUtil.WLP_USER_DIR), "shared" + File.separator + serverEnvString)); - parsePropertiesFromFile(new File(libertyDirectoryPropertyToFile.get(ServerFeatureUtil.SERVER_CONFIG_DIR), - serverEnvString)); + parsePropertiesFromFile(getFileFromConfigDirectory(serverEnvString)); } /** @@ -319,15 +312,15 @@ public void processJvmOptions() throws FileNotFoundException, Exception { * @throws FileNotFoundException */ public void processBootstrapProperties() throws Exception, FileNotFoundException { - File configDirBootstrapProperties = getFileFromConfigDirectory("bootstrap.properties"); - if (configDirBootstrapProperties == null) { + File bootstrapFile = getFileFromConfigDirectory("bootstrap.properties"); + if (bootstrapFile == null) { return; } - parseProperties(new FileInputStream(configDirBootstrapProperties)); + parsePropertiesFromFile(bootstrapFile); if (props.containsKey("bootstrap.include")) { Set visited = new HashSet(); - visited.add(configDirBootstrapProperties.getAbsolutePath()); + visited.add(bootstrapFile.getAbsolutePath()); processBootstrapInclude(visited); } } @@ -382,7 +375,7 @@ public void processVariablesDirectory() throws FileNotFoundException, Exception } for (File directory : toProcess) { - if (!directory.isDirectory()) { + if (directory == null || !directory.isDirectory()) { continue; } processVariablesDirectory(directory, ""); @@ -418,6 +411,20 @@ private void processVariablesDirectory(File directory, String propertyPrefix) } } + /** + * + * @param doc + * @throws XPathExpressionException + * @throws IOException + * @throws SAXException + */ + public void processServerXml(Document doc) throws XPathExpressionException, IOException, SAXException { + parseIncludeVariables(doc); + parseConfigDropinsDirVariables("defaults"); + parseVariablesForValues(doc); + parseConfigDropinsDirVariables("overrides"); + } + //Checks for application names in the document. Will add locations without names to a Set private void parseNames(Document doc, String expression) throws XPathExpressionException, IOException, SAXException { // parse input document @@ -700,6 +707,7 @@ 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 { @@ -846,39 +854,11 @@ private void parseDropinsFilesVariables(File file) } } - /* - * If giveConfigDirPrecedence is set to true, return the file from the configDirectory if it exists; - * otherwise return specificFile if it exists, or null if not. - * If giveConfigDirPrecedence is set to false, return specificFile if it exists; - * otherwise return the file from the configDirectory if it exists, or null if not. - */ - private File findConfigFile(String fileName, File specificFile, boolean giveConfigDirPrecedence) { - File f = new File(configDirectory, fileName); - - if (giveConfigDirPrecedence) { - if (configDirectory != null && f.exists()) { - return f; - } - if (specificFile != null && specificFile.exists()) { - return specificFile; - } - } else { - if (specificFile != null && specificFile.exists()) { - return specificFile; - } - if (configDirectory != null && f.exists()) { - return f; - } - } - - return null; - } - /* * Get the file from configDrectory if it exists, or null if not */ - private File getFileFromConfigDirectory(String file) { - File f = new File(configDirectory, file); + private File getFileFromConfigDirectory(String filename) { + File f = new File(configDirectory, filename); if (configDirectory != null && f.exists()) { return f; } diff --git a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java similarity index 62% rename from src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java rename to src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java index 0ea79012..6caf3a52 100644 --- a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java +++ b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java @@ -2,6 +2,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import java.io.File; import java.io.FileNotFoundException; @@ -12,7 +13,6 @@ import java.util.Map; import java.util.Properties; -import javax.xml.bind.annotation.XmlElement.DEFAULT; import javax.xml.xpath.XPathExpressionException; import org.junit.Test; @@ -21,6 +21,8 @@ import io.openliberty.tools.common.TestLogger; import io.openliberty.tools.common.plugins.config.ServerConfigDocument; +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 @@ -34,7 +36,7 @@ 7. variables declared on the command line */ -public class ServerConfigDocumentTest { +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/"); private final static Path WLP_USER_DIR = RESOURCES_DIR.resolve("serverConfig/liberty/wlp/usr/"); @@ -45,19 +47,21 @@ public class ServerConfigDocumentTest { // 6. variable values declared in the server.xml file @Test public void processServerXml() throws FileNotFoundException, IOException, XPathExpressionException, SAXException { - File serversDir = SERVERS_RESOURCES_DIR.toFile(); + File serversResourceDir = SERVERS_RESOURCES_DIR.toFile(); Document doc; + Map libertyDirPropMap = new HashMap(); + libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serversResourceDir); // no variables defined - ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); - File empty = new File(serversDir, "emptyList.xml"); + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + File empty = new File(serversResourceDir, "emptyList.xml"); doc = configDocument.parseDocument(empty); configDocument.parseVariablesForBothValues(doc); assertTrue(configDocument.getDefaultProperties().isEmpty() && configDocument.getProperties().isEmpty()); // variables defined - configDocument = new ServerConfigDocument(new TestLogger()); - File defined = new File(serversDir, "definedVariables.xml"); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + File defined = new File(serversResourceDir, "definedVariables.xml"); doc = configDocument.parseDocument(defined); configDocument.parseVariablesForBothValues(doc); assertEquals(1, configDocument.getDefaultProperties().size()); @@ -66,9 +70,8 @@ public void processServerXml() throws FileNotFoundException, IOException, XPathE assertEquals("9081", configDocument.getProperties().getProperty("http.port")); // variables defined in files - configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), new File(serversDir, "server.xml"), null, null); - File include = new File(serversDir, "testIncludeParseVariables.xml"); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + File include = new File(serversResourceDir, "testIncludeParseVariables.xml"); doc = configDocument.parseDocument(include); assertTrue(configDocument.getDefaultProperties().isEmpty() && configDocument.getProperties().isEmpty()); configDocument.parseIncludeVariables(doc); @@ -76,12 +79,16 @@ public void processServerXml() throws FileNotFoundException, IOException, XPathE assertEquals("9080", configDocument.getDefaultProperties().getProperty("default.http.port")); assertEquals(1, configDocument.getProperties().size()); assertEquals("9081", configDocument.getProperties().getProperty("http.port")); - - // server.xmls read in increasing precedence - // TODO: refactor - // configDropins/defaults - // server.xml - // configDropins/overrides + + // server.xml configDropins precedence + File serverConfigDir = SERVER_CONFIG_DIR.toFile(); + libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverConfigDir); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + doc = configDocument.parseDocument(new File(serverConfigDir, "server.xml")); + configDocument.processServerXml(doc); // Variable resolution warnings can be ignored here + assertEquals("1", configDocument.getProperties().getProperty("config.dropins.defaults")); + assertEquals("2", configDocument.getProperties().getProperty("config.dropins.server")); + assertEquals("3", configDocument.getProperties().getProperty("config.dropins.overrides")); } // when a server.xml references an environment variable that could not be resolved, additionally search for: @@ -89,20 +96,32 @@ public void processServerXml() throws FileNotFoundException, IOException, XPathE // 2. change all characters to uppercase @Test public void serverXmlEnvVarVariationLookup() throws FileNotFoundException, Exception { - File serverXml = SERVER_CONFIG_DIR.resolve("server.xml").toFile(); - ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), serverXml, SERVER_CONFIG_DIR.toFile(), new HashMap<>()); - Document serverXmlDoc = configDocument.parseDocument(serverXml); + File serverConfigDir = SERVER_CONFIG_DIR.toFile(); + Map libertyDirPropMap = new HashMap(); + libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverConfigDir); + + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + Document serverXmlDoc = configDocument.parseDocument(new File(serverConfigDir, "server.xml")); configDocument.parseVariablesForBothValues(serverXmlDoc); assertEquals("${this.value}", configDocument.getDefaultProperties().getProperty("server.env.defined")); assertEquals("${this.value}", configDocument.getProperties().getProperty("server.env.defined")); + assertEquals("${that.value}", configDocument.getProperties().getProperty("bootstrap.property.defined")); + configDocument.processBootstrapProperties(); + assertFalse(configDocument.getProperties().containsKey("that.value")); + assertTrue(configDocument.getProperties().containsKey("THAT_VALUE")); configDocument.processServerEnv(); + assertFalse(configDocument.getProperties().containsKey("this.value")); + assertTrue(configDocument.getProperties().containsKey("this_value")); configDocument.parseVariablesForBothValues(serverXmlDoc); - // TODO: implement feature and uncomment these lines - // assertEquals("DEFINED", configDocument.getProperties().getProperty("server.env.defined")); - // assertEquals("DEFINED", configDocument.getProperties().getProperty("bootstrap.properties.defined")); + String resolveUnderscore = VariableUtility.resolveVariables(new TestLogger(), "${this.value}", + null, configDocument.getProperties(), configDocument.getDefaultProperties(), libertyDirPropMap); + assertEquals("DEFINED", resolveUnderscore); + String resolveUnderscoreToUpper = VariableUtility.resolveVariables(new TestLogger(), "${that.value}", + null, configDocument.getProperties(), configDocument.getDefaultProperties(), libertyDirPropMap); + assertEquals("DEFINED", resolveUnderscoreToUpper); + } @Test @@ -110,13 +129,11 @@ public void processServerEnv() throws FileNotFoundException, Exception { File wlpInstallDir = WLP_DIR.toFile(); File wlpUserDir = WLP_USER_DIR.toFile(); File serverDir = SERVER_CONFIG_DIR.toFile(); - ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); Map libertyDirectoryPropertyToFileMap = new HashMap(); - libertyDirectoryPropertyToFileMap.put("wlp.install.dir", wlpInstallDir); - libertyDirectoryPropertyToFileMap.put("wlp.user.dir", wlpUserDir); - libertyDirectoryPropertyToFileMap.put("server.config.dir", serverDir); - - configDocument.initializeFields(new TestLogger(), null, serverDir, libertyDirectoryPropertyToFileMap); + libertyDirectoryPropertyToFileMap.put(ServerFeatureUtil.WLP_INSTALL_DIR, wlpInstallDir); + libertyDirectoryPropertyToFileMap.put(ServerFeatureUtil.WLP_USER_DIR, wlpUserDir); + libertyDirectoryPropertyToFileMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverDir); + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirectoryPropertyToFileMap); configDocument.processServerEnv(); Properties props = configDocument.getProperties(); @@ -144,25 +161,26 @@ public void environmentVariables() throws FileNotFoundException, Exception { public void processBootstrapProperties() throws FileNotFoundException, Exception { File serversDir = SERVERS_RESOURCES_DIR.toFile(); ServerConfigDocument configDocument; + Map libertyDirPropMap = new HashMap(); + libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serversDir); // bootstrap.properties - configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, serversDir, null); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); configDocument.processBootstrapProperties(); assertEquals(1, configDocument.getProperties().size()); assertEquals("extraFeatures.xml", configDocument.getProperties().getProperty("extras.filename")); // bootstrap.include - configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, new File(serversDir, "bootstrapInclude"), null); + libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, new File(serversDir, "bootstrapInclude")); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); configDocument.processBootstrapProperties(); assertEquals(2, configDocument.getProperties().size()); assertTrue(configDocument.getProperties().containsKey("bootstrap.include")); assertEquals("extraFeatures.xml", configDocument.getProperties().getProperty("extras.filename")); // bootstrap.include termination check - configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, new File(serversDir, "bootstrapOuroboros"), null); + libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, new File(serversDir, "bootstrapOuroboros")); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); configDocument.processBootstrapProperties(); } @@ -177,10 +195,11 @@ public void jvmOptions() { @Test public void variablesDir() throws FileNotFoundException, Exception { File serversDir = SERVER_CONFIG_DIR.toFile(); - ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, serversDir, null); + Map libertyDirPropMap = new HashMap(); + libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serversDir); + + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); configDocument.processVariablesDirectory(); - Properties props = configDocument.getProperties(); assertEquals("9080", props.getProperty("httpPort")); assertEquals("1000", props.getProperty(String.join(File.separator, "nested", "httpPort"))); @@ -188,8 +207,7 @@ public void variablesDir() throws FileNotFoundException, Exception { assertEquals("2", props.getProperty("VALUE_2")); // process VARIABLE_SOURCE_DIRS - configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, serversDir, null); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); String delimiter = (File.separator.equals("/")) ? ":" : ";"; String variableSourceDirsTestValue = String.join(delimiter, SERVERS_RESOURCES_DIR.resolve("variables").toString(), @@ -215,11 +233,37 @@ public void CLI() { // server.xml override bootstrap.properties, jvm.options, and server.env @Test public void overrides() { - File serversDir = SERVER_CONFIG_DIR.toFile(); + File serverConfigDir = SERVER_CONFIG_DIR.toFile(); + // server.xml overrides server.env ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), - new File(serversDir, "server.xml"), serversDir, new File(serversDir, "bootstrap.properties"), - new HashMap<>(), new File(serversDir, "server.env"), false, null); + 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")); } + + @Test + public void initializeAppsLocation() { + File serverConfigDir = SERVER_CONFIG_DIR.toFile(); + Map libertyDirPropMap = new HashMap(); + libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverConfigDir); + libertyDirPropMap.put(ServerFeatureUtil.WLP_INSTALL_DIR, WLP_DIR.toFile()); + libertyDirPropMap.put(ServerFeatureUtil.WLP_USER_DIR, WLP_USER_DIR.toFile()); + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + configDocument.initializeAppsLocation(); + + Properties properties = configDocument.getProperties(); + Properties defaultProperties = configDocument.getDefaultProperties(); + + // default properties in server.xml + assertEquals(3, defaultProperties.size()); + + // server.env, wlp/etc and wlp/shared + + // bootstrap.properties + + // variables dir + + // configDropins + } } diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/defaults/server.xml b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/defaults/server.xml new file mode 100644 index 00000000..5cf6f7aa --- /dev/null +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/defaults/server.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/overrides/server.xml b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/overrides/server.xml new file mode 100644 index 00000000..8609b5ad --- /dev/null +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/overrides/server.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.xml b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.xml index 43a7f85e..77dfb53b 100644 --- a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.xml +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.xml @@ -24,5 +24,6 @@ - + + \ No newline at end of file