@Test public void marshallJobExecutionTest() throws Exception { JobExecution jobExecution = JobExecutionTestUtils.getJobExecution(); JobExecutionAdapter adapter = new JobExecutionAdapter(); jaxb2Marshaller.marshal(adapter.marshal(jobExecution), result); Fragment frag = new Fragment(new DOMBuilder().build(doc)); frag.setNamespaces(getNamespaceProvider().getNamespaces()); frag.prettyPrint(); frag.assertElementExists("/msb:jobExecution/msb:id"); frag.assertElementExists("/msb:jobExecution/msb:createDateTime"); frag.assertElementValue("/msb:jobExecution/msb:status", "STARTING"); frag.assertElementExists("/msb:jobExecution/msb:jobInstance"); frag.assertElementExists("/msb:jobExecution/msb:jobParameters"); frag.assertElementExists("/msb:jobExecution/msb:stepExecutions"); frag.assertElementExists("/msb:jobExecution/msb:executionContext"); List<Fragment> steps = frag.getFragments("msb:jobExecution/msb:stepExecutions/msb:stepExecution"); steps.get(0).assertElementValue("/msb:stepExecution/msb:stepName", "sampleStep1"); steps.get(1).assertElementValue("/msb:stepExecution/msb:stepName", "sampleStep2"); }
@Test public void marshallStepExecutionTest() throws Exception { JobInstance jobInstance = new JobInstance(1234L, "test"); JobExecution jobExecution = new JobExecution(123L); jobExecution.setJobInstance(jobInstance); StepExecution step = new StepExecution("testStep", jobExecution); step.setLastUpdated(new Date(System.currentTimeMillis())); StepExecutionAdapter adapter = new StepExecutionAdapter(); AdaptedStepExecution adStep = adapter.marshal(step); jaxb2Marshaller.marshal(adStep, result); Fragment frag = new Fragment(new DOMBuilder().build(doc)); frag.setNamespaces(getNamespaceProvider().getNamespaces()); frag.prettyPrint(); frag.assertElementExists("/msb:stepExecution"); frag.assertElementExists("/msb:stepExecution/msb:lastUpdated"); frag.assertElementValue("/msb:stepExecution/msb:stepName", "testStep"); }
@Test public void marshallExecutionContextTest() throws Exception { ExecutionContext ec = new ExecutionContext(); ec.putString("testName", "testValue"); ec.putLong("testLong", 123L); ec.putDouble("testDouble", 123D); ec.putInt("testInteger", 123); ExecutionContextAdapter adapter = new ExecutionContextAdapter(); jaxb2Marshaller.marshal(adapter.marshal(ec), result); Fragment frag = new Fragment(new DOMBuilder().build(doc)); frag.setNamespaces(getNamespaceProvider().getNamespaces()); frag.prettyPrint(); frag.assertElementExists("/msb:executionContext/msb:map/entry/key[text() = 'testName']"); frag.assertElementExists("/msb:executionContext/msb:map/entry/value[@xsi:type = 'xs:int'][text() = '123']"); frag.assertElementExists("/msb:executionContext/msb:map/entry/value[@xsi:type = 'xs:long'][text() = '123']"); frag.assertElementExists("/msb:executionContext/msb:map/entry/value[@xsi:type = 'xs:string'][text() = 'testValue']"); frag.assertElementExists("/msb:executionContext/msb:map/entry/value[@xsi:type = 'xs:double'][text() = '123.0']"); frag.assertElementExists("/msb:executionContext/msb:hashCode"); }
public org.jdom2.Document getJDomDocument() throws XMLException { org.dom4j.io.DOMWriter d4Writer = new org.dom4j.io.DOMWriter(); try { DomDocument = d4Writer.write(dom4JDocument); } catch (DocumentException e) { throw new XMLException(e.getMessage()); } JDomDocument = new DOMBuilder().build(DomDocument); if (JDomDocument != null) return JDomDocument; else throw new XMLException("Invalid operation! Document = null"); }
@Test public void marshallJobParametersTest() throws Exception { JobParameters params = JobParametersTestUtils.getJobParameters(); JobParametersAdapter adapter = new JobParametersAdapter(); AdaptedJobParameters adaptedParams = adapter.marshal(params); jaxb2Marshaller.marshal(adaptedParams, result); Fragment frag = new Fragment(new DOMBuilder().build(doc)); frag.setNamespaces(getNamespaceProvider().getNamespaces()); frag.prettyPrint(); frag.assertElementExists("/msb:jobParameters/msb:jobParameter[@key = 'stringTest' and text() = 'Joe Cool' and @identifier = 'true']"); frag.assertElementExists("/msb:jobParameters/msb:jobParameter[@key = 'longTest' and text() = '1239' and @identifier = 'false']"); frag.assertElementExists("/msb:jobParameters/msb:jobParameter[@key = 'start' and @identifier = 'false']"); frag.assertElementExists("/msb:jobParameters/msb:jobParameter[@key = 'doubleTest' and text() = '1.35' and @identifier = 'false']"); }
@Test public void marshallJobInstanceTest() throws Exception { JobInstance jobInstance = new JobInstance(123L, "test"); JobInstanceAdapter adapter = new JobInstanceAdapter(); jaxb2Marshaller.marshal(adapter.marshal(jobInstance), result); Fragment frag = new Fragment(new DOMBuilder().build(doc)); frag.setNamespaces(getNamespaceProvider().getNamespaces()); frag.prettyPrint(); frag.assertElementValue("/msb:jobInstance/msb:id", "123"); frag.assertElementValue("/msb:jobInstance/msb:jobName", "test"); }
private void output(final Document document, final File tmp) throws IOException { DOMBuilder domBuilder = new DOMBuilder(); org.jdom2.Document doc = domBuilder.build(document); XMLOutputter out = new XMLOutputter(); Writer w = new OutputStreamWriter(new FileOutputStream(tmp), "UTF8"); BufferedWriter writer = new BufferedWriter(w); out.output(doc, writer); writer.close(); }
/** * Convert a DOM Document to a JDOM Document * * @param node * * @return */ public static org.jdom2.Document convert(org.w3c.dom.Document node) { if (node == null) return null; // Convert null->null DOMBuilder builder = new DOMBuilder(); return builder.build(node); }
/** * Convert a DOM Element to a JDOM Element * * @param node * * @return */ public static org.jdom2.Element convert(org.w3c.dom.Element node) { if (node == null) return null; // Convert null->null DOMBuilder builder = new DOMBuilder(); return builder.build(node); }
@Override public org.jdom2.Document asXML() throws JDOMException { return new DOMBuilder().build(dom); }