use of org.dom4j.dom.DOMDocument in project gocd by gocd.
the class JobXmlViewModelTest method shouldMaskSecureVariables.
@Test
public void shouldMaskSecureVariables() throws IOException, DocumentException {
EnvironmentVariableConfig envVariable = new EnvironmentVariableConfig(null, "stdVariable", "value1", false);
EnvironmentVariableConfig secureEnvVariable = new EnvironmentVariableConfig(new GoCipher(), "secureVariable", "value2", true);
EnvironmentVariablesConfig environmentVariablesConfig = new EnvironmentVariablesConfig();
environmentVariablesConfig.add(envVariable);
environmentVariablesConfig.add(secureEnvVariable);
when(jobPlan.getVariables()).thenReturn(environmentVariablesConfig);
DOMDocument document = (DOMDocument) jobXmlViewModel.toXml(xmlWriterContext);
Assert.assertThat(document.asXML(), containsString("<environmentvariables><variable name=\"stdVariable\"><![CDATA[value1]]></variable><variable name=\"secureVariable\"><![CDATA[****]]></variable></environmentvariables>"));
}
use of org.dom4j.dom.DOMDocument in project xwiki-platform by xwiki.
the class Package method toXML.
/**
* Write the package.xml file to an OutputStream
*
* @param out the OutputStream to write to
* @param context curent XWikiContext
* @throws IOException when an error occurs during streaming operation
* @since 2.3M2
*/
public void toXML(OutputStream out, XWikiContext context) throws IOException {
XMLWriter wr = new XMLWriter(out, new OutputFormat("", true, context.getWiki().getEncoding()));
Document doc = new DOMDocument();
wr.writeDocumentStart(doc);
toXML(wr);
wr.writeDocumentEnd(doc);
}
use of org.dom4j.dom.DOMDocument in project xwiki-platform by xwiki.
the class DOMXMLWriterTest method writeVersusWriteOpen.
/**
* Before 3.0M2 there was a bug where write and writeOpen were reversed.
*
* @throws IOException
* @see "XWIKI-5937"
*/
@Test
public void writeVersusWriteOpen() throws IOException {
Document doc = new DOMDocument();
DOMXMLWriter writer = new DOMXMLWriter(doc);
DOMElement e = new DOMElement("a");
writer.writeOpen(e);
writer.write(new DOMElement("b"));
writer.writeClose(e);
writer.close();
Assert.assertNotNull(doc.getRootElement().element("b"));
doc = new DOMDocument();
writer = new DOMXMLWriter(doc);
e = new DOMElement("c");
writer.write(e);
writer.write(new DOMElement("d"));
writer.close();
Assert.assertNull(doc.getRootElement().element("d"));
}
use of org.dom4j.dom.DOMDocument in project narayana by jbosstm.
the class XMLResultsServlet method doStatus.
public void doStatus(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
HttpSession session = request.getSession();
final FullTestResult testResult = (FullTestResult) session.getAttribute(TestConstants.ATTRIBUTE_TEST_RESULT);
DOMDocument report = new DOMDocument();
DOMElement testsuite = new DOMElement("testsuite");
report.setRootElement(testsuite);
if (testResult == null) {
// No JUnit test results generated.
} else {
List passedTests = testResult.getPassedTests();
List failedTests = testResult.getFailedTests();
List errorTests = testResult.getErrorTests();
final int runCount = testResult.runCount();
final int errorCount = testResult.errorCount();
final int failureCount = testResult.failureCount();
testsuite.addAttribute("name", "com.jboss.transaction.txinterop.interop.InteropTestSuite");
testsuite.addAttribute("errors", Integer.toString(errorCount));
testsuite.addAttribute("failures", Integer.toString(failureCount));
testsuite.addAttribute("hostname", request.getServerName());
testsuite.addAttribute("tests", Integer.toString(runCount));
testsuite.addAttribute("timestamp", new Date().toString());
DOMElement properties = new DOMElement("properties");
testsuite.add(properties);
DOMElement status = newPropertyDOMElement("status");
properties.add(status);
status.addAttribute("value", "finished");
long totalDuration = 0;
if (!passedTests.isEmpty()) {
Iterator passedTestsIterator = passedTests.iterator();
while (passedTestsIterator.hasNext()) {
FullTestResult.PassedTest passedTest = (FullTestResult.PassedTest) passedTestsIterator.next();
totalDuration += passedTest.duration;
final String name = passedTest.test.toString();
final String description = (String) TestConstants.DESCRIPTIONS.get(name);
testsuite.add(newTestcase(passedTest.test.getClass().getName(), name + ": " + description, passedTest.duration));
}
}
if (!failedTests.isEmpty()) {
Iterator failedTestsIterator = failedTests.iterator();
while (failedTestsIterator.hasNext()) {
FullTestResult.FailedTest failedTest = (FullTestResult.FailedTest) failedTestsIterator.next();
totalDuration += failedTest.duration;
final String name = failedTest.test.toString();
final String description = (String) TestConstants.DESCRIPTIONS.get(name);
CharArrayWriter charArrayWriter = new CharArrayWriter();
PrintWriter printWriter = new PrintWriter(charArrayWriter, true);
failedTest.assertionFailedError.printStackTrace(printWriter);
printWriter.close();
charArrayWriter.close();
testsuite.add(newFailedTestcase(failedTest.test.getClass().getName(), name + ": " + description, failedTest.duration, failedTest.assertionFailedError.getMessage(), charArrayWriter.toString()));
}
}
if (!errorTests.isEmpty()) {
Iterator errorTestsIterator = errorTests.iterator();
while (errorTestsIterator.hasNext()) {
FullTestResult.ErrorTest errorTest = (FullTestResult.ErrorTest) errorTestsIterator.next();
totalDuration += errorTest.duration;
final String name = errorTest.test.toString();
final String description = (String) TestConstants.DESCRIPTIONS.get(name);
CharArrayWriter charArrayWriter = new CharArrayWriter();
PrintWriter printWriter = new PrintWriter(charArrayWriter, true);
errorTest.throwable.printStackTrace(printWriter);
printWriter.close();
charArrayWriter.close();
System.out.println("charArrayWriter.toString()=" + charArrayWriter.toString());
testsuite.add(newErrorTestcase(errorTest.test.getClass().getName(), name + ": " + description, errorTest.duration, errorTest.throwable.getMessage(), charArrayWriter.toString()));
}
}
// total time of all tests
testsuite.addAttribute("time", Float.toString(totalDuration / 1000f));
}
String logContent = null;
final String logName = (String) session.getAttribute(TestConstants.ATTRIBUTE_LOG_NAME);
if (logName != null) {
try {
logContent = TestLogController.readLog(logName);
} catch (final Throwable th) {
log("Error reading log file", th);
}
}
testsuite.add(new DOMElement("system-out").addCDATA((logContent != null) ? logContent : ""));
testsuite.add(new DOMElement("system-err").addCDATA(""));
XMLWriter outputter = new XMLWriter(response.getWriter(), OutputFormat.createPrettyPrint());
try {
outputter.write(testsuite);
outputter.close();
} catch (IOException e) {
throw new ServletException(e);
}
}
use of org.dom4j.dom.DOMDocument in project gocd by gocd.
the class StageXmlViewModel method toXml.
@Override
public Document toXml(XmlWriterContext writerContext) {
DOMElement root = new DOMElement("stage");
root.addAttribute("name", stage.getName()).addAttribute("counter", String.valueOf(stage.getCounter()));
Document document = new DOMDocument(root);
root.addElement("link").addAttribute("rel", "self").addAttribute("href", httpUrl(writerContext.getBaseUrl()));
StageIdentifier stageId = stage.getIdentifier();
root.addElement("id").addCDATA(stageId.asURN());
String pipelineName = stageId.getPipelineName();
root.addElement("pipeline").addAttribute("name", pipelineName).addAttribute("counter", String.valueOf(stageId.getPipelineCounter())).addAttribute("label", stageId.getPipelineLabel()).addAttribute("href", writerContext.getBaseUrl() + "/api/pipelines/" + pipelineName + "/" + stage.getPipelineId() + ".xml");
root.addElement("updated").addText(DateUtils.formatISO8601(stage.latestTransitionDate()));
root.addElement("result").addText(stage.getResult().toString());
root.addElement("state").addText(stage.status());
root.addElement("approvedBy").addCDATA(stage.getApprovedBy());
Element jobs = root.addElement("jobs");
for (JobInstance jobInstance : stage.getJobInstances()) {
jobs.addElement("job").addAttribute("href", writerContext.getBaseUrl() + "/api/jobs/" + jobInstance.getId() + ".xml");
}
return document;
}
Aggregations