1   /*
2    * $Id: MemoryBPELProcessDAOTest.java,v 1.1 2004/12/15 14:18:20 patforna Exp $
3    *
4    * Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
5    * Berne University of Applied Sciences
6    * School of Engineering and Information Technology
7    * All rights reserved.
8    */
9   package bexee.dao;
10  
11  import junit.framework.TestCase;
12  import bexee.model.process.BPELProcess;
13  import bexee.model.process.Process;
14  import bexee.model.process.impl.BPELProcessImpl;
15  import bexee.model.process.impl.ProcessImpl;
16  
17  /***
18   * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:20 $
19   * @author Patric Fornasier
20   * @author Pawel Kowalski
21   */
22  public class MemoryBPELProcessDAOTest extends TestCase {
23  
24      private BPELProcessDAO dao;
25  
26      private BPELProcess processOne;
27  
28      private BPELProcess processTwo;
29  
30      private String processOneName = "ProcessOne";
31  
32      private String processTwoName = "ProcessTwo";
33  
34      protected void setUp() throws Exception {
35          super.setUp();
36  
37          dao = new MemoryBPELProcessDAO();
38  
39          // create BPEL processes
40          processOne = createBPELProcess(processOneName);
41          processOne.setSynchronous(true);
42          processTwo = createBPELProcess(processTwoName);
43      }
44  
45      /***
46       * Helper method to create a BPELProcess and set its name,
47       */
48      private BPELProcess createBPELProcess(String name) {
49          BPELProcess process = new BPELProcessImpl();
50          Process p = new ProcessImpl();
51          p.setName(name);
52          process.setProcess(p);
53  
54          return process;
55      }
56  
57      /***
58       * Test if we can insert a <code>BPELProcess</code> and find it again.
59       */
60      public void testInsertAndFind() throws Exception {
61  
62          // store the process
63          String idOne = dao.insert(processOne);
64          String idTwo = dao.insert(processTwo);
65          
66          assertEquals(processOneName, idOne);
67          assertEquals(processTwoName, idTwo);
68  
69          // explicitely nullify dao and process objects
70          dao = null;
71          processOne = null;
72          processTwo = null;
73  
74          // create a new dao and load process with primary key
75          dao = new MemoryBPELProcessDAO();
76          processOne = dao.find(idOne);
77          processTwo = dao.find(idTwo);
78  
79          // check if we retrieved the right objects
80          assertEquals(processOneName, dao.find(idOne).getName());
81          assertEquals(processTwoName, dao.find(idTwo).getName());
82      }
83      
84      /***
85       * Test if we can delete a <code>BPELProcess</code>.
86       */
87      public void testDelete() throws Exception {
88  
89          // store the process
90          String id = dao.insert(processOne);
91  
92          // check if the process is gone after calling the delete() method
93          assertNotNull(dao.find(id));
94          dao.delete(id);
95          assertNull(dao.find(id));
96      }
97  
98      /***
99       * Test if we can update a <code>BPELProcess</code>.
100      */
101     public void testUpdate() throws Exception {
102 
103         try {
104             dao.update(processOne);
105             fail("Calling update on a non-existing object should not work!");
106         } catch (DAOException e) {
107             // nothing to do here
108         }
109 
110         // store the process
111         dao.insert(processOne);
112 
113         // modify the process and update
114         String newName = "humba-rumba";
115         processOne.setSynchronous(false);
116         dao.update(processOne);
117 
118         // check if the process got updated
119         processOne = null;
120         processOne = dao.find(processOneName);
121         assertFalse(processOne.isSynchronous());
122     }
123     
124     /***
125      * Test if we can replace a <code>BPELProcess</code>.
126      */
127     public void testReplace() throws Exception {
128         
129         // replace a non-existing process
130         String id = dao.replace(processOne);
131         
132         // check if the process got inserted
133         processOne = null;
134         processOne = dao.find(id);        
135         assertEquals(processOneName, processOne.getName());
136         
137         // replace an existing process
138         String newId = dao.replace(processOne);
139         
140         // check if the process got updated (and we still have the same id)
141         processOne = null;
142         processOne = dao.find(id);
143         assertEquals(processOneName, processOne.getName());
144         assertEquals(id, newId);
145     }
146 }