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 javax.naming.NamingException;
25
26 import org.apache.directory.server.core.integ.DirectoryServiceFactory;
27 import org.apache.directory.server.core.integ.InheritableSettings;
28 import static org.apache.directory.server.core.integ.IntegrationUtils.doDelete;
29 import org.junit.internal.runners.TestClass;
30 import org.junit.internal.runners.TestMethod;
31 import org.junit.runner.notification.RunNotifier;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35
36
37
38
39
40
41
42 public class NonExistentState extends AbstractState
43 {
44 private static final Logger LOG = LoggerFactory.getLogger( NonExistentState.class );
45
46
47
48
49
50
51
52 public NonExistentState( TestServiceContext context )
53 {
54 super( context );
55 }
56
57
58
59
60
61
62
63
64
65
66
67 public void create( InheritableSettings settings ) throws NamingException
68 {
69 LOG.debug( "calling create()" );
70
71 try
72 {
73 DirectoryServiceFactory factory = settings.getFactory();
74 context.setService( factory.newInstance() );
75 }
76 catch ( InstantiationException ie )
77 {
78 throw new NamingException( ie.getMessage() );
79 }
80 catch ( IllegalAccessException iae )
81 {
82 throw new NamingException( iae.getMessage() );
83 }
84 catch ( Exception e )
85 {
86 throw new NamingException( e.getMessage() );
87 }
88 }
89
90
91
92
93
94
95
96
97
98 public void cleanup() throws IOException
99 {
100 LOG.debug( "calling cleanup()" );
101 doDelete( context.getService().getWorkingDirectory() );
102 }
103
104
105
106
107
108
109
110 public void startup() throws Exception
111 {
112 LOG.debug( "calling startup()" );
113 context.getService().startup();
114 }
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133 public void test( TestClass testClass, TestMethod testMethod, RunNotifier notifier, InheritableSettings settings )
134 {
135 LOG.debug( "calling test(): {}, mode {}", settings.getDescription().getDisplayName(), settings.getMode() );
136
137 if ( testMethod.isIgnored() )
138 {
139
140 return;
141 }
142
143 switch ( settings.getMode() )
144 {
145 case CUMULATIVE:
146 case RESTART:
147 try
148 {
149 create( settings );
150 }
151 catch ( NamingException ne )
152 {
153 LOG.error( "Failed to create and start new server instance: " + ne );
154 notifier.testAborted( settings.getDescription(), ne );
155 return;
156 }
157
158 try
159 {
160 startup();
161 }
162 catch ( Exception e )
163 {
164 LOG.error( "Failed to create and start new server instance: " + e );
165 notifier.testAborted( settings.getDescription(), e );
166 return;
167 }
168
169
170 context.setState( context.getStartedNormalState() );
171 context.getState().test( testClass, testMethod, notifier, settings );
172 return;
173
174
175 case PRISTINE:
176 case ROLLBACK:
177 try
178 {
179 create( settings );
180 }
181 catch ( NamingException ne )
182 {
183 LOG.error( "Failed to create and start new server instance: " + ne );
184 notifier.testAborted( settings.getDescription(), ne );
185 return;
186 }
187
188 try
189 {
190 cleanup();
191 }
192 catch ( IOException ioe )
193 {
194 LOG.error( "Failed to create and start new server instance: " + ioe );
195 notifier.testAborted( settings.getDescription(), ioe );
196 return;
197 }
198
199 try
200 {
201 startup();
202 }
203 catch ( Exception e )
204 {
205 LOG.error( "Failed to create and start new server instance: " + e );
206 notifier.testAborted( settings.getDescription(), e );
207 return;
208 }
209
210 context.setState( context.getStartedPristineState() );
211 context.getState().test( testClass, testMethod, notifier, settings );
212 return;
213
214 default:
215 return;
216 }
217 }
218 }