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

File AbstractTest.java

 

Coverage histogram

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

Code metrics

4
26
8
1
156
88
10
0.38
3.25
8
1.25

Classes

Class Line # Actions
AbstractTest 52 26 0% 10 1
0.973684297.4%
 

Contributing tests

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