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 javax.naming.NamingException;
25
26 import org.apache.directory.server.integ.LdapServerFactory;
27 import org.apache.directory.server.integ.InheritableServerSettings;
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( TestServerContext context )
53 {
54 super( context );
55 }
56
57
58
59
60
61
62
63
64
65
66
67 public void create( InheritableServerSettings settings ) throws NamingException
68 {
69 LOG.debug( "calling create()" );
70
71 try
72 {
73 LdapServerFactory factory = settings.getFactory();
74 context.setLdapServer( 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.getLdapServer().getDirectoryService().getWorkingDirectory() );
102 }
103
104
105
106
107
108
109
110 public void startup() throws Exception
111 {
112 LOG.debug( "calling startup()" );
113 context.getLdapServer().getDirectoryService().startup();
114 context.getLdapServer().start();
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134 public void test( TestClass testClass, TestMethod testMethod, RunNotifier notifier, InheritableServerSettings settings )
135 {
136 LOG.debug( "calling test(): {}, mode {}", settings.getDescription().getDisplayName(), settings.getMode() );
137
138 if ( testMethod.isIgnored() )
139 {
140
141 return;
142 }
143
144 switch ( settings.getMode() )
145 {
146 case CUMULATIVE:
147 case RESTART:
148 try
149 {
150 create( settings );
151 }
152 catch ( NamingException ne )
153 {
154 LOG.error( "Failed to create and start new server instance: " + ne );
155 notifier.testAborted( settings.getDescription(), ne );
156 return;
157 }
158
159 try
160 {
161 startup();
162 }
163 catch ( Exception e )
164 {
165 LOG.error( "Failed to create and start new server instance: " + e );
166 notifier.testAborted( settings.getDescription(), e );
167 return;
168 }
169
170
171 context.setState( context.getStartedNormalState() );
172 context.getState().test( testClass, testMethod, notifier, settings );
173 return;
174
175
176 case PRISTINE:
177 case ROLLBACK:
178 try
179 {
180 create( settings );
181 }
182 catch ( NamingException ne )
183 {
184 LOG.error( "Failed to create and start new server instance: " + ne );
185 notifier.testAborted( settings.getDescription(), ne );
186 return;
187 }
188
189 try
190 {
191 cleanup();
192 }
193 catch ( IOException ioe )
194 {
195 LOG.error( "Failed to create and start new server instance: " + ioe );
196 notifier.testAborted( settings.getDescription(), ioe );
197 return;
198 }
199
200 try
201 {
202 startup();
203 }
204 catch ( Exception e )
205 {
206 LOG.error( "Failed to create and start new server instance: " + e );
207 notifier.testAborted( settings.getDescription(), e );
208 return;
209 }
210
211 context.setState( context.getStartedPristineState() );
212 context.getState().test( testClass, testMethod, notifier, settings );
213 return;
214
215 default:
216 return;
217 }
218 }
219 }