PGETaskInstance implements WorkflowTaskInstance { protected void dumpMetadataIfRequested() throws IOException { if (Boolean.parseBoolean(pgeMetadata .getMetadata(DUMP_METADATA))) { new SerializableMetadata(pgeMetadata.asMetadata()) .writeMetadataToXmlStream(new FileOutputStream( getDumpMetadataPath())); } } protected  PGETaskInstance(); @Override void run(Metadata metadata, WorkflowTaskConfiguration config); String getWorkflowInstId(); void setWorkflowInstId(String workflowInstId); void setWmClient(WorkflowManagerClient wmClient); @Override void finalize();  }
@Test public void testDumpMetadataIfRequested() throws Exception { PGETaskInstance pgeTask = createTestInstance(); File dumpMetFile = new File(pgeTask.getDumpMetadataPath()); pgeTask.dumpMetadataIfRequested(); assertFalse(dumpMetFile.exists()); pgeTask.pgeMetadata.replaceMetadata(DUMP_METADATA, "true"); pgeTask.dumpMetadataIfRequested(); assertTrue(dumpMetFile.exists()); String expectedMetString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<cas:metadata xmlns:cas=\"http: + "<keyval type=\"vector\">" + "<key>PGETask_Name</key>" + "<val>" + pgeTask.pgeMetadata.getMetadata(NAME) + "</val>" + "</keyval>" + "<keyval type=\"vector\">" + "<key>PGETask_DumpMetadata</key>" + "<val>" + pgeTask.pgeMetadata.getMetadata(DUMP_METADATA) + "</val>" + "</keyval>" + "</cas:metadata>"; Document dumpMetDoc = parseXmlFile(dumpMetFile); Document expectedMetDoc = parseXmlString(expectedMetString); Element dumpMetRoot, expectedMetRoot; dumpMetRoot = dumpMetDoc.getDocumentElement(); expectedMetRoot = expectedMetDoc.getDocumentElement(); NodeList dumpKeyList = dumpMetRoot.getElementsByTagName("key"); NodeList expectedKeyList = expectedMetRoot.getElementsByTagName("key"); NodeList dumpValList = dumpMetRoot.getElementsByTagName("val"); NodeList expectedValList = expectedMetRoot.getElementsByTagName("val"); assertEquals(dumpKeyList.getLength(), expectedKeyList.getLength()); assertEquals(dumpValList.getLength(), expectedValList.getLength()); Map<String, String> dumpKeyValMap = new ConcurrentHashMap<String, String>(); Map<String, String> expectedKeyValMap = new ConcurrentHashMap<String, String>(); for (int i = 0; i < dumpKeyList.getLength(); i++) { Node k1 = dumpKeyList.item(i); Node k2 = expectedKeyList.item(i); Node v1 = dumpValList.item(i); Node v2 = expectedValList.item(i); dumpKeyValMap.put(k1.getFirstChild().getNodeValue(), v1.getFirstChild().getNodeValue()); expectedKeyValMap.put(k2.getFirstChild().getNodeValue(), v2.getFirstChild().getNodeValue()); } assumeTrue(dumpKeyValMap.equals(expectedKeyValMap)); }