01: package com.mockrunner.test.connector;
02:
03: import javax.resource.ResourceException;
04: import javax.resource.cci.Connection;
05: import javax.resource.cci.ConnectionMetaData;
06: import javax.resource.cci.Interaction;
07: import javax.resource.cci.LocalTransaction;
08: import javax.resource.cci.RecordFactory;
09: import javax.resource.cci.ResultSetInfo;
10:
11: import com.mockrunner.mock.connector.cci.MockConnection;
12: import com.mockrunner.mock.connector.cci.MockConnectionFactory;
13: import com.mockrunner.mock.connector.cci.MockRecordFactory;
14: import com.mockrunner.mock.connector.cci.MockResourceAdapterMetaData;
15:
16: import junit.framework.TestCase;
17:
18: public class MockConnectionFactoryTest extends TestCase {
19: private MockConnectionFactory factory;
20:
21: protected void setUp() throws Exception {
22: factory = new MockConnectionFactory();
23: }
24:
25: protected void tearDown() throws Exception {
26: factory = null;
27: }
28:
29: public void testConnection() throws Exception {
30: MockConnection mockConnection = new MockConnection();
31: factory.setConnection(mockConnection);
32: assertSame(mockConnection, factory.getConnection());
33: assertSame(mockConnection, factory.getConnection(null));
34: assertSame(mockConnection, factory.getMockConnection());
35: TestConnection testConnection = new TestConnection();
36: factory.setConnection(testConnection);
37: assertSame(testConnection, factory.getConnection());
38: assertSame(testConnection, factory.getConnection(null));
39: assertNull(factory.getMockConnection());
40: }
41:
42: public void testGetMetaData() throws Exception {
43: assertTrue(factory.getMetaData() instanceof MockResourceAdapterMetaData);
44: MockResourceAdapterMetaData metaData = new MockResourceAdapterMetaData() {
45: };
46: factory.setMetaData(metaData);
47: assertSame(metaData, factory.getMetaData());
48: }
49:
50: public void testRecordFactory() throws Exception {
51: assertTrue(factory.getRecordFactory() instanceof MockRecordFactory);
52: RecordFactory recordFactory = new MockRecordFactory() {
53: };
54: factory.setRecordFactory(recordFactory);
55: assertSame(recordFactory, factory.getRecordFactory());
56: }
57:
58: private class TestConnection implements Connection {
59: public void close() throws ResourceException {
60:
61: }
62:
63: public Interaction createInteraction() throws ResourceException {
64: return null;
65: }
66:
67: public LocalTransaction getLocalTransaction()
68: throws ResourceException {
69: return null;
70: }
71:
72: public ConnectionMetaData getMetaData()
73: throws ResourceException {
74: return null;
75: }
76:
77: public ResultSetInfo getResultSetInfo()
78: throws ResourceException {
79: return null;
80: }
81: }
82: }
|