001: /* ====================================================================
002: * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
003: *
004: * Copyright (c) 1995-2003 Jcorporate Ltd. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by Jcorporate Ltd.
021: * (http://www.jcorporate.com/)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. "Jcorporate" and product names such as "Expresso" must
026: * not be used to endorse or promote products derived from this
027: * software without prior written permission. For written permission,
028: * please contact info@jcorporate.com.
029: *
030: * 5. Products derived from this software may not be called "Expresso",
031: * or other Jcorporate product names; nor may "Expresso" or other
032: * Jcorporate product names appear in their name, without prior
033: * written permission of Jcorporate Ltd.
034: *
035: * 6. No product derived from this software may compete in the same
036: * market space, i.e. framework, without prior written permission
037: * of Jcorporate Ltd. For written permission, please contact
038: * partners@jcorporate.com.
039: *
040: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
041: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
042: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
043: * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
044: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
045: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
046: * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
047: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
048: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
049: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
050: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
051: * SUCH DAMAGE.
052: * ====================================================================
053: *
054: * This software consists of voluntary contributions made by many
055: * individuals on behalf of the Jcorporate Ltd. Contributions back
056: * to the project(s) are encouraged when you make modifications.
057: * Please send them to support@jcorporate.com. For more information
058: * on Jcorporate Ltd. and its products, please see
059: * <http://www.jcorporate.com/>.
060: *
061: * Portions of this software are based upon other open source
062: * products and are subject to their respective licenses.
063: */
064: package com.jcorporate.expresso.core.dataobjects.test;
065:
066: import com.jcorporate.expresso.core.dataobjects.PersistenceManager;
067: import com.jcorporate.expresso.core.db.DBConfig;
068: import com.jcorporate.expresso.core.db.TypeMapper;
069: import com.jcorporate.expresso.core.misc.SystemMacros;
070: import com.jcorporate.expresso.kernel.DataContext;
071: import com.jcorporate.expresso.kernel.RootContainerInterface;
072: import com.jcorporate.expresso.kernel.SystemFactory;
073: import com.jcorporate.expresso.kernel.util.LocatorUtils;
074: import junit.framework.TestCase;
075:
076: /**
077: * JUnitTest case for class: com.jcorporate.expresso.core.dataobjects.PersistenceManager
078: */
079: public class TestPersistenceManager extends TestCase {
080:
081: public TestPersistenceManager(String _name) {
082: super (_name);
083: }
084:
085: RootContainerInterface globalContainer = null;
086:
087: /**
088: * setUp method for test case
089: */
090: protected void setUp() {
091: SystemMacros.getInstance().setWebAppDir(
092: System.getProperty("junit.argv.webAppDir", ""));
093:
094: try {
095: globalContainer = SystemFactory
096: .buildExpressoComponentSystem(this .getClass()
097: .getResource("Test1ExpressoServices.xml"),
098: this .getClass().getResource(
099: "TestLog4jConfig.xml"), System
100: .getProperty("junit.argv.logDir",
101: "/d:/expresso/log"));
102: } catch (Exception e) {
103: e.printStackTrace();
104: fail("Caught Exception setting up test case");
105: }
106: }
107:
108: /**
109: * tearDown method for test case
110: */
111: protected void tearDown() {
112: globalContainer.destroy();
113: }
114:
115: /**
116: * test for method initialize(..)
117: */
118: public void testInitialize() {
119: try {
120: DataContext dc = (DataContext) globalContainer
121: .locateComponent("default");
122: assertTrue("DataContext should be non-null", dc != null);
123: assertTrue("DataContext should have setup tables", dc
124: .getHasSetupTables().booleanValue() == true);
125:
126: LocatorUtils lc = new LocatorUtils(globalContainer);
127: PersistenceManager manager = (PersistenceManager) lc
128: .locateComponent("default.PersistenceManager");
129: assertTrue("PersistenceManager should exist",
130: manager != null);
131:
132: DBConfig config = (DBConfig) lc
133: .locateComponent("default.PersistenceManager.DBConfig");
134: assertTrue("DBConfig should exist", config != null);
135:
136: TypeMapper mapper = (TypeMapper) lc
137: .locateComponent("default.PersistenceManager.TypeMapper");
138: assertTrue("TypeMapper should exist", mapper != null);
139: } catch (Exception ex) {
140: ex.printStackTrace();
141: fail("Caught Exception constructing Global Container");
142: }
143:
144: }
145:
146: /**
147: * test for method getTypeMapper(..)
148: */
149: public void testGetTypeMapper() {
150: try {
151: LocatorUtils lc = new LocatorUtils(globalContainer);
152: PersistenceManager manager = (PersistenceManager) lc
153: .locateComponent("default.PersistenceManager");
154: assertTrue("PersistenceManager should exist",
155: manager != null);
156: assertTrue("TypeMapper must not be null", manager
157: .getTypeMapper() != null);
158: } catch (Exception ex) {
159: ex.printStackTrace();
160: fail("Caught Exception constructing Global Container");
161: }
162:
163: }
164:
165: /**
166: * test for method getDataContext(..)
167: */
168: public void testGetDataContext() {
169: try {
170: LocatorUtils lc = new LocatorUtils(globalContainer);
171: PersistenceManager manager = (PersistenceManager) lc
172: .locateComponent("default.PersistenceManager");
173: assertTrue("PersistenceManager should exist",
174: manager != null);
175: assertTrue("default".equals(manager.getDataContext()));
176: } catch (Exception ex) {
177: ex.printStackTrace();
178: fail("Caught Exception constructing Global Container");
179: }
180: }
181:
182: /**
183: * test for method getConfigName(..)
184: */
185: public void testGetConfigName() {
186: try {
187: LocatorUtils lc = new LocatorUtils(globalContainer);
188: PersistenceManager manager = (PersistenceManager) lc
189: .locateComponent("default.PersistenceManager");
190: assertTrue("PersistenceManager should exist",
191: manager != null);
192: assertTrue("hypersonic.xml".equals(manager.getConfigName()));
193: } catch (Exception ex) {
194: ex.printStackTrace();
195: fail("Caught Exception constructing Global Container");
196: }
197: }
198:
199: /**
200: * test for method getDataURL(..)
201: */
202: public void testGetDataURL() {
203: try {
204: LocatorUtils lc = new LocatorUtils(globalContainer);
205: PersistenceManager manager = (PersistenceManager) lc
206: .locateComponent("default.PersistenceManager");
207: assertTrue("PersistenceManager should exist",
208: manager != null);
209: assertTrue("jdbc:hsqldb:%web-app%WEB-INF/db/default/default"
210: .equals(manager.getDataURL()));
211:
212: assertTrue(manager.getDBConfig().getCurrentConfig()
213: .getUrl() != null);
214: } catch (Exception ex) {
215: ex.printStackTrace();
216: fail("Caught Exception constructing Global Container");
217: }
218:
219: }
220:
221: /**
222: * test for method getUserName(..)
223: */
224: public void testGetUserName() {
225: try {
226: LocatorUtils lc = new LocatorUtils(globalContainer);
227: PersistenceManager manager = (PersistenceManager) lc
228: .locateComponent("default.PersistenceManager");
229: assertTrue("PersistenceManager should exist",
230: manager != null);
231: assertTrue("sa".equals(manager.getUserName()));
232: assertTrue("sa".equals(manager.getDBConfig()
233: .getCurrentConfig().getLogin()));
234: } catch (Exception ex) {
235: ex.printStackTrace();
236: fail("Caught Exception constructing Global Container");
237: }
238: }
239:
240: /**
241: * test for method getPassword(..)
242: */
243: public void testGetPassword() {
244: try {
245: LocatorUtils lc = new LocatorUtils(globalContainer);
246: PersistenceManager manager = (PersistenceManager) lc
247: .locateComponent("default.PersistenceManager");
248: assertTrue("PersistenceManager should exist",
249: manager != null);
250: assertTrue("".equals(manager.getPassword()));
251: assertTrue("".equals(manager.getDBConfig()
252: .getCurrentConfig().getPassword()));
253: } catch (Exception ex) {
254: ex.printStackTrace();
255: fail("Caught Exception constructing Global Container");
256: }
257: }
258:
259: /**
260: * Executes the test case
261: */
262: public static void main(String[] argv) {
263: String[] testCaseList = { TestPersistenceManager.class
264: .getName() };
265: junit.textui.TestRunner.main(testCaseList);
266: }
267: }
|