001: package com.mockrunner.test;
002:
003: import java.sql.Connection;
004: import java.sql.Driver;
005: import java.sql.DriverManager;
006: import java.sql.DriverPropertyInfo;
007: import java.sql.SQLException;
008: import java.util.Enumeration;
009: import java.util.Properties;
010:
011: import javax.naming.Context;
012:
013: import org.mockejb.jndi.MockContextFactory;
014:
015: import com.mockrunner.base.BaseTestCase;
016: import com.mockrunner.mock.connector.cci.ConnectorMockObjectFactory;
017: import com.mockrunner.mock.ejb.EJBMockObjectFactory;
018: import com.mockrunner.mock.jdbc.JDBCMockObjectFactory;
019: import com.mockrunner.mock.jdbc.MockDriver;
020: import com.mockrunner.mock.jms.JMSMockObjectFactory;
021: import com.mockrunner.mock.web.ActionMockObjectFactory;
022: import com.mockrunner.mock.web.WebMockObjectFactory;
023:
024: public class BaseTestCaseTest extends BaseTestCase {
025: public void testOneDriver() throws Exception {
026: DriverManager.registerDriver(new TestDriver());
027: DriverManager.registerDriver(new TestDriver());
028: getJDBCMockObjectFactory();
029: Enumeration drivers = DriverManager.getDrivers();
030: assertTrue(drivers.nextElement() instanceof MockDriver);
031: assertFalse(drivers.hasMoreElements());
032: super .tearDown();
033: drivers = DriverManager.getDrivers();
034: assertTrue(drivers.hasMoreElements());
035: drivers.nextElement();
036: assertTrue(drivers.hasMoreElements());
037: }
038:
039: public void testTearDownRevertSetAsInitialCalled() throws Exception {
040: getEJBMockObjectFactory();
041: assertEquals(MockContextFactory.class.getName(), System
042: .getProperty(Context.INITIAL_CONTEXT_FACTORY));
043: super .tearDown();
044: assertNull(System.getProperty(Context.INITIAL_CONTEXT_FACTORY));
045: }
046:
047: public void testLazyFactoriesInstance() {
048: assertSame(getJDBCMockObjectFactory(),
049: getJDBCMockObjectFactory());
050: assertSame(getJMSMockObjectFactory(), getJMSMockObjectFactory());
051: assertSame(getEJBMockObjectFactory(), getEJBMockObjectFactory());
052: assertSame(getWebMockObjectFactory(), getWebMockObjectFactory());
053: assertSame(getActionMockObjectFactory(),
054: getActionMockObjectFactory());
055: assertSame(getActionMockObjectFactory(),
056: getWebMockObjectFactory());
057: }
058:
059: public void testSetActionAndWebFactories() {
060: WebMockObjectFactory webFactory = new WebMockObjectFactory();
061: setWebMockObjectFactory(webFactory);
062: assertSame(webFactory, getWebMockObjectFactory());
063: assertNotSame(webFactory, getActionMockObjectFactory());
064: ActionMockObjectFactory actionFactory = new ActionMockObjectFactory();
065: setActionMockObjectFactory(actionFactory);
066: assertSame(actionFactory, getActionMockObjectFactory());
067: setWebMockObjectFactory(null);
068: assertSame(actionFactory, getWebMockObjectFactory());
069: }
070:
071: public void testSetJMSFactory() {
072: JMSMockObjectFactory jmsFactory = new JMSMockObjectFactory();
073: setJMSMockObjectFactory(jmsFactory);
074: assertSame(jmsFactory, getJMSMockObjectFactory());
075: setJMSMockObjectFactory(null);
076: assertNotNull(getJMSMockObjectFactory());
077: assertNotSame(jmsFactory, getJMSMockObjectFactory());
078: }
079:
080: public void testSetJDBCFactory() {
081: JDBCMockObjectFactory jdbcFactory = new JDBCMockObjectFactory();
082: setJDBCMockObjectFactory(jdbcFactory);
083: assertSame(jdbcFactory, getJDBCMockObjectFactory());
084: setJDBCMockObjectFactory(null);
085: assertNotNull(getJDBCMockObjectFactory());
086: assertNotSame(jdbcFactory, getJDBCMockObjectFactory());
087: }
088:
089: public void testSetEJBFactory() {
090: EJBMockObjectFactory ejbFactory = new EJBMockObjectFactory();
091: setEJBMockObjectFactory(ejbFactory);
092: assertSame(ejbFactory, getEJBMockObjectFactory());
093: setEJBMockObjectFactory(null);
094: assertNotNull(getEJBMockObjectFactory());
095: assertNotSame(ejbFactory, getEJBMockObjectFactory());
096: }
097:
098: public void testSetConnectorFactory() {
099: ConnectorMockObjectFactory connectorFactory = new ConnectorMockObjectFactory();
100: setConnectorMockObjectFactory(connectorFactory);
101: assertSame(connectorFactory, getConnectorMockObjectFactory());
102: setConnectorMockObjectFactory(null);
103: assertNotNull(getConnectorMockObjectFactory());
104: assertNotSame(connectorFactory, getConnectorMockObjectFactory());
105: }
106:
107: public static class TestDriver implements Driver {
108: public boolean acceptsURL(String url) throws SQLException {
109: return false;
110: }
111:
112: public Connection connect(String url, Properties info)
113: throws SQLException {
114: return null;
115: }
116:
117: public int getMajorVersion() {
118: return 0;
119: }
120:
121: public int getMinorVersion() {
122: return 0;
123: }
124:
125: public DriverPropertyInfo[] getPropertyInfo(String url,
126: Properties info) throws SQLException {
127: return null;
128: }
129:
130: public boolean jdbcCompliant() {
131: return false;
132: }
133: }
134: }
|