KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jca > cci > CciTemplateTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.jca.cci;
18
19 import java.sql.SQLException JavaDoc;
20
21 import javax.resource.ResourceException JavaDoc;
22 import javax.resource.cci.Connection JavaDoc;
23 import javax.resource.cci.ConnectionFactory JavaDoc;
24 import javax.resource.cci.ConnectionSpec JavaDoc;
25 import javax.resource.cci.IndexedRecord JavaDoc;
26 import javax.resource.cci.Interaction JavaDoc;
27 import javax.resource.cci.InteractionSpec JavaDoc;
28 import javax.resource.cci.MappedRecord JavaDoc;
29 import javax.resource.cci.Record JavaDoc;
30 import javax.resource.cci.RecordFactory JavaDoc;
31 import javax.resource.cci.ResultSet JavaDoc;
32
33 import junit.framework.TestCase;
34 import org.easymock.MockControl;
35
36 import org.springframework.jca.cci.connection.ConnectionSpecConnectionFactoryAdapter;
37 import org.springframework.jca.cci.core.CciTemplate;
38 import org.springframework.jca.cci.core.ConnectionCallback;
39 import org.springframework.jca.cci.core.InteractionCallback;
40 import org.springframework.jca.cci.core.RecordCreator;
41 import org.springframework.jca.cci.core.RecordExtractor;
42
43 /**
44  * @author Thierry Templier
45  * @author Juergen Hoeller
46  */

47 public class CciTemplateTests extends TestCase {
48
49     public void testCreateIndexedRecord() throws ResourceException JavaDoc {
50         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
51         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
52         MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory JavaDoc.class);
53         RecordFactory JavaDoc recordFactory = (RecordFactory JavaDoc) recordFactoryControl.getMock();
54         MockControl indexedRecordControl = MockControl.createStrictControl(IndexedRecord JavaDoc.class);
55         IndexedRecord JavaDoc indexedRecord = (IndexedRecord JavaDoc) indexedRecordControl.getMock();
56
57         connectionFactory.getRecordFactory();
58         connectionFactoryControl.setReturnValue(recordFactory, 1);
59
60         recordFactory.createIndexedRecord("name");
61         recordFactoryControl.setReturnValue(indexedRecord, 1);
62
63         connectionFactoryControl.replay();
64         recordFactoryControl.replay();
65
66         CciTemplate ct = new CciTemplate(connectionFactory);
67         ct.createIndexedRecord("name");
68
69         connectionFactoryControl.verify();
70         recordFactoryControl.verify();
71     }
72
73     public void testCreateMappedRecord() throws ResourceException JavaDoc {
74         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
75         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
76         MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory JavaDoc.class);
77         RecordFactory JavaDoc recordFactory = (RecordFactory JavaDoc) recordFactoryControl.getMock();
78         MockControl mappedRecordControl = MockControl.createStrictControl(MappedRecord JavaDoc.class);
79         MappedRecord JavaDoc mappedRecord = (MappedRecord JavaDoc) mappedRecordControl.getMock();
80
81         connectionFactory.getRecordFactory();
82         connectionFactoryControl.setReturnValue(recordFactory, 1);
83
84         recordFactory.createMappedRecord("name");
85         recordFactoryControl.setReturnValue(mappedRecord, 1);
86
87         connectionFactoryControl.replay();
88         recordFactoryControl.replay();
89
90         CciTemplate ct = new CciTemplate(connectionFactory);
91         ct.createMappedRecord("name");
92
93         connectionFactoryControl.verify();
94         recordFactoryControl.verify();
95     }
96
97     public void testTemplateExecuteInputOutput() throws ResourceException JavaDoc {
98         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
99         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
100         MockControl connectionControl = MockControl.createStrictControl(Connection JavaDoc.class);
101         Connection JavaDoc connection = (Connection JavaDoc) connectionControl.getMock();
102         MockControl interactionControl = MockControl.createStrictControl(Interaction JavaDoc.class);
103         Interaction JavaDoc interaction = (Interaction JavaDoc) interactionControl.getMock();
104
105         MockControl inputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
106         Record JavaDoc inputRecord = (Record JavaDoc) inputRecordControl.getMock();
107         MockControl outputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
108         Record JavaDoc outputRecord = (Record JavaDoc) outputRecordControl.getMock();
109
110         MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec JavaDoc.class);
111         InteractionSpec JavaDoc interactionSpec = (InteractionSpec JavaDoc) interactionSpecControl.getMock();
112
113         connectionFactory.getConnection();
114         connectionFactoryControl.setReturnValue(connection, 1);
115
116         connection.createInteraction();
117         connectionControl.setReturnValue(interaction, 1);
118
119         interaction.execute(interactionSpec, inputRecord, outputRecord);
120         interactionControl.setReturnValue(true, 1);
121
122         interaction.close();
123         interactionControl.setVoidCallable(1);
124
125         connection.close();
126         connectionControl.setVoidCallable(1);
127
128         connectionFactoryControl.replay();
129         connectionControl.replay();
130         interactionControl.replay();
131
132         CciTemplate ct = new CciTemplate(connectionFactory);
133         ct.execute(interactionSpec, inputRecord, outputRecord);
134
135         connectionFactoryControl.verify();
136         connectionControl.verify();
137         interactionControl.verify();
138     }
139
140     public void testTemplateExecuteInputTrueWithCreator() throws ResourceException JavaDoc {
141         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
142         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
143         MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory JavaDoc.class);
144         RecordFactory JavaDoc recordFactory = (RecordFactory JavaDoc) recordFactoryControl.getMock();
145         MockControl connectionControl = MockControl.createStrictControl(Connection JavaDoc.class);
146         Connection JavaDoc connection = (Connection JavaDoc) connectionControl.getMock();
147         MockControl interactionControl = MockControl.createStrictControl(Interaction JavaDoc.class);
148         Interaction JavaDoc interaction = (Interaction JavaDoc) interactionControl.getMock();
149         MockControl creatorControl = MockControl.createStrictControl(RecordCreator.class);
150         RecordCreator creator = (RecordCreator) creatorControl.getMock();
151
152         MockControl inputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
153         Record JavaDoc inputRecord = (Record JavaDoc) inputRecordControl.getMock();
154         MockControl outputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
155         Record JavaDoc outputRecord = (Record JavaDoc) outputRecordControl.getMock();
156
157         MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec JavaDoc.class);
158         InteractionSpec JavaDoc interactionSpec = (InteractionSpec JavaDoc) interactionSpecControl.getMock();
159
160         connectionFactory.getConnection();
161         connectionFactoryControl.setReturnValue(connection);
162
163         connectionFactory.getRecordFactory();
164         connectionFactoryControl.setReturnValue(recordFactory, 1);
165
166         connection.createInteraction();
167         connectionControl.setReturnValue(interaction);
168
169         creator.createRecord(recordFactory);
170         creatorControl.setReturnValue(outputRecord);
171
172         interaction.execute(interactionSpec, inputRecord, outputRecord);
173         interactionControl.setReturnValue(true, 1);
174
175         interaction.close();
176         interactionControl.setVoidCallable(1);
177
178         connection.close();
179         connectionControl.setVoidCallable(1);
180
181         connectionFactoryControl.replay();
182         connectionControl.replay();
183         interactionControl.replay();
184         creatorControl.replay();
185
186         CciTemplate ct = new CciTemplate(connectionFactory);
187         ct.setOutputRecordCreator(creator);
188         ct.execute(interactionSpec, inputRecord);
189
190         connectionFactoryControl.verify();
191         connectionControl.verify();
192         interactionControl.verify();
193         creatorControl.verify();
194     }
195
196     public void testTemplateExecuteInputFalse() throws ResourceException JavaDoc {
197         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
198         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
199         MockControl connectionControl = MockControl.createStrictControl(Connection JavaDoc.class);
200         Connection JavaDoc connection = (Connection JavaDoc) connectionControl.getMock();
201         MockControl interactionControl = MockControl.createStrictControl(Interaction JavaDoc.class);
202         Interaction JavaDoc interaction = (Interaction JavaDoc) interactionControl.getMock();
203
204         MockControl inputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
205         Record JavaDoc inputRecord = (Record JavaDoc) inputRecordControl.getMock();
206         MockControl outputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
207         Record JavaDoc outputRecord = (Record JavaDoc) outputRecordControl.getMock();
208
209         MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec JavaDoc.class);
210         InteractionSpec JavaDoc interactionSpec = (InteractionSpec JavaDoc) interactionSpecControl.getMock();
211
212         connectionFactory.getConnection();
213         connectionFactoryControl.setReturnValue(connection);
214
215         connection.createInteraction();
216         connectionControl.setReturnValue(interaction);
217
218         interaction.execute(interactionSpec, inputRecord);
219         interactionControl.setReturnValue(outputRecord, 1);
220
221         interaction.close();
222         interactionControl.setVoidCallable(1);
223
224         connection.close();
225         connectionControl.setVoidCallable(1);
226
227         connectionFactoryControl.replay();
228         connectionControl.replay();
229         interactionControl.replay();
230
231         CciTemplate ct = new CciTemplate(connectionFactory);
232         ct.execute(interactionSpec, inputRecord);
233
234         connectionFactoryControl.verify();
235         connectionControl.verify();
236         interactionControl.verify();
237     }
238
239     public void testTemplateExecuteInputExtractorTrueWithCreator() throws ResourceException JavaDoc, SQLException JavaDoc {
240         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
241         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
242         MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory JavaDoc.class);
243         RecordFactory JavaDoc recordFactory = (RecordFactory JavaDoc) recordFactoryControl.getMock();
244         MockControl connectionControl = MockControl.createStrictControl(Connection JavaDoc.class);
245         Connection JavaDoc connection = (Connection JavaDoc) connectionControl.getMock();
246         MockControl interactionControl = MockControl.createStrictControl(Interaction JavaDoc.class);
247         Interaction JavaDoc interaction = (Interaction JavaDoc) interactionControl.getMock();
248         MockControl extractorControl = MockControl.createStrictControl(RecordExtractor.class);
249         RecordExtractor extractor = (RecordExtractor) extractorControl.getMock();
250         MockControl creatorControl = MockControl.createStrictControl(RecordCreator.class);
251         RecordCreator creator = (RecordCreator) creatorControl.getMock();
252
253         MockControl inputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
254         Record JavaDoc inputRecord = (Record JavaDoc) inputRecordControl.getMock();
255         MockControl outputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
256         Record JavaDoc outputRecord = (Record JavaDoc) outputRecordControl.getMock();
257
258         MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec JavaDoc.class);
259         InteractionSpec JavaDoc interactionSpec = (InteractionSpec JavaDoc) interactionSpecControl.getMock();
260
261         Object JavaDoc obj = new Object JavaDoc();
262
263         connectionFactory.getConnection();
264         connectionFactoryControl.setReturnValue(connection);
265
266         connection.createInteraction();
267         connectionControl.setReturnValue(interaction);
268
269         connectionFactory.getRecordFactory();
270         connectionFactoryControl.setReturnValue(recordFactory, 1);
271
272         creator.createRecord(recordFactory);
273         creatorControl.setReturnValue(outputRecord);
274
275         interaction.execute(interactionSpec, inputRecord, outputRecord);
276         interactionControl.setReturnValue(true, 1);
277
278         extractor.extractData(outputRecord);
279         extractorControl.setReturnValue(obj);
280
281         interaction.close();
282         interactionControl.setVoidCallable(1);
283
284         connection.close();
285         connectionControl.setVoidCallable(1);
286
287         connectionFactoryControl.replay();
288         connectionControl.replay();
289         interactionControl.replay();
290         extractorControl.replay();
291         creatorControl.replay();
292
293         CciTemplate ct = new CciTemplate(connectionFactory);
294         ct.setOutputRecordCreator(creator);
295         ct.execute(interactionSpec, inputRecord, extractor);
296
297         connectionFactoryControl.verify();
298         connectionControl.verify();
299         interactionControl.verify();
300         extractorControl.verify();
301         creatorControl.verify();
302     }
303
304     public void testTemplateExecuteInputExtractorFalse() throws ResourceException JavaDoc, SQLException JavaDoc {
305         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
306         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
307         MockControl connectionControl = MockControl.createStrictControl(Connection JavaDoc.class);
308         Connection JavaDoc connection = (Connection JavaDoc) connectionControl.getMock();
309         MockControl interactionControl = MockControl.createStrictControl(Interaction JavaDoc.class);
310         Interaction JavaDoc interaction = (Interaction JavaDoc) interactionControl.getMock();
311         MockControl extractorControl = MockControl.createStrictControl(RecordExtractor.class);
312         RecordExtractor extractor = (RecordExtractor) extractorControl.getMock();
313
314         MockControl inputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
315         Record JavaDoc inputRecord = (Record JavaDoc) inputRecordControl.getMock();
316         MockControl outputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
317         Record JavaDoc outputRecord = (Record JavaDoc) outputRecordControl.getMock();
318
319         MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec JavaDoc.class);
320         InteractionSpec JavaDoc interactionSpec = (InteractionSpec JavaDoc) interactionSpecControl.getMock();
321
322         Object JavaDoc obj = new Object JavaDoc();
323
324         connectionFactory.getConnection();
325         connectionFactoryControl.setReturnValue(connection);
326
327         connection.createInteraction();
328         connectionControl.setReturnValue(interaction);
329
330         interaction.execute(interactionSpec, inputRecord);
331         interactionControl.setReturnValue(outputRecord, 1);
332
333         extractor.extractData(outputRecord);
334         extractorControl.setReturnValue(obj);
335
336         interaction.close();
337         interactionControl.setVoidCallable(1);
338
339         connection.close();
340         connectionControl.setVoidCallable(1);
341
342         connectionFactoryControl.replay();
343         connectionControl.replay();
344         interactionControl.replay();
345         extractorControl.replay();
346
347         CciTemplate ct = new CciTemplate(connectionFactory);
348         ct.execute(interactionSpec, inputRecord, extractor);
349
350         connectionFactoryControl.verify();
351         connectionControl.verify();
352         interactionControl.verify();
353         extractorControl.verify();
354     }
355
356     public void testTemplateExecuteInputGeneratorTrueWithCreator() throws ResourceException JavaDoc {
357         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
358         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
359         MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory JavaDoc.class);
360         RecordFactory JavaDoc recordFactory = (RecordFactory JavaDoc) recordFactoryControl.getMock();
361         MockControl connectionControl = MockControl.createStrictControl(Connection JavaDoc.class);
362         Connection JavaDoc connection = (Connection JavaDoc) connectionControl.getMock();
363         MockControl interactionControl = MockControl.createStrictControl(Interaction JavaDoc.class);
364         Interaction JavaDoc interaction = (Interaction JavaDoc) interactionControl.getMock();
365         MockControl generatorControl = MockControl.createStrictControl(RecordCreator.class);
366         RecordCreator generator = (RecordCreator) generatorControl.getMock();
367         MockControl creatorControl = MockControl.createStrictControl(RecordCreator.class);
368         RecordCreator creator = (RecordCreator) creatorControl.getMock();
369
370         MockControl inputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
371         Record JavaDoc inputRecord = (Record JavaDoc) inputRecordControl.getMock();
372         MockControl outputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
373         Record JavaDoc outputRecord = (Record JavaDoc) outputRecordControl.getMock();
374
375         MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec JavaDoc.class);
376         InteractionSpec JavaDoc interactionSpec = (InteractionSpec JavaDoc) interactionSpecControl.getMock();
377
378         connectionFactory.getRecordFactory();
379         connectionFactoryControl.setReturnValue(recordFactory, 1);
380
381         generator.createRecord(recordFactory);
382         generatorControl.setReturnValue(inputRecord);
383
384         connectionFactory.getConnection();
385         connectionFactoryControl.setReturnValue(connection);
386
387         connection.createInteraction();
388         connectionControl.setReturnValue(interaction);
389
390         creator.createRecord(recordFactory);
391         creatorControl.setReturnValue(outputRecord);
392
393         connectionFactory.getRecordFactory();
394         connectionFactoryControl.setReturnValue(recordFactory, 1);
395
396         interaction.execute(interactionSpec, inputRecord, outputRecord);
397         interactionControl.setReturnValue(true, 1);
398
399         interaction.close();
400         interactionControl.setVoidCallable(1);
401
402         connection.close();
403         connectionControl.setVoidCallable(1);
404
405         connectionFactoryControl.replay();
406         connectionControl.replay();
407         interactionControl.replay();
408         generatorControl.replay();
409         creatorControl.replay();
410
411         CciTemplate ct = new CciTemplate(connectionFactory);
412         ct.setOutputRecordCreator(creator);
413         ct.execute(interactionSpec, generator);
414
415         connectionFactoryControl.verify();
416         connectionControl.verify();
417         interactionControl.verify();
418         generatorControl.verify();
419         creatorControl.verify();
420     }
421
422     public void testTemplateExecuteInputGeneratorFalse() throws ResourceException JavaDoc {
423         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
424         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
425         MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory JavaDoc.class);
426         RecordFactory JavaDoc recordFactory = (RecordFactory JavaDoc) recordFactoryControl.getMock();
427         MockControl connectionControl = MockControl.createStrictControl(Connection JavaDoc.class);
428         Connection JavaDoc connection = (Connection JavaDoc) connectionControl.getMock();
429         MockControl interactionControl = MockControl.createStrictControl(Interaction JavaDoc.class);
430         Interaction JavaDoc interaction = (Interaction JavaDoc) interactionControl.getMock();
431         MockControl generatorControl = MockControl.createStrictControl(RecordCreator.class);
432         RecordCreator generator = (RecordCreator) generatorControl.getMock();
433
434         MockControl inputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
435         Record JavaDoc inputRecord = (Record JavaDoc) inputRecordControl.getMock();
436         MockControl outputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
437         Record JavaDoc outputRecord = (Record JavaDoc) outputRecordControl.getMock();
438
439         MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec JavaDoc.class);
440         InteractionSpec JavaDoc interactionSpec = (InteractionSpec JavaDoc) interactionSpecControl.getMock();
441
442         connectionFactory.getRecordFactory();
443         connectionFactoryControl.setReturnValue(recordFactory, 1);
444
445         connectionFactory.getConnection();
446         connectionFactoryControl.setReturnValue(connection);
447
448         connection.createInteraction();
449         connectionControl.setReturnValue(interaction);
450
451         generator.createRecord(recordFactory);
452         generatorControl.setReturnValue(inputRecord);
453
454         interaction.execute(interactionSpec, inputRecord);
455         interactionControl.setReturnValue(outputRecord, 1);
456
457         interaction.close();
458         interactionControl.setVoidCallable(1);
459
460         connection.close();
461         connectionControl.setVoidCallable(1);
462
463         connectionFactoryControl.replay();
464         connectionControl.replay();
465         interactionControl.replay();
466         generatorControl.replay();
467
468         CciTemplate ct = new CciTemplate(connectionFactory);
469         ct.execute(interactionSpec, generator);
470
471         connectionFactoryControl.verify();
472         connectionControl.verify();
473         interactionControl.verify();
474         generatorControl.verify();
475     }
476
477     public void testTemplateExecuteInputGeneratorExtractorTrueWithCreator() throws ResourceException JavaDoc, SQLException JavaDoc {
478         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
479         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
480         MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory JavaDoc.class);
481         RecordFactory JavaDoc recordFactory = (RecordFactory JavaDoc) recordFactoryControl.getMock();
482         MockControl connectionControl = MockControl.createStrictControl(Connection JavaDoc.class);
483         Connection JavaDoc connection = (Connection JavaDoc) connectionControl.getMock();
484         MockControl interactionControl = MockControl.createStrictControl(Interaction JavaDoc.class);
485         Interaction JavaDoc interaction = (Interaction JavaDoc) interactionControl.getMock();
486         MockControl generatorControl = MockControl.createStrictControl(RecordCreator.class);
487         RecordCreator generator = (RecordCreator) generatorControl.getMock();
488         MockControl extractorControl = MockControl.createStrictControl(RecordExtractor.class);
489         RecordExtractor extractor = (RecordExtractor) extractorControl.getMock();
490         MockControl creatorControl = MockControl.createStrictControl(RecordCreator.class);
491         RecordCreator creator = (RecordCreator) creatorControl.getMock();
492
493         MockControl inputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
494         Record JavaDoc inputRecord = (Record JavaDoc) inputRecordControl.getMock();
495         MockControl outputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
496         Record JavaDoc outputRecord = (Record JavaDoc) outputRecordControl.getMock();
497
498         MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec JavaDoc.class);
499         InteractionSpec JavaDoc interactionSpec = (InteractionSpec JavaDoc) interactionSpecControl.getMock();
500
501         Object JavaDoc obj = new Object JavaDoc();
502
503         connectionFactory.getRecordFactory();
504         connectionFactoryControl.setReturnValue(recordFactory, 1);
505
506         connectionFactory.getConnection();
507         connectionFactoryControl.setReturnValue(connection);
508
509         connection.createInteraction();
510         connectionControl.setReturnValue(interaction);
511
512         creator.createRecord(recordFactory);
513         creatorControl.setReturnValue(outputRecord);
514
515         connectionFactory.getRecordFactory();
516         connectionFactoryControl.setReturnValue(recordFactory, 1);
517
518         generator.createRecord(recordFactory);
519         generatorControl.setReturnValue(inputRecord);
520
521         interaction.execute(interactionSpec, inputRecord, outputRecord);
522         interactionControl.setReturnValue(true, 1);
523
524         extractor.extractData(outputRecord);
525         extractorControl.setReturnValue(obj);
526
527         interaction.close();
528         interactionControl.setVoidCallable(1);
529
530         connection.close();
531         connectionControl.setVoidCallable(1);
532
533         connectionFactoryControl.replay();
534         connectionControl.replay();
535         interactionControl.replay();
536         generatorControl.replay();
537         extractorControl.replay();
538         creatorControl.replay();
539
540         CciTemplate ct = new CciTemplate(connectionFactory);
541         ct.setOutputRecordCreator(creator);
542         assertEquals(obj, ct.execute(interactionSpec, generator, extractor));
543
544         connectionFactoryControl.verify();
545         connectionControl.verify();
546         interactionControl.verify();
547         generatorControl.verify();
548         extractorControl.verify();
549         creatorControl.verify();
550     }
551
552     public void testTemplateExecuteInputGeneratorExtractorFalse() throws ResourceException JavaDoc, SQLException JavaDoc {
553         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
554         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
555         MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory JavaDoc.class);
556         RecordFactory JavaDoc recordFactory = (RecordFactory JavaDoc) recordFactoryControl.getMock();
557         MockControl connectionControl = MockControl.createStrictControl(Connection JavaDoc.class);
558         Connection JavaDoc connection = (Connection JavaDoc) connectionControl.getMock();
559         MockControl interactionControl = MockControl.createStrictControl(Interaction JavaDoc.class);
560         Interaction JavaDoc interaction = (Interaction JavaDoc) interactionControl.getMock();
561         MockControl generatorControl = MockControl.createStrictControl(RecordCreator.class);
562         RecordCreator generator = (RecordCreator) generatorControl.getMock();
563         MockControl extractorControl = MockControl.createStrictControl(RecordExtractor.class);
564         RecordExtractor extractor = (RecordExtractor) extractorControl.getMock();
565
566         MockControl inputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
567         Record JavaDoc inputRecord = (Record JavaDoc) inputRecordControl.getMock();
568         MockControl outputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
569         Record JavaDoc outputRecord = (Record JavaDoc) outputRecordControl.getMock();
570
571         MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec JavaDoc.class);
572         InteractionSpec JavaDoc interactionSpec = (InteractionSpec JavaDoc) interactionSpecControl.getMock();
573
574         Object JavaDoc obj = new Object JavaDoc();
575
576         connectionFactory.getRecordFactory();
577         connectionFactoryControl.setReturnValue(recordFactory, 1);
578
579         connectionFactory.getConnection();
580         connectionFactoryControl.setReturnValue(connection);
581
582         connection.createInteraction();
583         connectionControl.setReturnValue(interaction);
584
585         generator.createRecord(recordFactory);
586         generatorControl.setReturnValue(inputRecord);
587
588         interaction.execute(interactionSpec, inputRecord);
589         interactionControl.setReturnValue(outputRecord, 1);
590
591         extractor.extractData(outputRecord);
592         extractorControl.setReturnValue(obj);
593
594         interaction.close();
595         interactionControl.setVoidCallable(1);
596
597         connection.close();
598         connectionControl.setVoidCallable(1);
599
600         connectionFactoryControl.replay();
601         connectionControl.replay();
602         interactionControl.replay();
603         generatorControl.replay();
604         extractorControl.replay();
605
606         CciTemplate ct = new CciTemplate(connectionFactory);
607         ct.execute(interactionSpec, generator, extractor);
608
609         connectionFactoryControl.verify();
610         connectionControl.verify();
611         interactionControl.verify();
612         generatorControl.verify();
613         extractorControl.verify();
614     }
615
616     public void testTemplateExecuteInputOutputConnectionSpec() throws ResourceException JavaDoc {
617         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
618         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
619         MockControl connectionControl = MockControl.createStrictControl(Connection JavaDoc.class);
620         Connection JavaDoc connection = (Connection JavaDoc) connectionControl.getMock();
621         MockControl interactionControl = MockControl.createStrictControl(Interaction JavaDoc.class);
622         Interaction JavaDoc interaction = (Interaction JavaDoc) interactionControl.getMock();
623
624         MockControl inputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
625         Record JavaDoc inputRecord = (Record JavaDoc) inputRecordControl.getMock();
626         MockControl outputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
627         Record JavaDoc outputRecord = (Record JavaDoc) outputRecordControl.getMock();
628
629         MockControl connectionSpecControl = MockControl.createStrictControl(ConnectionSpec JavaDoc.class);
630         ConnectionSpec JavaDoc connectionSpec = (ConnectionSpec JavaDoc) connectionSpecControl.getMock();
631         MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec JavaDoc.class);
632         InteractionSpec JavaDoc interactionSpec = (InteractionSpec JavaDoc) interactionSpecControl.getMock();
633
634         connectionFactory.getConnection(connectionSpec);
635         connectionFactoryControl.setReturnValue(connection, 1);
636
637         connection.createInteraction();
638         connectionControl.setReturnValue(interaction, 1);
639
640         interaction.execute(interactionSpec, inputRecord, outputRecord);
641         interactionControl.setReturnValue(true, 1);
642
643         interaction.close();
644         interactionControl.setVoidCallable(1);
645
646         connection.close();
647         connectionControl.setVoidCallable(1);
648
649         connectionFactoryControl.replay();
650         connectionControl.replay();
651         interactionControl.replay();
652
653         ConnectionSpecConnectionFactoryAdapter adapter = new ConnectionSpecConnectionFactoryAdapter();
654         adapter.setTargetConnectionFactory(connectionFactory);
655         adapter.setConnectionSpec(connectionSpec);
656         CciTemplate ct = new CciTemplate(adapter);
657         ct.execute(interactionSpec, inputRecord, outputRecord);
658
659         connectionFactoryControl.verify();
660         connectionControl.verify();
661         interactionControl.verify();
662     }
663
664     public void testTemplateExecuteInputOutputResultsSetFalse() throws ResourceException JavaDoc, SQLException JavaDoc {
665         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
666         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
667         MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory JavaDoc.class);
668         RecordFactory JavaDoc recordFactory = (RecordFactory JavaDoc) recordFactoryControl.getMock();
669         MockControl connectionControl = MockControl.createStrictControl(Connection JavaDoc.class);
670         Connection JavaDoc connection = (Connection JavaDoc) connectionControl.getMock();
671         MockControl interactionControl = MockControl.createStrictControl(Interaction JavaDoc.class);
672         Interaction JavaDoc interaction = (Interaction JavaDoc) interactionControl.getMock();
673         MockControl recordControl = MockControl.createStrictControl(Record JavaDoc.class);
674         Record JavaDoc record = (Record JavaDoc) recordControl.getMock();
675         MockControl resultsetControl = MockControl.createStrictControl(ResultSet JavaDoc.class);
676         ResultSet JavaDoc resultset = (ResultSet JavaDoc) resultsetControl.getMock();
677         MockControl generatorControl = MockControl.createStrictControl(RecordCreator.class);
678         RecordCreator generator = (RecordCreator) generatorControl.getMock();
679         MockControl extractorControl = MockControl.createStrictControl(RecordExtractor.class);
680         RecordExtractor extractor = (RecordExtractor) extractorControl.getMock();
681
682         MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec JavaDoc.class);
683         InteractionSpec JavaDoc interactionSpec = (InteractionSpec JavaDoc) interactionSpecControl.getMock();
684
685         Object JavaDoc obj = new Object JavaDoc();
686
687         connectionFactory.getRecordFactory();
688         connectionFactoryControl.setReturnValue(recordFactory, 1);
689
690         connectionFactory.getConnection();
691         connectionFactoryControl.setReturnValue(connection);
692
693         connection.createInteraction();
694         connectionControl.setReturnValue(interaction);
695
696         generator.createRecord(recordFactory);
697         generatorControl.setReturnValue(record);
698
699         interaction.execute(interactionSpec, record);
700         interactionControl.setReturnValue(resultset, 1);
701
702         extractor.extractData(resultset);
703         extractorControl.setReturnValue(obj);
704
705         resultset.close();
706         resultsetControl.setVoidCallable(1);
707
708         interaction.close();
709         interactionControl.setVoidCallable(1);
710
711         connection.close();
712         connectionControl.setVoidCallable(1);
713
714         connectionFactoryControl.replay();
715         connectionControl.replay();
716         interactionControl.replay();
717         generatorControl.replay();
718         extractorControl.replay();
719         resultsetControl.replay();
720
721         CciTemplate ct = new CciTemplate(connectionFactory);
722         ct.execute(interactionSpec, generator, extractor);
723
724         connectionFactoryControl.verify();
725         connectionControl.verify();
726         interactionControl.verify();
727         generatorControl.verify();
728         extractorControl.verify();
729         resultsetControl.verify();
730     }
731
732     public void testTemplateExecuteConnectionCallback() throws ResourceException JavaDoc, SQLException JavaDoc {
733         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
734         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
735         MockControl connectionControl = MockControl.createStrictControl(Connection JavaDoc.class);
736         Connection JavaDoc connection = (Connection JavaDoc) connectionControl.getMock();
737         MockControl connectionCallbackControl = MockControl.createStrictControl(ConnectionCallback.class);
738         ConnectionCallback connectionCallback = (ConnectionCallback) connectionCallbackControl.getMock();
739
740         Object JavaDoc obj = new Object JavaDoc();
741
742         connectionFactory.getConnection();
743         connectionFactoryControl.setReturnValue(connection);
744
745         connectionCallback.doInConnection(connection, connectionFactory);
746         connectionCallbackControl.setReturnValue(obj);
747
748         connection.close();
749         connectionControl.setVoidCallable(1);
750
751         connectionFactoryControl.replay();
752         connectionControl.replay();
753         connectionCallbackControl.replay();
754
755         CciTemplate ct = new CciTemplate(connectionFactory);
756         ct.execute(connectionCallback);
757
758         connectionFactoryControl.verify();
759         connectionControl.verify();
760         connectionCallbackControl.verify();
761     }
762
763     public void testTemplateExecuteInteractionCallback() throws ResourceException JavaDoc, SQLException JavaDoc {
764         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
765         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
766         MockControl connectionControl = MockControl.createStrictControl(Connection JavaDoc.class);
767         Connection JavaDoc connection = (Connection JavaDoc) connectionControl.getMock();
768         MockControl interactionControl = MockControl.createStrictControl(Interaction JavaDoc.class);
769         Interaction JavaDoc interaction = (Interaction JavaDoc) interactionControl.getMock();
770         MockControl interactionCallbackControl = MockControl.createStrictControl(InteractionCallback.class);
771         InteractionCallback interactionCallback = (InteractionCallback) interactionCallbackControl.getMock();
772
773         Object JavaDoc obj = new Object JavaDoc();
774
775         connectionFactory.getConnection();
776         connectionFactoryControl.setReturnValue(connection);
777
778         connection.createInteraction();
779         connectionControl.setReturnValue(interaction);
780
781         interactionCallback.doInInteraction(interaction, connectionFactory);
782         interactionCallbackControl.setReturnValue(obj);
783
784         interaction.close();
785         interactionControl.setVoidCallable(1);
786
787         connection.close();
788         connectionControl.setVoidCallable(1);
789
790         connectionFactoryControl.replay();
791         connectionControl.replay();
792         interactionControl.replay();
793         interactionCallbackControl.replay();
794
795         CciTemplate ct = new CciTemplate(connectionFactory);
796         ct.execute(interactionCallback);
797
798         connectionFactoryControl.verify();
799         connectionControl.verify();
800         interactionControl.verify();
801         interactionCallbackControl.verify();
802     }
803
804     public void testTemplateExecuteInputTrueTrueWithCreator() throws ResourceException JavaDoc {
805         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
806         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
807         MockControl connectionControl = MockControl.createStrictControl(Connection JavaDoc.class);
808         Connection JavaDoc connection = (Connection JavaDoc) connectionControl.getMock();
809         MockControl interactionControl = MockControl.createStrictControl(Interaction JavaDoc.class);
810         Interaction JavaDoc interaction = (Interaction JavaDoc) interactionControl.getMock();
811         MockControl creatorControl = MockControl.createStrictControl(RecordCreator.class);
812         RecordCreator creator = (RecordCreator) creatorControl.getMock();
813
814         MockControl inputOutputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
815         Record JavaDoc inputOutputRecord = (Record JavaDoc) inputOutputRecordControl.getMock();
816
817         MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec JavaDoc.class);
818         InteractionSpec JavaDoc interactionSpec = (InteractionSpec JavaDoc) interactionSpecControl.getMock();
819
820         connectionFactory.getConnection();
821         connectionFactoryControl.setReturnValue(connection);
822
823         connection.createInteraction();
824         connectionControl.setReturnValue(interaction);
825
826         interaction.execute(interactionSpec, inputOutputRecord, inputOutputRecord);
827         interactionControl.setReturnValue(true, 1);
828
829         interaction.close();
830         interactionControl.setVoidCallable(1);
831
832         connection.close();
833         connectionControl.setVoidCallable(1);
834
835         connectionFactoryControl.replay();
836         connectionControl.replay();
837         interactionControl.replay();
838         creatorControl.replay();
839
840         CciTemplate ct = new CciTemplate(connectionFactory);
841         ct.setOutputRecordCreator(creator);
842         ct.execute(interactionSpec, inputOutputRecord, inputOutputRecord);
843
844         connectionFactoryControl.verify();
845         connectionControl.verify();
846         interactionControl.verify();
847         creatorControl.verify();
848     }
849
850     public void testTemplateExecuteInputTrueTrue() throws ResourceException JavaDoc {
851         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
852         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
853         MockControl connectionControl = MockControl.createStrictControl(Connection JavaDoc.class);
854         Connection JavaDoc connection = (Connection JavaDoc) connectionControl.getMock();
855         MockControl interactionControl = MockControl.createStrictControl(Interaction JavaDoc.class);
856         Interaction JavaDoc interaction = (Interaction JavaDoc) interactionControl.getMock();
857
858         MockControl inputOutputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
859         Record JavaDoc inputOutputRecord = (Record JavaDoc) inputOutputRecordControl.getMock();
860
861         MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec JavaDoc.class);
862         InteractionSpec JavaDoc interactionSpec = (InteractionSpec JavaDoc) interactionSpecControl.getMock();
863
864         connectionFactory.getConnection();
865         connectionFactoryControl.setReturnValue(connection);
866
867         connection.createInteraction();
868         connectionControl.setReturnValue(interaction);
869
870         interaction.execute(interactionSpec, inputOutputRecord, inputOutputRecord);
871         interactionControl.setReturnValue(true, 1);
872
873         interaction.close();
874         interactionControl.setVoidCallable(1);
875
876         connection.close();
877         connectionControl.setVoidCallable(1);
878
879         connectionFactoryControl.replay();
880         connectionControl.replay();
881         interactionControl.replay();
882
883         CciTemplate ct = new CciTemplate(connectionFactory);
884         ct.execute(interactionSpec, inputOutputRecord, inputOutputRecord);
885
886         connectionFactoryControl.verify();
887         connectionControl.verify();
888         interactionControl.verify();
889     }
890
891     public void testTemplateExecuteInputFalseTrue() throws ResourceException JavaDoc {
892         MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory JavaDoc.class);
893         ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) connectionFactoryControl.getMock();
894         MockControl connectionControl = MockControl.createStrictControl(Connection JavaDoc.class);
895         Connection JavaDoc connection = (Connection JavaDoc) connectionControl.getMock();
896         MockControl interactionControl = MockControl.createStrictControl(Interaction JavaDoc.class);
897         Interaction JavaDoc interaction = (Interaction JavaDoc) interactionControl.getMock();
898
899         MockControl inputOutputRecordControl = MockControl.createStrictControl(Record JavaDoc.class);
900         Record JavaDoc inputOutputRecord = (Record JavaDoc) inputOutputRecordControl.getMock();
901
902         MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec JavaDoc.class);
903         InteractionSpec JavaDoc interactionSpec = (InteractionSpec JavaDoc) interactionSpecControl.getMock();
904
905         connectionFactory.getConnection();
906         connectionFactoryControl.setReturnValue(connection);
907
908         connection.createInteraction();
909         connectionControl.setReturnValue(interaction);
910
911         interaction.execute(interactionSpec, inputOutputRecord);
912         interactionControl.setReturnValue(null, 1);
913
914         interaction.close();
915         interactionControl.setVoidCallable(1);
916
917         connection.close();
918         connectionControl.setVoidCallable(1);
919
920         connectionFactoryControl.replay();
921         connectionControl.replay();
922         interactionControl.replay();
923
924         CciTemplate ct = new CciTemplate(connectionFactory);
925         Record JavaDoc tmpOutputRecord = (Record JavaDoc) ct.execute(interactionSpec, inputOutputRecord);
926         assertNull(tmpOutputRecord);
927
928         connectionFactoryControl.verify();
929         connectionControl.verify();
930         interactionControl.verify();
931     }
932
933 }
934
Popular Tags