001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: TestDbQueryManagerFactory.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.database;
009:
010: import com.uwyn.rife.database.exceptions.DatabaseException;
011: import com.uwyn.rife.tools.ExceptionUtils;
012: import junit.framework.TestCase;
013:
014: public class TestDbQueryManagerFactory extends TestCase {
015: private Datasource mDatasource = null;
016:
017: public TestDbQueryManagerFactory(Datasource datasource,
018: String datasourceName, String name) {
019: super (name);
020: mDatasource = datasource;
021: }
022:
023: public void testGetDefault() {
024: TestDbQueryManagerImpl dbquerymanager1 = TestDbQueryManagerFactoryImpl
025: .getInstance(mDatasource);
026: TestDbQueryManagerImpl dbquerymanager2 = TestDbQueryManagerFactoryImpl
027: .getInstance(mDatasource);
028:
029: assertSame(dbquerymanager1.getDatasource(), mDatasource);
030: assertSame(dbquerymanager2.getDatasource(), mDatasource);
031:
032: assertTrue(dbquerymanager1 == dbquerymanager2);
033: }
034:
035: public void testGetIdentifier() {
036: TestDbQueryManagerImpl dbquerymanager1 = TestDbQueryManagerFactoryImpl
037: .getInstance(mDatasource, "id1");
038: TestDbQueryManagerImpl dbquerymanager2 = TestDbQueryManagerFactoryImpl
039: .getInstance(mDatasource, "id1");
040: TestDbQueryManagerImpl dbquerymanager3 = TestDbQueryManagerFactoryImpl
041: .getInstance(mDatasource, "id2");
042: TestDbQueryManagerImpl dbquerymanager4 = TestDbQueryManagerFactoryImpl
043: .getInstance(mDatasource, "id3");
044:
045: assertSame(dbquerymanager1.getDatasource(), mDatasource);
046: assertSame(dbquerymanager2.getDatasource(), mDatasource);
047: assertSame(dbquerymanager3.getDatasource(), mDatasource);
048: assertSame(dbquerymanager4.getDatasource(), mDatasource);
049:
050: assertTrue(dbquerymanager1 == dbquerymanager2);
051: assertTrue(dbquerymanager1 != dbquerymanager3);
052: assertTrue(dbquerymanager1 != dbquerymanager4);
053: assertTrue(dbquerymanager2 != dbquerymanager3);
054: assertTrue(dbquerymanager2 != dbquerymanager4);
055: assertTrue(dbquerymanager3 != dbquerymanager4);
056:
057: dbquerymanager1.setSetting("setting1");
058: dbquerymanager3.setSetting("setting2");
059: dbquerymanager4.setSetting("setting3");
060:
061: assertTrue(dbquerymanager1.getSetting().equals(
062: dbquerymanager2.getSetting()));
063: assertTrue(!dbquerymanager1.getSetting().equals(
064: dbquerymanager3.getSetting()));
065: assertTrue(!dbquerymanager1.getSetting().equals(
066: dbquerymanager4.getSetting()));
067: assertTrue(!dbquerymanager2.getSetting().equals(
068: dbquerymanager3.getSetting()));
069: assertTrue(!dbquerymanager2.getSetting().equals(
070: dbquerymanager4.getSetting()));
071: assertTrue(!dbquerymanager3.getSetting().equals(
072: dbquerymanager4.getSetting()));
073: }
074:
075: public void testQuery() {
076: TestDbQueryManagerImpl dbquerymanager = TestDbQueryManagerFactoryImpl
077: .getInstance(mDatasource);
078: try {
079: dbquerymanager.install();
080: assertEquals(0, dbquerymanager.count());
081: dbquerymanager.store(1, "one");
082: assertEquals(1, dbquerymanager.count());
083: dbquerymanager.store(2, "two");
084: assertEquals(2, dbquerymanager.count());
085: dbquerymanager.store(3, "three");
086: assertEquals(3, dbquerymanager.count());
087: dbquerymanager.store(4, "four");
088: assertEquals(4, dbquerymanager.count());
089: try {
090: dbquerymanager.store(4, "fourb");
091: fail();
092: } catch (DatabaseException e) {
093: assertTrue(true);
094: }
095: assertEquals(4, dbquerymanager.count());
096: dbquerymanager.remove();
097: } catch (DatabaseException e) {
098: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
099: }
100: }
101: }
|