1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.directory.server.core.integ.state;
20
21
22 import java.io.IOException;
23
24 import org.apache.directory.server.core.integ.InheritableSettings;
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 public class StartedPristineState extends AbstractState
42 {
43 private static final Logger LOG = LoggerFactory.getLogger( StartedPristineState.class );
44
45
46
47
48
49
50
51
52 public StartedPristineState( TestServiceContext context )
53 {
54 super( context );
55 }
56
57
58
59
60
61
62
63
64
65 public void cleanup() throws IOException
66 {
67 LOG.debug( "calling cleanup()" );
68 doDelete( context.getService().getWorkingDirectory() );
69 }
70
71
72
73
74
75
76
77 public void startup() throws Exception
78 {
79 LOG.debug( "calling startup()" );
80 context.getService().startup();
81 }
82
83
84
85
86
87
88
89 public void shutdown() throws Exception
90 {
91 LOG.debug( "calling shutdown()" );
92 context.getService().shutdown();
93 }
94
95
96
97
98
99
100
101 public void destroy()
102 {
103 LOG.debug( "calling destroy()" );
104 context.setService( null );
105 context.setState( context.getNonExistentState() );
106 System.gc();
107 }
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 public void test( TestClass testClass, TestMethod testMethod, RunNotifier notifier, InheritableSettings settings )
124 {
125 LOG.debug( "calling test(): {}, mode {}", settings.getDescription().getDisplayName(), settings.getMode() );
126
127 if ( testMethod.isIgnored() )
128 {
129
130 return;
131 }
132
133 switch ( settings.getMode() )
134 {
135 case PRISTINE:
136
137 injectLdifs( context.getService(), settings );
138
139 TestServiceContext.invokeTest( testClass, testMethod, notifier, settings.getDescription() );
140
141 try
142 {
143 shutdown();
144 }
145 catch ( Exception e )
146 {
147
148
149
150 notifier.testAborted( settings.getDescription(), e );
151 return;
152 }
153
154 try
155 {
156 cleanup();
157 }
158 catch ( IOException ioe )
159 {
160 LOG.error( "Failed to cleanup new server instance: " + ioe );
161 notifier.testAborted( settings.getDescription(), ioe );
162 return;
163 }
164
165 destroy();
166 context.setState( context.getNonExistentState() );
167 return;
168
169 case ROLLBACK:
170 try
171 {
172 context.getService().getChangeLog().tag();
173 }
174 catch ( Exception e )
175 {
176
177
178
179 notifier.testAborted( settings.getDescription(), e );
180 return;
181 }
182
183
184 injectLdifs( context.getService(), settings );
185
186 TestServiceContext.invokeTest( testClass, testMethod, notifier, settings.getDescription() );
187 context.setState( context.getStartedNormalState() );
188
189 try
190 {
191 context.getState().revert();
192 }
193 catch ( Exception e )
194 {
195
196
197
198 notifier.testAborted( settings.getDescription(), e );
199 return;
200 }
201 return;
202
203 default:
204 return;
205 }
206 }
207 }