KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > par > BpelArchiveParserTest


1 package org.jbpm.bpel.par;
2
3 import java.io.InputStream JavaDoc;
4 import java.util.List JavaDoc;
5 import java.util.zip.ZipInputStream JavaDoc;
6
7 import javax.wsdl.Definition;
8
9 import junit.framework.TestCase;
10
11 import org.jbpm.jpdl.par.ProcessArchive;
12
13 import org.jbpm.bpel.def.BpelDefinition;
14 import org.jbpm.bpel.def.Import;
15 import org.jbpm.bpel.xml.ArchiveWsdlLocator;
16 import org.jbpm.bpel.xml.BpelReader;
17
18 /**
19  * @author Alejandro Guízar
20  * @version $Revision: 1.2 $ $Date: 2005/06/07 02:08:04 $
21  */

22 public class BpelArchiveParserTest extends TestCase {
23   
24   private BpelArchiveParser bpelParser = new BpelArchiveParser();
25   private BpelDefinition processDefinition = new BpelDefinition();
26   
27   public BpelArchiveParserTest(String JavaDoc name) {
28     super(name);
29   }
30
31   public void testReadFromArchive() throws Exception JavaDoc {
32     ProcessArchive archive = createProcessArchive("archiveSample.zip");
33     // parse process definition
34
processDefinition.setLocation("processSample.bpel");
35     bpelParser.readFromArchive(archive, processDefinition);
36     // process name
37
assertEquals("sampleProcess", processDefinition.getName());
38     // import count
39
List JavaDoc imports = processDefinition.getImports().getImports();
40     assertEquals(1, imports.size());
41     // wsdl location
42
Import imp = (Import) imports.get(0);
43     assertEquals("wsdl/partnerLinkTypeSample.wsdl", imp.getLocation());
44     // wsdl target namespace
45
Definition definition = (Definition) imp.getDocument();
46     assertEquals("http://manufacturing.org/wsdl/purchase", definition.getTargetNamespace());
47   }
48   
49   public void testReadFromArchive_1_1() throws Exception JavaDoc {
50     ProcessArchive archive = createProcessArchive("archiveSample-1_1.zip");
51     // add wsdl document
52
Import imp = new Import();
53     imp.setNamespace("http://manufacturing.org/wsdl/purchase");
54     imp.setLocation("wsdl/partnerLinkTypeSample-1_1.wsdl");
55     imp.setType(Import.Type.WSDL);
56     BpelReader.getInstance().readWsdlDocument(imp, new ArchiveWsdlLocator("", archive));
57     processDefinition.getImports().addImport(imp);
58     // parse process definition
59
processDefinition.setLocation("bpel/processSample-1_1.bpel");
60     bpelParser.readFromArchive(archive, processDefinition);
61     // process name
62
assertEquals("sampleProcess", processDefinition.getName());
63     // import count
64
List JavaDoc imports = processDefinition.getImports().getImports();
65     assertEquals(1, imports.size());
66   }
67   
68   private ProcessArchive createProcessArchive(String JavaDoc resourceName) throws Exception JavaDoc {
69     InputStream JavaDoc archiveStream = getClass().getResourceAsStream(resourceName);
70     ProcessArchive archive = new ProcessArchive(new ZipInputStream JavaDoc(archiveStream));
71     archiveStream.close();
72     return archive;
73   }
74 }
75
Popular Tags