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;
20
21
22 import java.lang.reflect.Method;
23
24 import static org.apache.directory.server.core.integ.state.TestServiceContext.cleanup;
25 import static org.apache.directory.server.core.integ.state.TestServiceContext.destroy;
26 import static org.apache.directory.server.core.integ.state.TestServiceContext.shutdown;
27 import static org.apache.directory.server.core.integ.state.TestServiceContext.test;
28 import org.junit.internal.runners.InitializationError;
29 import org.junit.internal.runners.JUnit4ClassRunner;
30 import org.junit.runner.Description;
31 import org.junit.runner.notification.Failure;
32 import org.junit.runner.notification.RunNotifier;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36
37
38
39
40
41
42
43 public class CiRunner extends JUnit4ClassRunner
44 {
45 private static final Logger LOG = LoggerFactory.getLogger( CiRunner.class );
46 private CiSuite suite;
47 private InheritableSettings settings;
48
49
50 public CiRunner( Class<?> clazz ) throws InitializationError
51 {
52 super( clazz );
53 }
54
55
56 protected InheritableSettings getSettings()
57 {
58 if ( settings != null )
59 {
60 return settings;
61 }
62
63 if ( suite == null )
64 {
65 settings = new InheritableSettings( getDescription(), null );
66 }
67
68 return settings;
69 }
70
71
72 @Override
73 public void run( final RunNotifier notifier )
74 {
75 super.run( notifier );
76 Level cleanupLevel = getSettings().getCleanupLevel();
77
78 if ( cleanupLevel == Level.CLASS )
79 {
80 try
81 {
82 shutdown();
83 cleanup();
84 destroy();
85 }
86 catch ( Exception e )
87 {
88 LOG.error( "Encountered exception while trying to cleanup after test class: "
89 + this.getDescription().getDisplayName(), e );
90 notifier.fireTestFailure( new Failure( getDescription(), e ) );
91 }
92 }
93 }
94
95
96 @Override
97 protected void invokeTestMethod( Method method, final RunNotifier notifier )
98 {
99 LOG.debug( "About to invoke test method {}", method.getName() );
100 Description description = methodDescription( method );
101 test( getTestClass(), wrapMethod( method ), notifier, new InheritableSettings( description, getSettings() ) );
102
103 Level cleanupLevel = getSettings().getCleanupLevel();
104
105 if ( cleanupLevel == Level.METHOD )
106 {
107 try
108 {
109 shutdown();
110 cleanup();
111 destroy();
112 }
113 catch ( Exception e )
114 {
115 LOG.error( "Encountered exception while trying to cleanup after test class: "
116 + this.getDescription().getDisplayName(), e );
117 notifier.fireTestFailure( new Failure( getDescription(), e ) );
118 }
119 }
120 }
121
122
123 public void setSuite( CiSuite suite )
124 {
125 this.suite = suite;
126 this.settings = new InheritableSettings( getDescription(), suite.getSettings() );
127 }
128
129
130 public CiSuite getSuite()
131 {
132 return suite;
133 }
134 }