forked from smokestack/smokestack.github.com
-
Notifications
You must be signed in to change notification settings - Fork 1
/
usage.html
240 lines (137 loc) · 7.96 KB
/
usage.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
<!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">
<strong>Usage</strong>
</li>
<li class="none">
<a href="faq.html">FAQ</a>
</li>
<li class="none">
<a href="extensionguidelines.html">Extensions Guidelines</a>
</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>Usage</pre>
</div>
<p>The various JEE technologies are packaged as separate modules. These modules can be used independently or can be combined within a single test case. </p>
<p>We do not make any assumption on the type of tests that you need to create and as such, there will be lot of methods that might need to be overridden. All of these methods would throw NeedsMockDefinitionException. Convenience methods are provided allowing to verify the integrity of the tests. For example, JDBC module comes with connection.assertClosed() method that will ensure that all the connections, statements and result sets are closed.</p>
<p>Many of the modules are work-in-progress, and so testcases and patches are welcome. All the methods that are not yet implemented and do not partake in the life-cycle would throw NotYetImplementedException exception.</p>
<p>There are generally two types of actions that we track. One is a set of operations that is explicitly invoked on the components and other is a set of operations that are implicitly invoked as part of the specifications. For example, a close() on connection will issue an implicit closure on all the associated statements and result sets or you can explicitly call close on each of these components. In parallel, we have provided assertions that test the the above two scenarios. For example, if you want to ensure that all the components were explicitly closed in the unit under testing, you can invoke assertExplicitClose() on the components. However if you don't really care for explicit closure, but just want to ensure that there is no components are in open state, you can invoke assertClosed(). For JDBC, there is a similar implementation for rollback and commit states.</p>
<p>The one reason we had to do this was that there are certain drivers implementing the specifications in a limited fashion, so when we close connection, it doesn't close the associated statements and resultsets. We give full flexibility to the user to decide what type of assertions they want to do for their particular environment.</p>
<p>The other design decision that we have taken to ensure that the state of the mock component is maintained in case of known exceptions as indicated in the method signature. For example, You have void commit throws SQLException(). If you use JMockit Expectations to throw a SQLException on commit(), then we ensure that the transaction state of that connection is reverted to rollback state. However if you decide to throw NullPointerException, we provide no guarantee on the state of the component from that point onwards and the validity of the corresponding assertions.</p>
<p><tt> @Test <br />
public void testMainThrowOnCommit() throws SQLException, ClassNotFoundException { <br />
new Expectations(){ <br />
@Mocked( methods= {"_commit"}) <br />
MockConnection c; <br />
@Mocked( methods= {"_execute"}) <br />
MockStatement st; <br />
{ <br />
st._execute((String)any); <br />
c._commit(); throwsException(new SQLException("something bad happened")); <br />
} <br />
}; <br />
Class.forName("com.github.smokestack.jdbc.MockDriver"); <br />
try { <br />
PSBatch.main(new String[]{}); <br />
fail("expected Exception"); <br />
} catch (Exception e){ <br />
MockConnection c=MockDriver.instance.getMockConnections().get(0); <br />
c.assertAutoRollback(); <br />
c.assertClosed(); <br />
} <br />
} </tt> </p>
<p>Depending on which of the modules you need to do your testing, you can download each required modules or download the entire smokestack framework. Put the required Jar files in your development environment and you are set to go. </p>
</div>
</div>
<div class="clear">
<hr/>
</div>
<div id="footer">
<div class="xright">©
2009-2010
</div>
<div class="clear">
<hr/>
</div>
</div>
</body>
</html>