public static final String CONFIG_FILE = "src/test/resources/pge-config.xml";
public void testBuild() throws IOException {
XmlFilePgeConfigBuilder builder = new XmlFilePgeConfigBuilder();
PgeMetadata pgeMetadata = new PgeMetadata();
pgeMetadata.replaceMetadata(CONFIG_FILE_PATH, CONFIG_FILE);
pgeMetadata.replaceMetadata("INPUT_FILE_1", "src/test/resources/data-file-1.txt");
pgeMetadata.replaceMetadata("INPUT_FILE_2", "src/test/resources/data-file-2.txt");
pgeMetadata.replaceMetadata("WORKING_DIR", "/tmp");
pgeMetadata.markAsDynamicMetadataKey();
pgeMetadata.commitMarkedDynamicMetadataKeys();
PgeConfig pgeConfig = builder.build(pgeMetadata);
// Verify metadata checks out.
assertEquals(40, pgeMetadata.asMetadata().getAllKeys().size());
assertEquals(CONFIG_FILE, pgeMetadata.getMetadata(CONFIG_FILE_PATH));
assertEquals("src/test/resources/data-file-1.txt", pgeMetadata.getMetadata("INPUT_FILE_1"));
assertEquals("src/test/resources/data-file-2.txt", pgeMetadata.getMetadata("INPUT_FILE_2"));
assertEquals("/tmp", pgeMetadata.getMetadata("WORKING_DIR"));
assertEquals(">", pgeMetadata.getMetadata("commons/GreaterThan"));
assertEquals("<", pgeMetadata.getMetadata("commons/LessThan"));
assertEquals("&", pgeMetadata.getMetadata("commons/Ampersand"));
assertEquals("'", pgeMetadata.getMetadata("commons/Apostrophe"));
assertEquals("\"", pgeMetadata.getMetadata("commons/QuotationMark"));
assertEquals("org.apache.oodt.cas.pge.writers.TextConfigFileWriter", pgeMetadata.getMetadata("writers/TextWriter"));
assertEquals("org.apache.oodt.cas.pge.writers.CsvConfigFileWriter", pgeMetadata.getMetadata("writers/CsvWriter"));
assertEquals("Simple", pgeMetadata.getMetadata("GREETING_ENUM"));
assertEquals("true", pgeMetadata.getMetadata("FORCE_STAGING"));
assertEquals("Custom", pgeMetadata.getMetadata("CUSTOM_GREETING_ENUM"));
assertEquals("<Custom Greeting Here>", pgeMetadata.getMetadata("CUSTOM_GREETING_ENUM_VALUE"));
assertEquals("/tmp", pgeMetadata.getMetadata("WorkingDir"));
assertEquals("Simple", pgeMetadata.getMetadata("GreetingEnum"));
assertEquals("Custom", pgeMetadata.getMetadata("CustomGreetingEnum"));
assertEquals("<Custom Greeting Here>", pgeMetadata.getMetadata("CustomGreetingEnumValue"));
assertEquals("src/test/resources/data-file-1.txt", pgeMetadata.getMetadata("InputFile1"));
assertEquals("src/test/resources/data-file-2.txt", pgeMetadata.getMetadata("InputFile2"));
assertEquals("true", pgeMetadata.getMetadata("ForceStaging"));
assertEquals(Lists.newArrayList("/tmp/staging/data-file-1.txt", "/tmp/staging/data-file-2.txt"), pgeMetadata.getAllMetadata("InputFiles"));
assertEquals("/tmp/config", pgeMetadata.getMetadata("ConfigDir"));
assertEquals("/tmp/output", pgeMetadata.getMetadata("OutputDir"));
assertEquals("/tmp/staging", pgeMetadata.getMetadata("StagingDir"));
assertEquals("dyn-input.txt", pgeMetadata.getMetadata("DynInput/Text/Name"));
assertEquals("dyn-input.csv", pgeMetadata.getMetadata("DynInput/CSV/Name"));
assertEquals("/tmp/config/dyn-input.txt", pgeMetadata.getMetadata("TextInputFile"));
assertEquals("/tmp/config/dyn-input.csv", pgeMetadata.getMetadata("CsvInputFile"));
assertEquals("PgeOutput.txt", pgeMetadata.getMetadata("OutputFileName"));
assertEquals("\n [Greeting],\n This is a template for text file [TextInputFile].\n This template was written at: [DATE.UTC].\n [Signature]\n ", pgeMetadata.getMetadata("TextFileTemplate"));
assertEquals("Hello", pgeMetadata.getMetadata("SimpleGreeting"));
assertEquals("Hi", pgeMetadata.getMetadata("CasualGreeting"));
assertEquals("<Custom Greeting Here>", pgeMetadata.getMetadata("CustomGreeting"));
assertEquals("Hello", pgeMetadata.getMetadata("Greating"));
assertEquals("-bfost", pgeMetadata.getMetadata("Signature"));
assertEquals(Lists.newArrayList("File1.txt","File2.dat","File3.xml"), pgeMetadata.getAllMetadata("AuxInputFiles"));
assertEquals(Lists.newArrayList("true","false","true"), pgeMetadata.getAllMetadata("IsText"));
assertEquals(Lists.newArrayList("AuxInputFiles","IsText"), pgeMetadata.getAllMetadata("CsvHeader"));
// Verify pgeconfig checks out.
List<DynamicConfigFile> dynConfigFiles = pgeConfig.getDynamicConfigFiles();
assertEquals(2, dynConfigFiles.size());
assertEquals("org.apache.oodt.cas.pge.writers.TextConfigFileWriter", dynConfigFiles.get(0).getWriterClass());