public String getXML() throws KettleException { StringBuilder xml = new StringBuilder(); xml.append( "<" + XML_TAG + ">" ).append( Const.CR ); xml.append( XMLHandler.addTagValue( "statusdesc", statusDescription ) ); xml.append( XMLHandler.addTagValue( "memory_free", memoryFree ) ); xml.append( XMLHandler.addTagValue( "memory_total", memoryTotal ) ); xml.append( XMLHandler.addTagValue( "cpu_cores", cpuCores ) ); xml.append( XMLHandler.addTagValue( "cpu_process_time", cpuProcessTime ) ); xml.append( XMLHandler.addTagValue( "uptime", uptime ) ); xml.append( XMLHandler.addTagValue( "thread_count", threadCount ) ); xml.append( XMLHandler.addTagValue( "load_avg", loadAvg ) ); xml.append( XMLHandler.addTagValue( "os_name", osName ) ); xml.append( XMLHandler.addTagValue( "os_version", osVersion ) ); xml.append( XMLHandler.addTagValue( "os_arch", osArchitecture ) ); xml.append( " <transstatuslist>" ).append( Const.CR ); for ( int i = 0; i < transStatusList.size(); i++ ) { SlaveServerTransStatus transStatus = transStatusList.get( i ); xml.append( " " ).append( transStatus.getXML() ).append( Const.CR ); } xml.append( " </transstatuslist>" ).append( Const.CR ); xml.append( " <jobstatuslist>" ).append( Const.CR ); for ( int i = 0; i < jobStatusList.size(); i++ ) { SlaveServerJobStatus jobStatus = jobStatusList.get( i ); xml.append( " " ).append( jobStatus.getXML() ).append( Const.CR ); } xml.append( " </jobstatuslist>" ).append( Const.CR ); xml.append( "</" + XML_TAG + ">" ).append( Const.CR ); return xml.toString(); }
String xml = jobStatus.getXML(); data = xml.getBytes( Charset.forName( Const.XML_ENCODING ) ); out = response.getOutputStream();
protected void testXmlRoundTrip() throws KettleException { SlaveServerJobStatus metaToSave = createMeta(); Map<String, FieldLoadSaveValidator<?>> validatorMap = createValidatorMapAndInvokeSetters( xmlAttributes, metaToSave ); String xml = metaToSave.getXML(); SlaveServerJobStatus metaLoaded = SlaveServerJobStatus.fromXML( xml ); validateLoadedMeta( xmlAttributes, validatorMap, metaToSave, metaLoaded ); } }
@Test public void testNoDate() throws KettleException { String jobName = "testNullDate"; String id = UUID.randomUUID().toString(); String status = Trans.STRING_FINISHED; SlaveServerJobStatus js = new SlaveServerJobStatus( jobName, id, status ); String resultXML = js.getXML(); Node newJobStatus = XMLHandler.getSubNode( XMLHandler.loadXMLString( resultXML ), SlaveServerJobStatus.XML_TAG ); assertEquals( "The XML document should match after rebuilding from XML", resultXML, SlaveServerJobStatus.fromXML( resultXML ).getXML() ); assertEquals( "There should be one \"log_date\" node in the XML", 1, XMLHandler.countNodes( newJobStatus, "log_date" ) ); assertTrue( "The \"log_date\" node should have a null value", Utils.isEmpty( XMLHandler.getTagValue( newJobStatus, "log_date" ) ) ); }
@Test public void testWithDate() throws KettleException { String jobName = "testWithDate"; String id = UUID.randomUUID().toString(); String status = Trans.STRING_FINISHED; Date logDate = new Date(); SlaveServerJobStatus js = new SlaveServerJobStatus( jobName, id, status ); js.setLogDate( logDate ); String resultXML = js.getXML(); Node newJobStatus = XMLHandler.getSubNode( XMLHandler.loadXMLString( resultXML ), SlaveServerJobStatus.XML_TAG ); assertEquals( "The XML document should match after rebuilding from XML", resultXML, SlaveServerJobStatus.fromXML( resultXML ).getXML() ); assertEquals( "There should be one \"log_date\" node in the XML", 1, XMLHandler.countNodes( newJobStatus, "log_date" ) ); assertEquals( "The \"log_date\" node should match the original value", XMLHandler.date2string( logDate ), XMLHandler.getTagValue( newJobStatus, "log_date" ) ); }