/** * {@inheritDoc} */ @Override public void setConfigFileProperty(FileConfig fileConfig) { // a configuration file should always overwrite the previous file if it exists // since the token value could have changed during. fileConfig.setOverwrite(true); fileConfig.setConfigfile(true); this.setFileProperty(fileConfig); }
/** * 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)); }
/** * Test file copy with replacement tokens. * @throws Exception If anything goes wrong. */ public void testCopyWithTokens() throws Exception { // test that token replacement for "@foo@" results in "bar" String fileName = "simpleCopyWT1"; String fileContents = "@token1@ "; File file1 = createFile(configFileDirectory, fileName, fileContents); FileConfig configFile = new FileConfig(); configFile.setFile(getAbsolutePath(file1)); // set the property so that "@foo@" is replaced with "bar" configuration.setProperty("token1", "value1"); // not set as a configuration file yet so token replacement shouldn't happen testCopy(configFile, fileName, "@token1@ "); configFile.setConfigfile("true"); testCopy(configFile, fileName, "value1 "); }
/** * 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)); }