001: package com.mockrunner.test.connector;
002:
003: import java.util.List;
004:
005: import javax.resource.ResourceException;
006: import javax.resource.cci.Interaction;
007: import javax.resource.cci.LocalTransaction;
008:
009: import junit.framework.TestCase;
010:
011: import com.mockrunner.mock.connector.cci.MockConnection;
012: import com.mockrunner.mock.connector.cci.MockConnectionMetaData;
013: import com.mockrunner.mock.connector.cci.MockInteraction;
014: import com.mockrunner.mock.connector.cci.MockLocalTransaction;
015: import com.mockrunner.mock.connector.cci.MockResultSetInfo;
016:
017: public class MockConnectionTest extends TestCase {
018: private MockConnection connection;
019:
020: protected void setUp() throws Exception {
021: connection = new MockConnection();
022: }
023:
024: protected void tearDown() throws Exception {
025: connection = null;
026: }
027:
028: public void testGetInteractionList() throws Exception {
029: Interaction interaction1 = connection.createInteraction();
030: Interaction interaction2 = connection.createInteraction();
031: Interaction interaction3 = connection.createInteraction();
032: List interactionList = connection.getInteractionList();
033: assertEquals(3, interactionList.size());
034: assertEquals(interaction1, interactionList.get(0));
035: assertEquals(interaction2, interactionList.get(1));
036: assertEquals(interaction3, interactionList.get(2));
037: try {
038: interactionList.add(new MockInteraction(connection));
039: fail();
040: } catch (RuntimeException exc) {
041: //expected exception
042: }
043: }
044:
045: public void testClose() throws Exception {
046: MockInteraction interaction1 = (MockInteraction) connection
047: .createInteraction();
048: MockInteraction interaction2 = (MockInteraction) connection
049: .createInteraction();
050: MockInteraction interaction3 = (MockInteraction) connection
051: .createInteraction();
052: connection.close();
053: assertTrue(connection.isClosed());
054: assertTrue(interaction1.isClosed());
055: assertTrue(interaction2.isClosed());
056: assertTrue(interaction3.isClosed());
057: }
058:
059: public void testGetMetaData() throws Exception {
060: assertTrue(connection.getMetaData() instanceof MockConnectionMetaData);
061: MockConnectionMetaData metaData = new MockConnectionMetaData() {
062: };
063: connection.setMetaData(metaData);
064: assertSame(metaData, connection.getMetaData());
065: }
066:
067: public void testGetResultSetInfo() throws Exception {
068: assertTrue(connection.getResultSetInfo() instanceof MockResultSetInfo);
069: MockResultSetInfo resultSetInfo = new MockResultSetInfo() {
070: };
071: connection.setResultSetInfo(resultSetInfo);
072: assertSame(resultSetInfo, connection.getResultSetInfo());
073: }
074:
075: public void testGetLocalTransaction() throws Exception {
076: assertTrue(connection.getLocalTransaction() instanceof MockLocalTransaction);
077: MockLocalTransaction localTransaction = new MockLocalTransaction() {
078: };
079: connection.setLocalTransaction(localTransaction);
080: assertSame(localTransaction, connection.getLocalTransaction());
081: assertSame(localTransaction, connection
082: .getMockLocalTransaction());
083: LocalTransaction otherLocalTransaction = new TestLocalTransaction() {
084: };
085: connection.setLocalTransaction(otherLocalTransaction);
086: assertSame(otherLocalTransaction, connection
087: .getLocalTransaction());
088: assertNull(connection.getMockLocalTransaction());
089: }
090:
091: private class TestLocalTransaction implements LocalTransaction {
092: public void begin() throws ResourceException {
093:
094: }
095:
096: public void commit() throws ResourceException {
097:
098: }
099:
100: public void rollback() throws ResourceException {
101:
102: }
103: }
104: }
|