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

File PageObjectSuite.java

 

Coverage histogram

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

Code metrics

4
20
4
2
107
61
9
0.45
5
2
2.25

Classes

Class Line # Actions
PageObjectSuite 38 20 0% 9 4
0.8571428785.7%
PageObjectSuite.PostStart 42 0 - 0 0
-1.0 -
 

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.test.ui;
21   
22    import java.lang.annotation.ElementType;
23    import java.lang.annotation.Retention;
24    import java.lang.annotation.RetentionPolicy;
25    import java.lang.annotation.Target;
26    import java.lang.reflect.Method;
27   
28    import org.junit.runners.model.InitializationError;
29    import org.junit.runners.model.RunnerBuilder;
30    import org.xwiki.test.integration.XWikiExecutorSuite;
31   
32    /**
33    * Extends {@link XWikiExecutorSuite} and initialize the {@link PersistentTestContext}.
34    *
35    * @version $Id: ac4b2dd3799fe29efe842df18b2b94d7263e5978 $
36    * @since 3.2M3
37    */
 
38    public class PageObjectSuite extends XWikiExecutorSuite
39    {
40    @Retention(RetentionPolicy.RUNTIME)
41    @Target(ElementType.METHOD)
 
42    public static @interface PostStart
43    {
44    }
45   
46    private PersistentTestContext context;
47   
 
48  15 toggle public PageObjectSuite(Class< ? > suiteClass, RunnerBuilder builder) throws InitializationError
49    {
50  15 super(suiteClass, builder);
51    }
52   
 
53  15 toggle @Override
54    protected void beforeTests()
55    {
56    // Construct the executors and start the XWiki instances.
57  15 super.beforeTests();
58   
59  15 try {
60  15 initializePersistentTestContext();
61   
62    // Callback to setup executors in the suite class after containers have been started
63  15 for (Method method : getTestClass().getJavaClass().getMethods()) {
64  146 PostStart postStartAnnotation = method.getAnnotation(PostStart.class);
65  146 if (postStartAnnotation != null) {
66    // Call it!
67  4 Object instance = getTestClass().getJavaClass().newInstance();
68  4 method.invoke(instance, this.context);
69    }
70    }
71    } catch (Exception e) {
72    // Make sure to stop the executors if anything goes wrong
73  0 afterTests();
74   
75  0 throw new RuntimeException("Failed to initialize PO suite", e);
76    }
77    }
78   
 
79  15 toggle private void initializePersistentTestContext()
80    {
81  15 try {
82  15 this.context = new PersistentTestContext(getExecutors());
83  15 AbstractTest.initializeSystem(this.context.getUnstoppable());
84   
85    // Cache the initial CSRF token since that token needs to be passed to all forms (this is done automatically
86    // in TestUtils), including the login form. Whenever a new user logs in we need to recache.
87    // Note that this requires a running XWiki instance.
88  15 AbstractTest.context.getUtil().recacheSecretToken();
89    } catch (Exception e) {
90  0 throw new RuntimeException("Failed to initialize PersistentTestContext", e);
91    }
92    }
93   
 
94  15 toggle @Override
95    protected void afterTests()
96    {
97  15 if (context != null) {
98  15 try {
99  15 context.shutdown();
100    } catch (Exception e) {
101  1 throw new RuntimeException("Failed to shutdown PersistentTestContext", e);
102    }
103    }
104   
105    // Note: Don't call super.afterTests() since XWiki will be stopped twice otherwise!
106    }
107    }