1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.test.cts

File RenderingTestClassRunner.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
24
7
1
153
83
11
0.46
3.43
7
1.57

Classes

Class Line # Actions
RenderingTestClassRunner 39 24 0% 11 5
0.848484984.8%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.test.cts;
21   
22    import java.lang.reflect.Method;
23    import java.util.List;
24   
25    import org.junit.runner.notification.Failure;
26    import org.junit.runner.notification.RunNotifier;
27    import org.junit.runners.BlockJUnit4ClassRunner;
28    import org.junit.runners.model.FrameworkMethod;
29    import org.junit.runners.model.InitializationError;
30    import org.junit.runners.model.Statement;
31    import org.xwiki.test.jmock.XWikiComponentInitializer;
32   
33    /**
34    * Represents a Test Runner for a single Rendering Test to execute.
35    *
36    * @version $Id: 9bd3183a9d4f156450b7bbf963b01c5ce596d001 $
37    * @since 4.1M1
38    */
 
39    public class RenderingTestClassRunner extends BlockJUnit4ClassRunner
40    {
41    /**
42    * Used to pass the Component Manager to the Rendering Test instance executing.
43    */
44    private XWikiComponentInitializer componentInitializer = new XWikiComponentInitializer();
45   
46    /**
47    * @see #RenderingTestClassRunner(Object, Class, TestData, String)
48    */
49    private Object testInstance;
50   
51    /**
52    * @see #RenderingTestClassRunner(Object, Class, TestData, String)
53    */
54    private TestData testData;
55   
56    /**
57    * @see #RenderingTestClassRunner(Object, Class, TestData, String)
58    */
59    private String metadataSyntaxId;
60   
61    /**
62    * @param testInstance the Test instance (The Test instance is the class on which this Compatibility Test Suite is
63    * used)
64    * @param testClass the {@link RenderingTest} class
65    * @param testData the Test Data, passed to the Rendering Test instance executing
66    * @param metadataSyntaxId the Syntax id of the syntax used as Metadata in the generated XDOM for parsers
67    * @throws InitializationError if the {@link RenderingTest} isn't a valid JUnit Test class
68    */
 
69  537 toggle RenderingTestClassRunner(Object testInstance, Class<?> testClass, TestData testData, String metadataSyntaxId)
70    throws InitializationError
71    {
72  537 super(testClass);
73  537 this.testInstance = testInstance;
74  537 this.testData = testData;
75  537 this.metadataSyntaxId = metadataSyntaxId;
76    }
77   
 
78  537 toggle @Override
79    public Object createTest() throws Exception
80    {
81  537 return getTestClass().getOnlyConstructor().newInstance(
82    this.testData, this.metadataSyntaxId, this.componentInitializer.getComponentManager());
83    }
84   
 
85  1074 toggle @Override
86    protected String getName()
87    {
88  1074 return this.testData.computeTestName();
89    }
90   
 
91  537 toggle @Override
92    protected String testName(final FrameworkMethod method)
93    {
94  537 return getName();
95    }
96   
 
97  537 toggle @Override
98    protected void validateConstructor(List<Throwable> errors)
99    {
100  537 validateOnlyOneConstructor(errors);
101    }
102   
 
103  537 toggle @Override
104    protected Statement classBlock(RunNotifier notifier)
105    {
106  537 return childrenInvoker(notifier);
107    }
108   
109    /**
110    * {@inheritDoc}
111    *
112    * <p>
113    * Initialize the Component Manager and call all methods annotated with {@link Initialized} in the suite,
114    * before each test is executed, to ensure test isolation.
115    * </p>
116    */
 
117  537 toggle @Override
118    protected void runChild(FrameworkMethod method, RunNotifier notifier)
119    {
120  537 try {
121  537 this.componentInitializer.initializeConfigurationSource();
122  537 this.componentInitializer.initializeExecution();
123    } catch (Exception e) {
124  0 notifier.fireTestFailure(new Failure(getDescription(),
125    new RuntimeException("Failed to initialize Component Manager", e)));
126    }
127   
128    // Check all methods for a ComponentManager annotation and call the found ones.
129  537 try {
130  537 for (Method klassMethod : this.testInstance.getClass().getMethods()) {
131  4833 Initialized componentManagerAnnotation = klassMethod.getAnnotation(Initialized.class);
132  4833 if (componentManagerAnnotation != null) {
133    // Call it!
134  0 klassMethod.invoke(this.testInstance, this.componentInitializer.getComponentManager());
135    }
136    }
137    } catch (Exception e) {
138  0 notifier.fireTestFailure(new Failure(getDescription(),
139    new RuntimeException("Failed to call Component Manager initialization method", e)));
140    }
141   
142  537 try {
143  537 super.runChild(method, notifier);
144    } finally {
145  537 try {
146  537 this.componentInitializer.shutdown();
147    } catch (Exception e) {
148  0 notifier.fireTestFailure(new Failure(getDescription(),
149    new RuntimeException("Failed to shutdown Component Manager", e)));
150    }
151    }
152    }
153    }