1 package com.atlassian.sal.core.rdbms;
2
3 import org.junit.Before;
4 import org.junit.Rule;
5 import org.junit.Test;
6 import org.junit.rules.ExpectedException;
7 import org.junit.runner.RunWith;
8 import org.mockito.Mock;
9 import org.mockito.runners.MockitoJUnitRunner;
10
11 import java.sql.Connection;
12 import java.sql.SQLException;
13 import java.sql.Savepoint;
14 import java.util.concurrent.Executor;
15
16 import static org.mockito.Mockito.mock;
17 import static org.mockito.Mockito.verify;
18 import static org.mockito.Mockito.verifyZeroInteractions;
19
20 @RunWith (MockitoJUnitRunner.class)
21 public class TestWrappedConnection
22 {
23 @Mock
24 private Connection mockConnection;
25
26 private WrappedConnection wrappedConnection;
27
28 @Rule
29 public ExpectedException expectedException = ExpectedException.none();
30
31 @Before
32 public void before() throws Exception
33 {
34 wrappedConnection = new WrappedConnection(mockConnection);
35 }
36
37 @Test
38 public void expire() throws SQLException
39 {
40 expectedException.expect(IllegalStateException.class);
41
42 wrappedConnection.expire();
43
44 wrappedConnection.getMetaData();
45 }
46
47
48
49
50 @Test
51 public void setAutoCommit() throws SQLException
52 {
53 expectedException.expect(UnsupportedOperationException.class);
54 wrappedConnection.setAutoCommit(true);
55 verifyZeroInteractions(mockConnection);
56 }
57
58 @Test
59 public void commit() throws SQLException
60 {
61 expectedException.expect(UnsupportedOperationException.class);
62 wrappedConnection.commit();
63 verifyZeroInteractions(mockConnection);
64 }
65
66 @Test
67 public void close() throws SQLException
68 {
69 expectedException.expect(UnsupportedOperationException.class);
70 wrappedConnection.close();
71 verifyZeroInteractions(mockConnection);
72 }
73
74 @Test
75 public void rollback() throws SQLException
76 {
77 expectedException.expect(UnsupportedOperationException.class);
78 wrappedConnection.rollback();
79 verifyZeroInteractions(mockConnection);
80 }
81
82 @Test
83 public void setReadOnly() throws SQLException
84 {
85 expectedException.expect(UnsupportedOperationException.class);
86 wrappedConnection.setReadOnly(true);
87 verifyZeroInteractions(mockConnection);
88 }
89
90 @Test
91 public void abort() throws SQLException
92 {
93 expectedException.expect(UnsupportedOperationException.class);
94 wrappedConnection.abort(mock(Executor.class));
95 verifyZeroInteractions(mockConnection);
96 }
97
98 @Test
99 public void setCatalog() throws SQLException
100 {
101 expectedException.expect(UnsupportedOperationException.class);
102 wrappedConnection.setCatalog("bazza");
103 verifyZeroInteractions(mockConnection);
104 }
105
106 @Test
107 public void setSchema() throws SQLException
108 {
109 expectedException.expect(UnsupportedOperationException.class);
110 wrappedConnection.setSchema("mckenzie");
111 verifyZeroInteractions(mockConnection);
112 }
113
114 @Test
115 public void setTransactionIsolation() throws SQLException
116 {
117 expectedException.expect(UnsupportedOperationException.class);
118 wrappedConnection.setTransactionIsolation(Connection.TRANSACTION_NONE);
119 verifyZeroInteractions(mockConnection);
120 }
121
122 @Test
123 public void setNetworkTimeout() throws SQLException
124 {
125 expectedException.expect(UnsupportedOperationException.class);
126 wrappedConnection.setNetworkTimeout(mock(Executor.class), 11);
127 verifyZeroInteractions(mockConnection);
128 }
129
130 @Test
131 public void setSavepoint() throws SQLException
132 {
133 expectedException.expect(UnsupportedOperationException.class);
134 wrappedConnection.setSavepoint();
135 verifyZeroInteractions(mockConnection);
136 }
137
138 @Test
139 public void setSavepointAlt() throws SQLException
140 {
141 expectedException.expect(UnsupportedOperationException.class);
142 wrappedConnection.setSavepoint("bleh");
143 verifyZeroInteractions(mockConnection);
144 }
145
146 @Test
147 public void rollbackSavepoint() throws SQLException
148 {
149 expectedException.expect(UnsupportedOperationException.class);
150 wrappedConnection.rollback(mock(Savepoint.class));
151 verifyZeroInteractions(mockConnection);
152 }
153
154 @Test
155 public void releaseSavepoint() throws SQLException
156 {
157 expectedException.expect(UnsupportedOperationException.class);
158 wrappedConnection.releaseSavepoint(mock(Savepoint.class));
159 verifyZeroInteractions(mockConnection);
160 }
161
162
163
164
165 @Test
166 public void getMetaData() throws SQLException
167 {
168 wrappedConnection.getMetaData();
169 verify(mockConnection).getMetaData();
170 }
171 }