1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.internal

File XWikiStubContextInitializerTest.java

 

Code metrics

0
23
3
1
92
53
4
0.17
7.67
3
1.33

Classes

Class Line # Actions
XWikiStubContextInitializerTest 37 23 0% 4 1
0.9615384396.2%
 

Contributing tests

This file is covered by 1 test. .

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 com.xpn.xwiki.internal;
21   
22    import org.jmock.Mock;
23    import org.xwiki.context.ExecutionContext;
24    import org.xwiki.context.ExecutionContextException;
25    import org.xwiki.context.ExecutionContextManager;
26   
27    import com.xpn.xwiki.XWiki;
28    import com.xpn.xwiki.XWikiContext;
29    import com.xpn.xwiki.test.AbstractBridgedXWikiComponentTestCase;
30    import com.xpn.xwiki.util.XWikiStubContextProvider;
31   
32    /**
33    * Validate XWikiStubContextInitializer and DefaultXWikiStubContextProvider.
34    *
35    * @version $Id: fa61d5942674321beabc04724650a29e43d34193 $
36    */
 
37    public class XWikiStubContextInitializerTest extends AbstractBridgedXWikiComponentTestCase
38    {
39    private ExecutionContextManager executionContextManager;
40   
41    private Mock mockXWiki;
42   
 
43  1 toggle @Override
44    protected void setUp() throws Exception
45    {
46  1 super.setUp();
47   
48  1 this.executionContextManager = getComponentManager().getInstance(ExecutionContextManager.class);
49    }
50   
 
51  1 toggle public void testWithAndWithoutXWikiContext() throws Exception
52    {
53  1 XWikiContext xcontext = new XWikiContext();
54  1 xcontext.put("key", "value");
55   
56  1 this.mockXWiki = mock(XWiki.class);
57  1 this.mockXWiki.stubs().method("prepareResources");
58   
59  1 xcontext.setWiki((XWiki) this.mockXWiki.proxy());
60   
61  1 ExecutionContext context = new ExecutionContext();
62  1 xcontext.declareInExecutionContext(context);
63   
64  1 XWikiStubContextProvider stubContextProvider =
65    getComponentManager().getInstance(XWikiStubContextProvider.class);
66  1 stubContextProvider.initialize(xcontext);
67   
68  1 final ExecutionContext daemonContext = new ExecutionContext();
69   
70  1 Thread thread = new Thread(new Runnable()
71    {
 
72  1 toggle @Override
73    public void run()
74    {
75  1 try {
76  1 executionContextManager.initialize(daemonContext);
77    } catch (ExecutionContextException e) {
78  0 fail("Failed to initialize execution context: " + e.getStackTrace());
79    }
80    }
81    });
82   
83  1 thread.start();
84  1 thread.join();
85   
86  1 XWikiContext daemonXcontext = (XWikiContext) daemonContext.getProperty("xwikicontext");
87  1 assertNotNull(daemonXcontext);
88  1 assertNotSame(xcontext, daemonXcontext);
89  1 assertEquals("value", daemonXcontext.get("key"));
90  1 assertNotNull(daemonXcontext.getWiki());
91    }
92    }