KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > core > dataobjects > jdbc > tests > JoinedObjectTest


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64
65 package com.jcorporate.expresso.core.dataobjects.jdbc.tests;
66
67 import com.jcorporate.expresso.core.dataobjects.DataException;
68 import com.jcorporate.expresso.core.dataobjects.Securable;
69 import com.jcorporate.expresso.core.dataobjects.jdbc.JoinedDataObject;
70 import com.jcorporate.expresso.core.db.DBException;
71 import com.jcorporate.expresso.core.misc.ConfigManager;
72 import com.jcorporate.expresso.core.misc.ConfigurationException;
73 import com.jcorporate.expresso.services.test.TestSystemInitializer;
74 import junit.framework.Test;
75 import junit.framework.TestCase;
76 import junit.framework.TestSuite;
77
78 import java.util.ArrayList JavaDoc;
79
80
81 /**
82  * <p/>
83  * DBObjectTest.java</p>
84  * <p>Copyright 1999, 2000, 2001 Jcorporate Ltd.</p>
85  * A test case to verify the functions of DBObject. You can also use this
86  * test as
87  */

88 public class JoinedObjectTest
89         extends TestCase {
90
91
92     /**
93      * Constructs a test case with the given name.
94      *
95      * @param name The name of the test case
96      */

97     public JoinedObjectTest(String JavaDoc name) {
98         super(name);
99     } /* DBObjectTest(String) */
100
101
102     public static void main(String JavaDoc[] args)
103             throws Exception JavaDoc {
104
105         //Set the system properties we need
106
junit.textui.TestRunner.run(suite());
107         ConfigManager.destroy();
108     }
109
110     /**
111      * Sets up the fixture, for example, open a network connection.
112      * This method is called before a test is executed.
113      */

114     public void setUp()
115             throws Exception JavaDoc {
116         TestSystemInitializer.setUp();
117
118         try {
119             ConfigManager.getContext(TestSystemInitializer.getTestContext());
120         } catch (ConfigurationException ce) {
121             fail(
122                     "Specified context to test:" + TestSystemInitializer.getTestContext() + " but couldn't find that context");
123         }
124
125     } /* setUp() */
126
127
128     /**
129      * Tears down the fixture, for example, close a network connection.
130      * This method is called after a test is executed.
131      */

132     public void tearDown()
133             throws Exception JavaDoc {
134
135     } /* tearDown() */
136
137
138     /**
139      * Define the suite of tests that verify each function of the cache
140      *
141      * @return an instantiated test suite
142      */

143     public static Test suite() {
144         TestSuite suite = new TestSuite(JoinedObjectTest.class);
145
146         return suite;
147     } /* suite() */
148
149     public void testCount() {
150         try {
151             JoinedDataObject testJoin = new JoinedDataObject();
152             testJoin.setRequestingUid(Securable.SYSTEM_ACCOUNT);
153             testJoin.setDefinitionName("/com/jcorporate/" +
154                     "expresso/core/dataobjects/jdbc/tests/DownloadMimeTypeJoin.xml");
155             testJoin.set("DownloadLog.LogEntry", "1");
156             int number = testJoin.count();
157             System.out.println("Received count result of : " + number);
158
159             JoinedDataObject emptyCount = new JoinedDataObject();
160             emptyCount.setRequestingUid(Securable.SYSTEM_ACCOUNT);
161             emptyCount.setDefinitionName("/com/jcorporate/" +
162                     "expresso/core/dataobjects/jdbc/tests/DownloadMimeTypeJoin.xml");
163             number = emptyCount.count();
164             System.out.println("Received count result of : " + number);
165
166
167         } catch (DataException ex) {
168             ex.printStackTrace();
169             fail("Error testing Joined DataObject");
170         } catch (DBException ex) {
171             ex.printStackTrace();
172             fail("Caught DBException testing Joined DataObject");
173         } catch (Exception JavaDoc ex) {
174             ex.printStackTrace();
175             fail("Caught Exception testing Joined DataObject");
176         }
177
178     }
179
180
181     /**
182      * Test to make sure that calling clear doesn't break anything.
183      */

184     public void testClear() {
185         try {
186             JoinedDataObject testJoin = new JoinedDataObject();
187             testJoin.setRequestingUid(Securable.SYSTEM_ACCOUNT);
188             testJoin.setDefinitionName("/com/jcorporate/" +
189                     "expresso/core/dataobjects/jdbc/tests/DownloadMimeTypeJoin.xml");
190             testJoin.set("DownloadLog.LogEntry", "1");
191             int number = testJoin.count();
192             System.out.println("Received count result of : " + number);
193
194             testJoin.clear();
195             testJoin.setRequestingUid(Securable.SYSTEM_ACCOUNT);
196             testJoin.setDefinitionName("/com/jcorporate/" +
197                     "expresso/core/dataobjects/jdbc/tests/DownloadMimeTypeJoin.xml");
198             number = testJoin.count();
199             System.out.println("Received count result of : " + number);
200
201
202         } catch (DataException ex) {
203             ex.printStackTrace();
204             fail("Error testing Joined DataObject");
205         } catch (DBException ex) {
206             ex.printStackTrace();
207             fail("Caught DBException testing Joined DataObject");
208         } catch (Exception JavaDoc ex) {
209             ex.printStackTrace();
210             fail("Caught Exception testing Joined DataObject");
211         }
212
213     }
214
215     /**
216      * Tries a database object join on search and retrieve.
217      */

218     public void testSearchAndRetrieveList() {
219         try {
220             JoinedDataObject testJoin = new JoinedDataObject();
221             testJoin.setRequestingUid(Securable.SYSTEM_ACCOUNT);
222             testJoin.setDefinitionName("/com/jcorporate/expresso/core/dataobjects/jdbc/tests/DownloadMimeTypeJoin.xml");
223             testJoin.set("DownloadLog.LogEntry", "1");
224             ArrayList JavaDoc al = testJoin.searchAndRetrieveList();
225             System.out.println("Received result of : " + al.size() + " records");
226         } catch (DataException ex) {
227             ex.printStackTrace();
228             fail("Error testing Joined DataObject");
229         } catch (DBException ex) {
230             ex.printStackTrace();
231             fail("Caught DBException testing Joined DataObject");
232         } catch (Exception JavaDoc ex) {
233             ex.printStackTrace();
234             fail("Caught Exception testing Joined DataObject");
235         }
236
237     }
238
239     public void testOrderBy() {
240         try {
241             JoinedDataObject testJoin = new JoinedDataObject();
242             testJoin.setRequestingUid(Securable.SYSTEM_ACCOUNT);
243             testJoin.setDefinitionName("/com/jcorporate/expresso/core/dataobjects/jdbc/tests/DownloadMimeTypeJoin.xml");
244             testJoin.set("DownloadLog.LogEntry", "1");
245             ArrayList JavaDoc al = testJoin.searchAndRetrieveList("MimeTypes.MimeNumber DESC");
246             System.out.println("Received result of : " + al.size() + " records");
247             al = testJoin.searchAndRetrieveList("MimeTypes.MimeNumber");
248             System.out.println("Received result of : " + al.size() + " records");
249             al = testJoin.searchAndRetrieveList("Users.ExpUid DESC|MimeTypes.MimeNumber ASC");
250             System.out.println("Received result of : " + al.size() + " records");
251         } catch (DataException ex) {
252             ex.printStackTrace();
253             fail("Error testing Joined DataObject");
254         } catch (DBException ex) {
255             ex.printStackTrace();
256             fail("Caught DBException testing Joined DataObject");
257         } catch (Exception JavaDoc ex) {
258             ex.printStackTrace();
259             fail("Caught Exception testing Joined DataObject");
260         }
261
262     }
263
264
265     /**
266      * Tests the setter and getter values of the dataobject.
267      */

268     public void testGetSet() {
269
270     }
271 }
272
273 /* DBObjectTest */
274
Popular Tags