KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > engine > WaitRetryStrategyTest


1 package org.jacorb.test.notification.engine;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2003 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import junit.framework.Test;
24 import junit.framework.TestSuite;
25
26 import org.jacorb.notification.engine.RetryException;
27 import org.jacorb.notification.engine.AbstractRetryStrategy;
28 import org.jacorb.notification.engine.WaitRetryStrategy;
29 import org.omg.CORBA.TRANSIENT JavaDoc;
30
31 /**
32  * @author Alphonse Bendt
33  */

34     
35 public class WaitRetryStrategyTest extends AbstractRetryStrategyTest
36 {
37     public WaitRetryStrategyTest(String JavaDoc name)
38     {
39         super(name);
40     }
41
42     public void testRetryTerminatesAndThrowsException() throws Exception JavaDoc
43     {
44         mockConsumer_.isRetryAllowed();
45         controlConsumer_.setReturnValue(true);
46
47         mockConsumer_.isRetryAllowed();
48         controlConsumer_.setReturnValue(true);
49
50         mockConsumer_.isRetryAllowed();
51         controlConsumer_.setDefaultReturnValue(false);
52
53         mockConsumer_.incErrorCounter();
54         controlConsumer_.setReturnValue(0);
55
56         mockConsumer_.destroy();
57
58         controlConsumer_.replay();
59
60         mockPushOperation_.invokePush();
61         controlPushOperation_.setThrowable(new TRANSIENT JavaDoc());
62
63         mockPushOperation_.dispose();
64
65         controlPushOperation_.replay();
66
67         try
68         {
69             objectUnderTest_.retry();
70
71             fail();
72         } catch (RetryException e)
73         {
74             // expected
75
}
76
77         controlPushOperation_.verify();
78         controlConsumer_.verify();
79     }
80
81     public void testRetrySucceeds() throws Exception JavaDoc
82     {
83         mockConsumer_.isRetryAllowed();
84         controlConsumer_.setDefaultReturnValue(true);
85
86         mockPushOperation_.invokePush();
87         mockPushOperation_.dispose();
88         controlPushOperation_.replay();
89
90         controlConsumer_.replay();
91
92         objectUnderTest_.retry();
93
94         controlConsumer_.verify();
95         controlPushOperation_.verify();
96     }
97
98     public void testSuccessfulRetryDisposesPushOperation() throws Exception JavaDoc
99     {
100         mockPushOperation_.invokePush();
101         mockPushOperation_.dispose();
102         
103         controlPushOperation_.replay();
104         
105         mockConsumer_.isRetryAllowed();
106         controlConsumer_.setDefaultReturnValue(true);
107         
108         controlConsumer_.replay();
109       
110         objectUnderTest_.retry();
111         
112         controlPushOperation_.verify();
113     }
114     
115     public void testNotSuccessfulRetryDisposes() throws Exception JavaDoc
116     {
117         mockPushOperation_.dispose();
118
119         mockConsumer_.isRetryAllowed();
120         controlConsumer_.setDefaultReturnValue(false);
121         
122         controlPushOperation_.replay();
123         
124         controlConsumer_.replay();
125         
126         objectUnderTest_.retry();
127         
128         controlPushOperation_.verify();
129     }
130
131     
132     public void testRetryAllowedDisposesPushOperation() throws Exception JavaDoc
133     {
134         mockPushOperation_.dispose();
135         
136         controlPushOperation_.replay();
137         
138         mockConsumer_.isRetryAllowed();
139         controlConsumer_.setDefaultReturnValue(true);
140         
141         controlConsumer_.replay();
142       
143         objectUnderTest_.retry();
144         
145         controlPushOperation_.verify();
146     }
147     
148     public static Test suite()
149     {
150         TestSuite suite = new TestSuite(WaitRetryStrategyTest.class);
151
152         return suite;
153     }
154
155     
156     protected void setUpTest()
157     {
158        // no op
159
}
160
161     
162     protected AbstractRetryStrategy newRetryStrategy()
163     {
164         return new WaitRetryStrategy(mockConsumer_, mockPushOperation_);
165     }
166 }
Popular Tags