1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.test.ui

File AbstractTest.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
29
11
1
173
102
13
0.45
2.64
11
1.18

Classes

Class Line # Actions
AbstractTest 54 29 0% 13 3
0.931818293.2%
 

Contributing tests

This file is covered by 175 tests. .

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.util.ArrayList;
23    import java.util.Arrays;
24    import java.util.List;
25   
26    import org.junit.AfterClass;
27    import org.junit.Before;
28    import org.junit.BeforeClass;
29    import org.junit.Rule;
30    import org.junit.rules.TestName;
31    import org.junit.runner.RunWith;
32    import org.xwiki.component.annotation.ComponentAnnotationLoader;
33    import org.xwiki.component.annotation.ComponentDeclaration;
34    import org.xwiki.component.embed.EmbeddableComponentManager;
35    import org.xwiki.model.internal.DefaultModelConfiguration;
36    import org.xwiki.model.internal.reference.DefaultEntityReferenceProvider;
37    import org.xwiki.model.internal.reference.DefaultStringEntityReferenceResolver;
38    import org.xwiki.model.internal.reference.DefaultStringEntityReferenceSerializer;
39    import org.xwiki.model.internal.reference.DefaultSymbolScheme;
40    import org.xwiki.model.internal.reference.RelativeStringEntityReferenceResolver;
41    import org.xwiki.test.integration.XWikiExecutor;
42    import org.xwiki.test.ui.browser.BrowserTestRule;
43    import org.xwiki.test.ui.po.BaseElement;
44   
45    import com.google.code.tempusfugit.concurrency.IntermittentTestRunner;
46   
47    /**
48    * To be extended by all Test Classes. Allows to start/stop the Web Driver and get access to it.
49    *
50    * @version $Id: 9f340978c353e1eebf07af238070542fdc97fedd $
51    * @since 3.2M3
52    */
53    @RunWith(IntermittentTestRunner.class)
 
54    public abstract class AbstractTest
55    {
56    /**
57    * The object used to access the name of the current test.
58    */
59    @Rule
60    public final TestName testName = new TestName();
61   
62    /**
63    * Used for ignoring tests that use {@link org.xwiki.test.ui.browser.IgnoreBrowser} and
64    * {@link org.xwiki.test.ui.browser.IgnoreBrowsers} annotations.
65    */
66    @Rule
67    public BrowserTestRule browserRule = new BrowserTestRule(getDriver());
68   
69    /**
70    * Generates debugging information on test failure.
71    */
72    @Rule
73    public TestDebugger testDebugger = new TestDebugger(getDriver());
74   
75    protected static PersistentTestContext context;
76   
77    protected static EmbeddableComponentManager componentManager;
78   
79    /** Used so that AllTests can set the persistent test context. */
 
80  33 toggle public static void initializeSystem(PersistentTestContext context) throws Exception
81    {
82  33 AbstractTest.setContext(context);
83  33 BaseElement.setContext(context);
84  33 TestUtils.setContext(context);
85  33 AbstractTest.componentManager = new EmbeddableComponentManager();
86   
87    // Only load the minimal number of components required for the test framework, for both performance reasons
88    // and for avoiding having to declare dependencies such as HttpServletRequest.
89  33 ComponentAnnotationLoader loader = new ComponentAnnotationLoader();
90  33 List<ComponentDeclaration> componentDeclarations = new ArrayList<>();
91  33 componentDeclarations.add(new ComponentDeclaration(DefaultStringEntityReferenceResolver.class.getName()));
92  33 componentDeclarations.add(new ComponentDeclaration(DefaultStringEntityReferenceSerializer.class.getName()));
93  33 componentDeclarations.add(new ComponentDeclaration(RelativeStringEntityReferenceResolver.class.getName()));
94  33 componentDeclarations.add(new ComponentDeclaration(DefaultEntityReferenceProvider.class.getName()));
95  33 componentDeclarations.add(new ComponentDeclaration(DefaultModelConfiguration.class.getName()));
96  33 componentDeclarations.add(new ComponentDeclaration(DefaultSymbolScheme.class.getName()));
97  33 loader.initialize(AbstractTest.componentManager, AbstractTest.class.getClassLoader(), componentDeclarations);
98   
99  33 TestUtils.initializeComponent(AbstractTest.componentManager);
100    }
101   
 
102  33 toggle public static void setContext(PersistentTestContext testContext)
103    {
104  33 context = testContext;
105    }
106   
 
107  0 toggle public static PersistentTestContext getContext()
108    {
109  0 return context;
110    }
111   
 
112  93 toggle @BeforeClass
113    public static void init() throws Exception
114    {
115    // This will not be null if we are in the middle of allTests
116  93 if (context == null) {
117  12 init(Arrays.asList(new XWikiExecutor(0)));
118    }
119    }
120   
 
121  14 toggle public static void init(List<XWikiExecutor> executors) throws Exception
122    {
123  14 PersistentTestContext persistentTestContext = new PersistentTestContext(executors);
124  14 initializeSystem(persistentTestContext);
125   
126    // Start XWiki
127  14 persistentTestContext.start();
128   
129    // Cache the initial CSRF token since that token needs to be passed to all forms (this is done automatically
130    // in TestUtils), including the login form. Whenever a new user logs in we need to recache.
131    // Note that this requires a running XWiki instance.
132  14 getUtil().recacheSecretToken();
133    }
134   
 
135  98 toggle @AfterClass
136    public static void shutdown() throws Exception
137    {
138    // The context can be null if the XWiki Server couldn't start for example.
139  98 if (context != null) {
140  98 context.shutdown();
141    }
142    }
143   
 
144  298 toggle @Before
145    public void beforeTest()
146    {
147    // Make sure to start the test on first instance
148  298 getUtil().switchExecutor(0);
149    }
150   
 
151  244 toggle protected String getTestMethodName()
152    {
153  244 return this.testName.getMethodName();
154    }
155   
 
156  323 toggle protected String getTestClassName()
157    {
158  323 return getClass().getSimpleName();
159    }
160   
 
161  998 toggle protected static XWikiWebDriver getDriver()
162    {
163  998 return context.getDriver();
164    }
165   
166    /**
167    * @return Utility class with functions not specific to any test or element.
168    */
 
169  2260 toggle protected static TestUtils getUtil()
170    {
171  2260 return context.getUtil();
172    }
173    }