1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.directory.server.integ.state;
20
21
22 import java.io.IOException;
23
24 import org.apache.directory.server.integ.InheritableServerSettings;
25 import static org.apache.directory.server.core.integ.IntegrationUtils.doDelete;
26 import org.junit.internal.runners.TestClass;
27 import org.junit.internal.runners.TestMethod;
28 import org.junit.runner.notification.RunNotifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33
34
35
36
37
38
39
40
41
42
43
44 public class StartedNormalState extends AbstractState
45 {
46 private static final Logger LOG = LoggerFactory.getLogger( StartedNormalState.class );
47
48
49
50
51
52
53
54
55 public StartedNormalState( TestServerContext context )
56 {
57 super( context );
58 }
59
60
61
62
63
64
65
66 public void destroy()
67 {
68 LOG.debug( "calling destroy()" );
69 context.getLdapServer().setDirectoryService( null );
70 context.setLdapServer( null );
71 context.setState( context.getNonExistentState() );
72 System.gc();
73 }
74
75
76
77
78
79
80
81
82
83 public void cleanup() throws IOException
84 {
85 LOG.debug( "calling cleanup()" );
86 doDelete( context.getLdapServer().getDirectoryService().getWorkingDirectory() );
87 }
88
89
90
91
92
93
94
95 public void startup() throws Exception
96 {
97 LOG.debug( "calling start()" );
98 context.getLdapServer().getDirectoryService().startup();
99 context.getLdapServer().start();
100 }
101
102
103
104
105
106
107
108 public void shutdown() throws Exception
109 {
110 LOG.debug( "calling shutdown()" );
111 context.getLdapServer().stop();
112 context.getLdapServer().getDirectoryService().shutdown();
113 }
114
115
116
117
118
119
120
121
122
123 public void revert() throws Exception
124 {
125 LOG.debug( "calling revert()" );
126 context.getLdapServer().getDirectoryService().revert();
127 }
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143 public void test( TestClass testClass, TestMethod testMethod, RunNotifier notifier, InheritableServerSettings settings )
144 {
145 LOG.debug( "calling test(): {}, mode {}", settings.getDescription().getDisplayName(), settings.getMode() );
146
147 if ( testMethod.isIgnored() )
148 {
149
150 return;
151 }
152
153 switch ( settings.getMode() )
154 {
155 case ROLLBACK:
156 try
157 {
158 context.getLdapServer().getDirectoryService().getChangeLog().tag();
159
160
161 injectLdifs( context.getLdapServer().getDirectoryService(), settings );
162 }
163 catch ( Exception e )
164 {
165
166
167
168 notifier.testAborted( settings.getDescription(), e );
169 return;
170 }
171
172 TestServerContext.invokeTest( testClass, testMethod, notifier, settings.getDescription() );
173
174 try
175 {
176 revert();
177 }
178 catch ( Exception e )
179 {
180
181
182
183 notifier.testAborted( settings.getDescription(), e );
184 return;
185 }
186
187 return;
188
189 case RESTART :
190
191 try
192 {
193 injectLdifs( context.getLdapServer().getDirectoryService(), settings );
194 }
195 catch ( Exception e )
196 {
197
198
199
200 notifier.testAborted( settings.getDescription(), e );
201 return;
202 }
203
204 TestServerContext.invokeTest( testClass, testMethod, notifier, settings.getDescription() );
205
206 try
207 {
208 shutdown();
209 }
210 catch ( Exception e )
211 {
212
213
214
215 notifier.testAborted( settings.getDescription(), e );
216 return;
217 }
218
219 try
220 {
221 startup();
222 }
223 catch ( Exception e )
224 {
225 LOG.error( "Failed to create and start new server instance: " + e );
226 notifier.testAborted( settings.getDescription(), e );
227 return;
228 }
229
230 return;
231
232 default:
233 return;
234 }
235 }
236 }