forked from smokestack/smokestack.github.com
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextensionguidelines.html
325 lines (222 loc) · 9.95 KB
/
extensionguidelines.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Smokestack - </title>
<style type="text/css" media="all">
@import url("./css/maven-base.css");
@import url("./css/maven-theme.css");
@import url("./css/site.css");
</style>
<link rel="stylesheet" href="./css/print.css" type="text/css" media="print" />
</head>
<body class="composite">
<div id="banner">
<a href="" id="bannerLeft">
Smokestack
</a>
<div class="clear">
<hr/>
</div>
</div>
<div id="breadcrumbs">
<div class="xleft">
Last Published: 2010-02-13
</div>
<div class="xright"> <a href="http://smokestack.github.com/" class="externalLink">Home</a>
</div>
<div class="clear">
<hr/>
</div>
</div>
<div id="leftColumn">
<div id="navcolumn">
<h5>Documentation</h5>
<ul>
<li class="none">
<a href="index.html">Home</a>
</li>
<li class="none">
<a href="design.html">Design</a>
</li>
<li class="none">
<a href="usage.html">Usage</a>
</li>
<li class="none">
<a href="faq.html">FAQ</a>
</li>
<li class="none">
<strong>Extensions Guidelines</strong>
</li>
</ul>
<h5>Modules</h5>
<ul>
<li class="none">
<a href="smokestack-common/index.html">Smokestack Common</a>
</li>
<li class="none">
<a href="smokestack-jndi-1.2/index.html">Smokestack JNDI 1.2</a>
</li>
<li class="none">
<a href="smokestack-jpa-1.0/index.html">Smokestack JPA 1.0</a>
</li>
<li class="none">
<a href="smokestack-jms-1.1/index.html">Smokestack JMS 1.1</a>
</li>
<li class="none">
<a href="smokestack-jca-1.5/index.html">Smokestack JCA 1.5</a>
</li>
<li class="none">
<a href="smokestack-ejb-3.0/index.html">Smokestack EJB 3.0</a>
</li>
<li class="none">
<a href="smokestack-jdbc-3.0/index.html">Smokestack JDBC 3.0</a>
</li>
</ul>
<h5>Project Documentation</h5>
<ul>
<li class="collapsed">
<a href="project-info.html">Project Information</a>
</li>
<li class="collapsed">
<a href="project-reports.html">Project Reports</a>
</li>
</ul>
<a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
<img alt="Built by Maven" src="./images/logos/maven-feather.png"></img>
</a>
</div>
</div>
<div id="bodyColumn">
<div id="contentBox">
<div class="source"><pre>Extension Guidelines</pre>
</div>
<p>The design is based on the following classification of operations: * Methods that change the state of the container (e.g connection.commit()) * Methods that provide container specific components (e.g connection.createStatement()) * Methods that are simple getter/setter types (e.g connection.getHoldability(), connection.setHoldability()) * Methods that prepare the container/component for use (e.g connection.setSavePoint()) * Methods that the users directly interact with and expect certain output (e.g resultSet.getInt())</p>
<p>Based on the above classification we have followed the simple rules given below. These standardizes how the mock containers behave and if you are looking for creating extensions, you would follow the same classification.</p>
<table class="bodyTable"><tbody><tr class="a"><td align="left">Method types</td>
<td align="left">Examples</td>
<td align="left">Has Implementation</td>
<td align="left">Needs Mock Ixmplementation</td>
</tr>
<tr class="b"><td align="left">Container<br />
Specific</td>
<td align="left">connection.commit()<br />
connection.createStatement()</td>
<td align="left">Yes</td>
<td align="left">No</td>
</tr>
<tr class="a"><td align="left">Getter/<br />
Setters</td>
<td align="left">connection.getHoldability()<br />
connection.setHoldability()</td>
<td align="left">Yes</td>
<td align="left">No</td>
</tr>
<tr class="b"><td align="left">Prepare methods</td>
<td align="left">connection.setSavePoint()</td>
<td align="left">Yes</td>
<td align="left">No</td>
</tr>
<tr class="a"><td align="left">Integration</td>
<td align="left">resultSet.getInt()</td>
<td align="left">No</td>
<td align="left">Yes</td>
</tr>
</tbody>
</table>
<p>Some of the cases are explained in detail</p>
<ol type="1"><li>Simple getters that you do not do anything with...if you prefer to override, you still override the corresponding _method. <p><tt>public boolean getAutoCommit() throws SQLException { <br />
assertThat(mockConnectionState, IsNot.not(ConnectionState.CLOSE)); <br />
return _getAutoCommit(); <br />
} <br />
<br />
public boolean _getAutoCommit() { <br />
return autoCommitState \=\= AutoCommitState.ENABLED?true:false; <br />
}</tt> </p>
</li>
<li>Simple setters that you do not do anything with...if you prefer to override, you do the actual method override <p><tt>public void setAutoCommit(boolean autoCommit) throws SQLException { <br />
assertThat(mockConnectionState, IsNot.not(ConnectionState.CLOSE)); <br />
_setAutoCommit(autoCommit);   } <br />
<br />
public void _setAutoCommit(boolean autoCommit) { <br />
autoCommitState = autoCommit? AutoCommitState.ENABLED:AutoCommitState.DISABLED; <br />
} </tt> </p>
</li>
<li>Interactions methods - Because this is not a getter (as there is not direct setter for this one, if you are using this, you will have to override its corresponding _getWarnings() method and tell exactly what you want the framework to return to you. <tt>public SQLWarning getWarnings() throws SQLException { <br />
assertThat(mockConnectionState, IsNot.not(ConnectionState.CLOSE)); <br />
return _getWarnings(); <br />
} <br />
<br />
public SQLWarning _getWarnings() { <br />
throw new NeedsMockDefinitionException(); <br />
}</tt> <p>Another Example<br />
<tt> public boolean last() throws SQLException { <br />
assertThat(mockState, AnyOf.anyOf(IsNot.not(ResultSetState.CLOSE), IsNot.not(ResultSetState.AUTOCLOSE))); <br />
return _last(); <br />
} <br />
<br />
public boolean _last() { <br />
throw new NeedsMockDefinitionException(); \ }</tt> </p>
</li>
<li>Container Specific - The framework is directly responsible for giving you the statement and keep track of the same. If you want to overrride it, say to throw the SQLException, you override the _createStatement method. <p><tt> public Statement createStatement() throws SQLException { <br />
assertThat(mockConnectionState, IsNot.not(ConnectionState.CLOSE)); <br />
MockStatement st= _createStatement(); <br />
mockStatements.add(st); <br />
return st; <br />
} <br />
<br />
public MockStatement _createStatement() { <br />
return new MockStatement(this); <br />
} </tt> </p>
<p>Another example<br />
<tt> public void commit() throws SQLException { <br />
try{ <br />
assertThat(mockConnectionState, IsNot.not(ConnectionState.CLOSE)); <br />
assertThat(autoCommitState, Is.is(AutoCommitState.DISABLED)); <br />
mockTransactionState = TransactionState.COMMIT; <br />
_commit(); <br />
} catch (SQLException e){ <br />
mockTransactionState = TransactionState.AUTOROLLBACK; <br />
throw e; <br />
} <br />
} <br />
<br />
public void _commit() throws SQLException { <br />
} </tt> </p>
</li>
<li>Container Specific - Special case of the above, contains container state management stuff that you can still override without disrupting the framework <p><tt>public void rollback(Savepoint savepoint) throws SQLException { <br />
assertThat(mockConnectionState, IsNot.not(ConnectionState.CLOSE)); <br />
assertThat(autoCommitState, Is.is(AutoCommitState.DISABLED)); <br />
mockTransactionState = TransactionState.ROLLBACK; <br />
_rollback(savepoint); <br />
} <br />
<br />
public void _rollback(Savepoint savepoint) throws SQLException { <br />
}</tt> </p>
</li>
<li>Preparation Methods - Nothing special about these. Holds internal state.<p><tt> public void clearBatch() throws SQLException { <br />
assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE))); <br />
assertThat("Auto Commit State", parent.autoCommitState, Is.is(MockConnection.AutoCommitState.DISABLED)); <br />
_clearBatch(); <br />
} <br />
<br />
public void _clearBatch() { <br />
batchSQLs.clear(); <br />
} </tt> </p>
</li>
</ol>
</div>
</div>
<div class="clear">
<hr/>
</div>
<div id="footer">
<div class="xright">©
2009-2010
</div>
<div class="clear">
<hr/>
</div>
</div>
</body>
</html>