1 package org.jbpm.jpdl.par; 2 3 import java.io.*; 4 import java.util.*; 5 import java.util.zip.ZipEntry ; 6 import java.util.zip.ZipInputStream ; 7 import java.util.zip.ZipOutputStream ; 8 9 import org.jbpm.db.*; 10 import org.jbpm.graph.def.*; 11 import org.jbpm.instantiation.*; 12 13 public class ProcessArchiveDeployerDbTest extends AbstractDbTestCase { 14 15 String getTestClassesDir() { 16 return ProcessArchiveDeployerDbTest.class.getProtectionDomain().getCodeSource().getLocation().getFile(); 17 } 18 19 public void testDeployProcess() throws Exception { 20 21 String fileName = getTestClassesDir()+"/testarchive.par"; 23 FileOutputStream fileOutputStream = new FileOutputStream(fileName); 24 ZipOutputStream zipOutputStream = new ZipOutputStream (fileOutputStream); 25 addEntry(zipOutputStream, "processdefinition.xml", "org/jbpm/jpdl/par/deployableprocess.xml"); 26 zipOutputStream.close(); 27 28 ZipInputStream zipInputStream = new ZipInputStream (new FileInputStream(fileName)); 30 ProcessArchiveDeployer.deployZipInputStream(zipInputStream, AbstractDbTestCase.getJbpmSessionFactory()); 31 32 newTransaction(); 33 34 List allProcessDefinitions = graphSession.findAllProcessDefinitions(); 35 assertEquals(1, allProcessDefinitions.size()); 36 ProcessDefinition processDefinition = (ProcessDefinition) allProcessDefinitions.get(0); 37 assertEquals("the deployable process", processDefinition.getName()); 38 } 39 40 public void testDeployProcessWithFile() throws Exception { 41 String fileName = getTestClassesDir()+"/testarchive.par"; 43 FileOutputStream fileOutputStream = new FileOutputStream(fileName); 44 ZipOutputStream zipOutputStream = new ZipOutputStream (fileOutputStream); 45 addEntry(zipOutputStream, "processdefinition.xml", "org/jbpm/jpdl/par/deployableprocess.xml"); 46 addEntry(zipOutputStream, "classes/org/jbpm/jpdl/par/ProcessArchiveDeployerDbTest.class", "org/jbpm/jpdl/par/ProcessArchiveDeployerDbTest.class"); 47 zipOutputStream.close(); 48 49 ZipInputStream zipInputStream = new ZipInputStream (new FileInputStream(fileName)); 51 ProcessArchiveDeployer.deployZipInputStream(zipInputStream, AbstractDbTestCase.getJbpmSessionFactory()); 52 53 newTransaction(); 54 55 List allProcessDefinitions = graphSession.findAllProcessDefinitions(); 56 assertEquals(1, allProcessDefinitions.size()); 57 ProcessDefinition processDefinition = (ProcessDefinition) allProcessDefinitions.get(0); 58 byte[] processBytes = processDefinition.getFileDefinition().getBytes("classes/org/jbpm/jpdl/par/ProcessArchiveDeployerDbTest.class"); 59 byte[] expectedBytes = ProcessArchive.readBytes(ClassLoaderUtil.getStream("org/jbpm/jpdl/par/ProcessArchiveDeployerDbTest.class")); 60 61 assertTrue(Arrays.equals(expectedBytes, processBytes)); 62 } 63 64 public void testDeployTwoVersionOfProcess() throws Exception { 65 66 String fileName = getTestClassesDir()+"/testarchive.par"; 68 FileOutputStream fileOutputStream = new FileOutputStream(fileName); 69 ZipOutputStream zipOutputStream = new ZipOutputStream (fileOutputStream); 70 addEntry(zipOutputStream, "processdefinition.xml", "org/jbpm/jpdl/par/deployableprocess.xml"); 71 zipOutputStream.close(); 72 73 ZipInputStream zipInputStream = new ZipInputStream (new FileInputStream(fileName)); 75 ProcessArchiveDeployer.deployZipInputStream(zipInputStream, AbstractDbTestCase.getJbpmSessionFactory()); 76 77 newTransaction(); 78 79 zipInputStream = new ZipInputStream (new FileInputStream(fileName)); 81 ProcessArchiveDeployer.deployZipInputStream(zipInputStream, AbstractDbTestCase.getJbpmSessionFactory()); 82 83 newTransaction(); 84 85 assertEquals(2, graphSession.findAllProcessDefinitions().size()); 86 assertEquals(2, graphSession.findLatestProcessDefinition("the deployable process").getVersion()); 87 } 88 89 public void testDeployProcessWithValidation() throws Exception { 90 String fileName = getTestClassesDir()+"/testarchive.par"; 92 FileOutputStream fileOutputStream = new FileOutputStream(fileName); 93 ZipOutputStream zipOutputStream = new ZipOutputStream (fileOutputStream); 94 addEntry(zipOutputStream, "processdefinition.xml", "org/jbpm/jpdl/par/deployableprocesswithns.xml"); 95 zipOutputStream.close(); 96 97 ZipInputStream zipInputStream = new ZipInputStream (new FileInputStream(fileName)); 99 ProcessArchiveDeployer.deployZipInputStream(zipInputStream, AbstractDbTestCase.getJbpmSessionFactory()); 100 101 newTransaction(); 102 103 List allProcessDefinitions = graphSession.findAllProcessDefinitions(); 104 assertEquals(1, allProcessDefinitions.size()); 105 ProcessDefinition processDefinition = (ProcessDefinition) allProcessDefinitions.get(0); 106 assertEquals("the deployable process", processDefinition.getName()); 107 } 108 109 private static void addEntry(ZipOutputStream zipOutputStream, String entryName, String resource) throws IOException { 110 InputStream inputStream = ClassLoaderUtil.getStream(resource); 111 byte[] bytes = ProcessArchive.readBytes(inputStream); 112 addEntry(zipOutputStream, entryName, bytes); 113 } 114 115 private static void addEntry(ZipOutputStream zipOutputStream, String entryName, byte[] content) throws IOException { 116 ZipEntry zipEntry = new ZipEntry (entryName); 117 zipOutputStream.putNextEntry(zipEntry); 118 zipOutputStream.write(content); 119 } 120 } 121 | Popular Tags |