View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ken.dao;
17  
18  import org.junit.Test;
19  
20  /**
21   * This abstract class puts forward a simple framework for testing the basic 
22   * persistence of business objects in the system.
23   * 
24   * @author Kuali Rice Team (rice.collab@kuali.org)
25   */
26  public abstract class BusinessObjectPersistenceTestCaseBase extends BusinessObjectDaoTestCaseBase {
27  
28      /**
29       * This method is responsible for testing the basic persistence of a business object.
30       */
31      @Test
32      public void testBasicPersistence() {
33  	setup();
34  	assertTrue(insert());
35  	assertTrue(retrieve());
36  	assertTrue(update());
37  	assertTrue(validateChanges());
38  	assertTrue(delete());
39      }
40      
41      /**
42       * This method should be overridden and implemented to perform a setup of any dependent objects that 
43       * business object may need to reference.  Since we are using Spring's automated 
44       * transaction rollback, we do not need to worry about tearing stuff down.
45       * @return boolean
46       */
47      protected void setup() {
48      }
49      
50      /**
51       * This method must be implemented to return true if a record 
52       * was properly inserted into the database.
53       * @return boolean
54       */
55      protected abstract boolean insert();
56  
57      /**
58       * This method must be implemented to return true if a record 
59       * was properly retreived from the database.
60       * @return boolean
61       */
62      protected abstract boolean retrieve();
63      
64      /**
65       * This method must be implemented to return true if a record 
66       * was properly updated in the database.
67       * @return boolean
68       */
69      protected abstract boolean update();
70      
71      /**
72       * This method should be implemented to retrieve the objects that were just updated, and validate 
73       * that their changes took effect.
74       * @return boolean
75       */
76      protected abstract boolean validateChanges();
77      
78      /**
79       * This method must be implemented to return true if a record 
80       * was properly delted from the database.
81       * @return boolean
82       */
83      protected abstract boolean delete();
84  }