1 package org.jbpm.jpdl.convert; 2 3 import java.io.ByteArrayOutputStream ; 4 import java.io.IOException ; 5 import java.util.zip.ZipInputStream ; 6 7 import junit.framework.TestCase; 8 9 import org.dom4j.Document; 10 import org.dom4j.io.SAXReader; 11 import org.jbpm.graph.def.ProcessDefinition; 12 import org.jbpm.jpdl.par.ProcessArchive; 13 14 public class ConversionTestCase extends TestCase { 15 16 private static final String TESTPAR_1 = "payraiseprocess-2.0.par"; 17 private static final String TESTPAR_2 = "exampleprocess-2.0.par"; 18 19 public void testPDConversion(){ 20 21 Converter converter = new Converter(); 22 try 23 { 24 SAXReader reader = new SAXReader(); 25 26 Document doc = reader.read( 27 this.getClass().getResourceAsStream("jpdl-sample-2.0.xml") ); 28 Document doc30 = converter.convert( doc ); 29 ByteArrayOutputStream bos = new ByteArrayOutputStream (); 30 31 converter.serializetoXML( bos, doc30) ; 32 33 System.out.println(bos.toString()); 34 35 ProcessDefinition.parseXmlString( bos.toString() ); 36 } 37 catch(Exception ex) 38 { 39 fail("2.0 PDL did not convert successfully to 3.0 PDL" + ex.toString()); 40 } 41 } 42 43 public void testParConversion01(){ 44 45 Converter converter = new Converter(); 46 47 try 48 { 49 ProcessArchive pa = new ProcessArchive( 51 new ZipInputStream ( 52 this.getClass().getResourceAsStream( TESTPAR_1 ) ) ); 53 String result = converter.convertPar( pa ); 54 55 if (result == null) 56 fail("2.0 PAR did not convert successfully."); 57 else 58 { 59 System.out.println(result); 60 try 61 { 62 ProcessDefinition.parseXmlString( result ); 63 } 64 catch(Exception ex) 65 { 66 fail("Converted PDL is invalid " + ex.toString()); 67 } 68 } 69 } 70 catch(IOException ioe) 71 { 72 fail("Unexpected IO error " + ioe.toString()); 73 } 74 } 75 76 public void testParConversion02(){ 77 78 Converter converter = new Converter(); 79 80 try 81 { 82 ProcessArchive pa = new ProcessArchive( 84 new ZipInputStream ( 85 this.getClass().getResourceAsStream( TESTPAR_2 ) ) ); 86 String result = converter.convertPar( pa ); 87 88 if (result == null) 89 fail("2.0 PAR did not convert successfully."); 90 else 91 { 92 System.out.println(result); 93 try 94 { 95 ProcessDefinition.parseXmlString( result ); 96 } 97 catch(Exception ex) 98 { 99 fail("Converted PDL is invalid " + ex.toString()); 100 } 101 } 102 } 103 catch(IOException ioe) 104 { 105 fail("Unexpected IO error " + ioe.toString()); 106 } 107 108 } 109 110 public void testDirectoryConversion(){ 111 112 try 113 { 114 Converter.main( 115 new String [] {"src/java.jbpm.test/org/jbpm/jpdl/convert", 116 "src/java.jbpm.test/org/jbpm/jpdl/convert/output"} ); 117 } 118 catch(Exception ex) 119 { 120 fail("Directory conversion failed: " + ex.toString()); 121 } 122 } 123 } 124 | Popular Tags |