Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/enableit/db/daf/CastorJdoDafTest.java


1   package org.enableit.db.daf;
2   
3   // Java imports
4   import java.io.File ;
5   import java.io.FileReader ;
6   import java.io.FileWriter ;
7   import java.io.StringReader ;
8   import java.io.StringWriter ;
9   import java.math.BigDecimal ;
10  import java.text.SimpleDateFormat ;
11  import java.util.Arrays ;
12  import java.util.Date ;
13  import java.util.Iterator ;
14  import java.util.List ;
15  
16  // Testing framework imports
17  import junit.framework.*;
18  
19  // Log4J imports
20  import org.apache.log4j.Category;
21  
22  // My imports 
23  import org.enableit.apps.task.TaskForm ; 
24  import org.enableit.apps.task.TaskForm2 ; 
25  import org.enableit.db.daf.* ; 
26  import org.enableit.db.daf.castor.* ; 
27  
28  /**
29   * Tests ...
30   */
31  public class CastorJdoDafTest extends TestCase 
32  {
33  /*
34   * Properties
35   */
36  
37      /**
38       * Define a static Category variable for logging.
39       */
40      private static Category logger = Category.getInstance(CastorJdoDafTest.class);
41  
42      private static TaskForm2 bean ; 
43      private static TaskForm2 existingBean ; 
44  
45  /*
46   * Constructors
47   */
48    /**
49     * Default Constructor
50     */
51    public CastorJdoDafTest(String name)
52    {
53          super(name) ;
54    }
55  
56  /*
57   * Methods
58   */
59  
60      /**
61       * Defines all the tests for the Web Service application including
62       * tests in this class.
63       */
64      public static Test suite() {
65          TestSuite suite = new TestSuite(CastorJdoDafTest.class);
66          return suite;
67      }
68  
69      /**
70       * Define the test environment. 
71       */
72      protected void setUp()
73      throws java.lang.Exception
74      {
75          bean = new TaskForm2() ; 
76          bean.setTaskName("testing daf") ; 
77          bean.setTaskDesc("desc") ; 
78          bean.setTaskCreationDate(new Date()) ; 
79          bean.setTaskDueDate(new Date()) ; 
80          bean.setTaskAllocatedTo("tim") ; 
81          bean.setTaskCreatedBy("tim") ; 
82          bean.setCategoryId(new Long(1)) ; 
83          bean.setStatusId(new Long(1)) ; 
84          bean.setPriorityId(new Long(1)) ; 
85      
86          existingBean = bean ; 
87          existingBean.setTaskId(new Long(75)) ; 
88          
89      }
90  
91      /** 
92       * Run a test to configure the Data Abstraction Factory from a resource.
93       * 
94       */
95      public void testInitFromResource() 
96      { 
97  
98          
99  
100     } 
101     
102 
103     /** 
104      * Run a test to create a Bean using the DataAbstractionFacade and its factory.
105      * 
106      */
107     public void testCreate() 
108     { 
109         try {
110             DataAbstractionFacade daf = DataAbstractionFacadeFactory.getInstance(bean) ;
111             assertNotNull("Received null DAF", daf) ;
112             assertEquals("Received wrong DAF", daf.getClass().getName(), "org.enableit.db.daf.castor.CastorJdoDaf") ;
113 
114             bean = (TaskForm2)daf.create(bean) ; 
115             assertNotNull("Null bean returned from DAF. ", bean) ; 
116             assertNotNull("No key set on bean.", bean.getTaskId()) ; 
117             logger.debug("Returned bean=" + bean) ; 
118         } catch (Exception e) {
119             e.printStackTrace() ; 
120             fail(e.getClass().getName() + ":" + e.getMessage()) ; 
121         } 
122 
123     } 
124 
125     /** 
126      * Run a test to update a Bean using the DataAbstractionFacade and its factory.
127      * 
128      */
129     public void testModify() 
130     { 
131         try {
132             DataAbstractionFacade daf = DataAbstractionFacadeFactory.getInstance(bean) ;
133             assertNotNull("Received null DAF", daf) ;
134             assertEquals("Received wrong DAF", daf.getClass().getName(), "org.enableit.db.daf.castor.CastorJdoDaf") ;
135 
136             existingBean.setTaskDesc("modified desc") ; 
137             existingBean = (TaskForm2)daf.modify(existingBean) ; 
138             assertNotNull("Null existingBean returned from DAF. ", existingBean) ; 
139             assertNotNull("No key set on existingBean.", existingBean.getTaskId()) ; 
140             logger.debug("Returned existingBean=" + existingBean) ; 
141         } catch (Exception e) {
142             e.printStackTrace() ; 
143             fail(e.getClass().getName() + ":" + e.getMessage()) ; 
144         } 
145 
146     } 
147 
148     /** 
149      * Run a test to retrieve a Bean using the DataAbstractionFacade and its factory.
150      * 
151      */
152     public void testLoad() 
153     { 
154         try {
155             DataAbstractionFacade daf = DataAbstractionFacadeFactory.getInstance(bean) ;
156             assertNotNull("Received null DAF", daf) ;
157             assertEquals("Received wrong DAF", daf.getClass().getName(), "org.enableit.db.daf.castor.CastorJdoDaf") ;
158 
159             existingBean = (TaskForm2)daf.load(existingBean) ; 
160             assertNotNull("Null existingBean returned from DAF. ", existingBean) ; 
161             assertNotNull("No key set on existingBean.", existingBean.getTaskId()) ; 
162             logger.debug("Returned existingBean=" + existingBean) ; 
163         } catch (Exception e) {
164             e.printStackTrace() ; 
165             fail(e.getClass().getName() + ":" + e.getMessage()) ; 
166         } 
167 
168     } 
169 
170     /** 
171      * Run a test to delete a Bean using the DataAbstractionFacade and its factory.
172      * 
173      */
174     public void testRemove() 
175     { 
176         try {
177             DataAbstractionFacade daf = DataAbstractionFacadeFactory.getInstance(bean) ;
178             assertNotNull("Received null DAF", daf) ;
179             assertEquals("Received wrong DAF", daf.getClass().getName(), "org.enableit.db.daf.castor.CastorJdoDaf") ;
180 
181             existingBean = (TaskForm2)daf.remove(existingBean) ; 
182             assertNotNull("Null existingBean returned from DAF. ", existingBean) ; 
183             assertNotNull("No key set on existingBean.", existingBean.getTaskId()) ; 
184             logger.debug("Returned existingBean=" + existingBean) ; 
185         } catch (Exception e) {
186             e.printStackTrace() ; 
187             fail(e.getClass().getName() + ":" + e.getMessage()) ; 
188         } 
189 
190     } 
191 
192 }