use of org.jdom2.Content in project gocd by gocd.
the class UniqueOnCancelValidatorTest method shouldFailWithExceptionWhenThereIsMoreThanOneOnCancelTasksForAPluginInTask.
@Test
public void shouldFailWithExceptionWhenThereIsMoreThanOneOnCancelTasksForAPluginInTask() throws Exception {
ConfigElementImplementationRegistry registry = mock(ConfigElementImplementationRegistry.class);
when(registry.implementersOf(Task.class)).thenReturn(tasks(ExecTask.class, PluggableTask.class));
String content = "<cruise>" + " <pipeline>" + " <stage>" + " <jobs>" + " <job>" + " <tasks>" + " <task name=\"\">\n" + " <pluginConfiguration id=\"curl.task.plugin\" version=\"1\" />\n" + " <configuration>\n" + " <property>\n" + " <key>Url</key>\n" + " <value>With_On_Cancel</value>\n" + " </property>\n" + " </configuration>\n" + " <runif status=\"passed\" />\n" + " <oncancel>\n" + " <ant buildfile=\"blah\" target=\"blah1\" />\n" + " </oncancel>\n" + " <oncancel>\n" + " <ant buildfile=\"blah\" target=\"blah2\" />\n" + " </oncancel>\n" + " </task>" + " </tasks>" + " </job>" + " </jobs>" + " </stage>" + " </pipeline>" + "</cruise>";
try {
UniqueOnCancelValidator validator = new UniqueOnCancelValidator();
validator.validate(elementFor(content), registry);
} catch (Exception e) {
assertThat(e.getMessage(), is("Task [task] should not contain more than 1 oncancel task"));
}
}
use of org.jdom2.Content in project gocd by gocd.
the class GoConfigMigration method getCurrentSchemaVersion.
private int getCurrentSchemaVersion(String content) {
try {
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(new ByteArrayInputStream(content.getBytes()));
Element root = document.getRootElement();
String currentVersion = root.getAttributeValue(schemaVersion) == null ? "0" : root.getAttributeValue(schemaVersion);
return Integer.parseInt(currentVersion);
} catch (Exception e) {
throw bomb(e);
}
}
use of org.jdom2.Content in project gocd by gocd.
the class MagicalGoConfigXmlLoader method deserializeConfig.
public CruiseConfig deserializeConfig(String content) throws Exception {
String md5 = md5Hex(content);
Element element = parseInputStream(new ByteArrayInputStream(content.getBytes()));
LOGGER.debug("[Config Save] Updating config cache with new XML");
CruiseConfig configForEdit = classParser(element, BasicCruiseConfig.class, configCache, new GoCipher(), registry, new ConfigReferenceElements()).parse();
setMd5(configForEdit, md5);
configForEdit.setOrigins(new FileConfigOrigin());
return configForEdit;
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRMetaLink method createXML.
/**
* This method create a XML stream for all data in this class, defined by the MyCoRe XML MCRMetaLink definition for the given subtag.
*
* @exception MCRException
* if the content of this class is not valid
* @return a JDOM Element with the XML MCRMetaLink part
*/
@Override
public org.jdom2.Element createXML() throws MCRException {
Element elm = super.createXML();
elm.setAttribute("type", linktype, XLINK_NAMESPACE);
if (title != null) {
elm.setAttribute("title", title, XLINK_NAMESPACE);
}
if (label != null) {
elm.setAttribute("label", label, XLINK_NAMESPACE);
}
if (role != null) {
elm.setAttribute("role", role, XLINK_NAMESPACE);
}
if (linktype.equals("locator")) {
elm.setAttribute("href", href, XLINK_NAMESPACE);
} else {
elm.setAttribute("from", from, XLINK_NAMESPACE);
elm.setAttribute("to", to, XLINK_NAMESPACE);
}
return elm;
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRMetaNumber method createXML.
/**
* This method creates an XML element containing all data in this instance,
* as defined by the MyCoRe XML MCRNumber definition for the given subtag.
*
* @exception MCRException
* if the content of this instance is not valid
* @return a JDOM Element with the XML MCRNumber part
*/
@Override
public final org.jdom2.Element createXML() throws MCRException {
Element elm = super.createXML();
if (dimension != null && dimension.length() != 0) {
elm.setAttribute("dimension", dimension);
}
if (measurement != null && measurement.length() != 0) {
elm.setAttribute("measurement", measurement);
}
elm.addContent(getNumberAsString());
return elm;
}
Aggregations