/** * Sets a configuration file property for the container's configuration * * This function is currently only used to specify a different context.xml file from the one * located in the installations 'conf' folder. * * @param filePath The path to the new configuration file * @param configDirDest The name of the directory that the configuration file be placed in * @param configFileDestName The name of destination file for the new configuration file */ private void setConfigFile(String filePath, String configDirDest, String configFileDestName) { FileConfig configFile = new FileConfig(); configFile.setFile(filePath); configFile.setToDir(configDirDest); configFile.setToFile(configFileDestName); getConfiguration().setConfigFileProperty(configFile); } }
configFile.setToFile("file1"); testCopy(configFile, "file1", fileContents); configFile.setToFile("dir1/file2"); testCopy(configFile, "dir1/file2", fileContents); configFile.setToFile(null); configFile.setToDir("dir2"); testCopy(configFile, "dir2/file", fileContents); configFile.setToFile("file3"); configFile.setToDir("dir3"); testCopy(configFile, "dir3/file3", fileContents); configFile.setToFile("/dir4/file4"); configFile.setToDir("/dir5"); testCopy(configFile, "dir5/dir4/file4", fileContents);
/** * Test file copy with overwrite. * @throws Exception If anything goes wrong. */ public void testOverwite() throws Exception { File configHome = new File(configuration.getHome()); assertTrue("Could not find a proper configuration home.", configHome.exists() && configHome.isDirectory()); File existingFile = createFile(configHome, "existingfile", "helloworld"); // make sure the file exists and contains the proper information. assertEquals("helloworld", readFile(existingFile)); String fileName = "simpleCopyWithOverwrite"; String fileContents = "goodbye"; File file1 = createFile(configFileDirectory, fileName, fileContents); FileConfig configFile = new FileConfig(); configFile.setFile(getAbsolutePath(file1)); configFile.setToFile("existingfile"); configFile.setOverwrite("true"); testCopy(configFile, "existingfile", "goodbye"); assertEquals("goodbye", readFile(existingFile)); }
/** * {@inheritDoc} */ @Override public void startAndStop(URL warPingURL) { String testFileName = "cargo-test/test.file"; File testFile = new File(getLocalContainer().getConfiguration().getHome(), testFileName); assertFalse("File " + testFile + " already exists", testFile.exists()); FileConfig fileConfig = new FileConfig(); fileConfig.setFile(getTestData().getTestDataFileFor("simple-war")); fileConfig.setToFile(testFileName); getLocalContainer().getConfiguration().setConfigFileProperty(fileConfig); getLocalContainer().start(); PingUtils.assertPingTrue(warPingURL.getPath() + " not started", warPingURL, getLogger()); // CARGO-1195: DeployableFiles should be setup for ExistingLocalConfiguration assertTrue("File " + testFile + " was not configured", testFile.exists()); getLocalContainer().stop(); PingUtils.assertPingFalse(warPingURL.getPath() + " not stopped", warPingURL, getLogger()); }
/** * Test configuration file property. * @throws Exception If anything goes wrong. */ public void testConfigFileProperty() throws Exception { File configHome = new File(configuration.getHome()); assertTrue("Could not find a proper configuration home.", configHome.exists() && configHome.isDirectory()); File existingFile = createFile(configHome, "existingfile", "helloworld"); // make sure the file exists and contains the proper information. assertEquals("helloworld", readFile(existingFile)); String fileName = "testConfigfile"; String fileContents = "Hello @message@ "; File file = createFile(configFileDirectory, fileName, fileContents); FileConfig configFile = new FileConfig(); configFile.setFile(getAbsolutePath(file)); configFile.setToFile("existingfile"); // if using the setConfigFilePropery then its should always be set // to overwrite and that its a configfile regardless of the what the // FileConfig is set as. configFile.setOverwrite(false); configFile.setConfigfile(false); configuration.setProperty("message", "world"); configuration.setConfigFileProperty(configFile); configuration.doConfigure(null); File copiedFile = new File(configuration.getHome() + "/existingfile"); assertTrue("Cannot find the expected copied file", copiedFile.exists()); assertEquals("Hello world ", readFile(copiedFile)); }
/** * Test file copy with overwrite and replacement tokens. * @throws Exception If anything goes wrong. */ public void testOverwriteWithTokens() throws Exception { File configHome = new File(configuration.getHome()); assertTrue("Could not find a proper configuration home.", configHome.exists() && configHome.isDirectory()); File existingFile = createFile(configHome, "existingfile2", "helloworld"); // make sure the file exists and contains the proper information. assertEquals("helloworld", readFile(existingFile)); String fileName = "simpleCopyWithOverwrite"; String fileContents = "goodbye@token1@."; File file1 = createFile(configFileDirectory, fileName, fileContents); FileConfig configFile = new FileConfig(); configFile.setFile(getAbsolutePath(file1)); configFile.setToFile("existingfile2"); configFile.setOverwrite("true"); configFile.setConfigfile("true"); configuration.setProperty("token1", " everyone"); testCopy(configFile, "existingfile2", "goodbye everyone."); assertEquals("goodbye everyone.", readFile(existingFile)); }