KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > plankton > data > PDataTestCases


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: PDataTestCases.java,v 1.3 2004/02/01 05:16:33 christianc Exp $
19  */

20 package org.enhydra.barracuda.plankton.data;
21
22 import java.io.*;
23 import java.util.*;
24
25 import junit.framework.*;
26
27 import org.apache.log4j.*;
28 import org.enhydra.barracuda.testbed.*;
29
30
31 /**
32  * Test case for any PData. The idea is that you can test any
33  * PData object by extending this test case and adding tests
34  * for the specific implementation details. All you really have
35  * to do is override teh factory PData methods.
36  */

37 public abstract class PDataTestCases extends StateMapTestCases {
38     //common vars (customize for every test class)
39
// protected static String testClass = PDataTestCases.class.getName();
40
// protected static final Logger logger = Logger.getLogger("test."+testClass);
41

42     //variables
43

44     //-------------------- Basics --------------------------------
45
/**
46      * Public Constructor
47      */

48     public PDataTestCases(String JavaDoc name) {
49         super(name);
50     }
51     
52     //-------------------- Actual Tests --------------------------
53
//Note: all the methods herein should follow the testXXXX naming convention
54
//Also keep in mind that local vars set in one test method are NOT retained
55
//when the next method is invoked because JUnit makes a separate instance of
56
//the test class for each testXXXX method!!!
57

58     /**
59      * Verify the parental aspects
60      */

61     public void testParental() {
62         if (logger.isInfoEnabled()) logger.info("testing parental methods");
63         PData proot = null;
64         PData pchild1 = null;
65         PData pchild2 = null;
66         PData pchild3 = null;
67
68         //test simple set/get
69
proot = getPDataInstance();
70         pchild1 = getPDataInstance();
71         pchild1.setParent(proot);
72         assertTrue("Parental check 1 failed...basic set/get failure", pchild1.getParent()==proot);
73         pchild1.setParent(null);
74         assertTrue("Parental check 1a failed...set to null failure", pchild1.getParent()==null);
75         pchild1.setParent(pchild1);
76         assertTrue("Parental check 1b failed...allowed parent to be set to self", pchild1.getParent()!=pchild1);
77
78         //test the inheritParents attribute set/get
79
proot = getPDataInstance();
80         assertTrue("Parental check 2 failed...invalid default inheritParents value", proot.isInheritParents()==true);
81         proot.setInheritParents(false);
82         assertTrue("Parental check 2a failed...basic set/get failure", proot.isInheritParents()==false);
83         proot.setInheritParents(true);
84         assertTrue("Parental check 2b failed...basic set/get failure", proot.isInheritParents()==true);
85         
86         //test the getRootParent
87
proot = getPDataInstance();
88         pchild1 = getPDataInstance();
89         pchild1.setParent(proot);
90         pchild2 = getPDataInstance();
91         pchild2.setParent(pchild1);
92         assertTrue("Parental check 3 failed...root parent not correctly located", pchild2.getRootParent()==proot);
93     }
94     
95     /**
96      * Verify the PData is serializable
97      */

98     public void testSerializable() {
99         if (logger.isInfoEnabled()) logger.info("testing for Serializable");
100         PData pdata = this.getPDataInstance();
101         assertTrue("PData instance does not implement Serializable!", pdata instanceof Serializable);
102     }
103     
104
105     //-------------------- Abstract methods ----------------------
106
public abstract PData getPDataInstance();
107     public abstract PList getPListInstance();
108     public abstract PMap getPMapInstance();
109
110 }
111
Popular Tags