View Javadoc

1   /**
2    * Copyright 2005-2011 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  import static org.junit.Assert.assertTrue;
21  
22  /**
23   * This abstract class puts forward a simple framework for testing the basic 
24   * persistence of business objects in the system.
25   * 
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public abstract class BusinessObjectPersistenceTestCaseBase extends BusinessObjectDaoTestCaseBase {
29  
30      /**
31       * This method is responsible for testing the basic persistence of a business object.
32       */
33      @Test
34      public void testBasicPersistence() {
35          setup();
36          assertTrue(insert());
37          assertTrue(retrieve());
38          assertTrue(update());
39          assertTrue(validateChanges());
40          assertTrue(delete());
41      }
42      
43      /**
44       * This method should be overridden and implemented to perform a setup of any dependent objects that 
45       * business object may need to reference.  Since we are using Spring's automated 
46       * transaction rollback, we do not need to worry about tearing stuff down.
47       * @return boolean
48       */
49      protected void setup() {
50      }
51      
52      /**
53       * This method must be implemented to return true if a record 
54       * was properly inserted into the database.
55       * @return boolean
56       */
57      protected abstract boolean insert();
58  
59      /**
60       * This method must be implemented to return true if a record 
61       * was properly retreived from the database.
62       * @return boolean
63       */
64      protected abstract boolean retrieve();
65      
66      /**
67       * This method must be implemented to return true if a record 
68       * was properly updated in the database.
69       * @return boolean
70       */
71      protected abstract boolean update();
72      
73      /**
74       * This method should be implemented to retrieve the objects that were just updated, and validate 
75       * that their changes took effect.
76       * @return boolean
77       */
78      protected abstract boolean validateChanges();
79      
80      /**
81       * This method must be implemented to return true if a record 
82       * was properly delted from the database.
83       * @return boolean
84       */
85      protected abstract boolean delete();
86  }