mirror of
https://github.com/Fishwaldo/rundeck-api-java-client.git
synced 2025-07-08 22:19:44 +00:00
Generates project xml document for creation request
This commit is contained in:
parent
7543d5d630
commit
303a3dec57
2 changed files with 63 additions and 0 deletions
|
@ -0,0 +1,38 @@
|
||||||
|
package org.rundeck.api.generator;
|
||||||
|
|
||||||
|
import org.dom4j.Document;
|
||||||
|
import org.dom4j.DocumentFactory;
|
||||||
|
import org.dom4j.Element;
|
||||||
|
import org.rundeck.api.domain.ProjectConfig;
|
||||||
|
import org.rundeck.api.domain.RundeckProject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ProjectGenerator is ...
|
||||||
|
*
|
||||||
|
* @author greg
|
||||||
|
* @since 2014-02-27
|
||||||
|
*/
|
||||||
|
public class ProjectGenerator {
|
||||||
|
RundeckProject project;
|
||||||
|
|
||||||
|
public ProjectGenerator(RundeckProject project) {
|
||||||
|
this.project = project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Document generate() {
|
||||||
|
Document projectDom = DocumentFactory.getInstance().createDocument();
|
||||||
|
Element rootElem = projectDom.addElement("project");
|
||||||
|
rootElem.addElement("name").setText(project.getName());
|
||||||
|
ProjectConfig configuration = project.getProjectConfig();
|
||||||
|
if (null != configuration) {
|
||||||
|
|
||||||
|
Element config = rootElem.addElement("config");
|
||||||
|
for (String s : configuration.getProperties().keySet()) {
|
||||||
|
Element property = config.addElement("property");
|
||||||
|
property.addAttribute("key", s);
|
||||||
|
property.addAttribute("value", configuration.getProperties().get(s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return projectDom;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package org.rundeck.api.generator;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
import org.dom4j.Document;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.rundeck.api.domain.RundeckProject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ProjectGeneratorTest is ...
|
||||||
|
*
|
||||||
|
* @author greg
|
||||||
|
* @since 2014-02-27
|
||||||
|
*/
|
||||||
|
public class ProjectGeneratorTest {
|
||||||
|
@Test
|
||||||
|
public void generate() {
|
||||||
|
RundeckProject project = new RundeckProject();
|
||||||
|
project.setName("monkey1");
|
||||||
|
|
||||||
|
Document doc = new ProjectGenerator(project).generate();
|
||||||
|
Assert.assertEquals("project", doc.getRootElement().getName());
|
||||||
|
Assert.assertNotNull(doc.selectSingleNode("/project/name"));
|
||||||
|
Assert.assertEquals("monkey1", doc.selectSingleNode("/project/name").getText());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue