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

File DefaultExecutionContextManagerTest.java

 

Code metrics

0
19
3
1
90
52
3
0.16
6.33
3
1

Classes

Class Line # Actions
DefaultExecutionContextManagerTest 44 19 0% 3 0
1.0100%
 

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 org.xwiki.context.internal;
21   
22    import java.util.Arrays;
23    import java.util.HashMap;
24    import java.util.List;
25    import java.util.Map;
26   
27    import javax.inject.Provider;
28   
29    import org.junit.Assert;
30    import org.junit.Test;
31    import org.xwiki.component.util.ReflectionUtils;
32    import org.xwiki.context.Execution;
33    import org.xwiki.context.ExecutionContext;
34    import org.xwiki.context.ExecutionContextException;
35    import org.xwiki.context.ExecutionContextInitializer;
36   
37    /**
38    * Unit tests for {@link ExecutionContext}.
39    *
40    * @version $Id: 4af95be4ed02cb2b10f6754891c865a2bb22641f $
41    * @since 1.8RC3
42    */
43    @SuppressWarnings("unchecked")
 
44    public class DefaultExecutionContextManagerTest
45    {
46    /**
47    * Verify we have different objects in the Execution Context after the clone.
48    */
 
49  1 toggle @Test
50    public void cloneExecutionContext() throws Exception
51    {
52  1 Execution execution = new DefaultExecution();
53  1 ExecutionContext context = new ExecutionContext();
54  1 execution.setContext(context);
55   
56  1 Map<Object, Object> xwikicontext = new HashMap<>();
57  1 context.newProperty("property1").initial(xwikicontext).inherited().declare();
58  1 context.newProperty("property2").initial(xwikicontext).inherited().makeFinal().cloneValue().declare();
59   
60  1 DefaultExecutionContextManager contextManager = new DefaultExecutionContextManager();
61  1 ReflectionUtils.setFieldValue(contextManager, "execution", execution);
62   
63    // Set up an Execution Context Initiliazer for the test
64  1 final ExecutionContextInitializer initializer = new ExecutionContextInitializer()
65    {
 
66  1 toggle @Override
67    public void initialize(ExecutionContext context) throws ExecutionContextException
68    {
69  1 context.setProperty("key", Arrays.asList("value"));
70    }
71    };
72  1 Provider<List<ExecutionContextInitializer>> provider = new Provider<List<ExecutionContextInitializer>>()
73    {
 
74  1 toggle @Override
75    public List<ExecutionContextInitializer> get()
76    {
77  1 return Arrays.asList(initializer);
78    }
79    };
80  1 ReflectionUtils.setFieldValue(contextManager, "initializerProvider", provider);
81   
82  1 ExecutionContext clonedContext = contextManager.clone(context);
83   
84  1 Assert.assertSame(context, execution.getContext());
85  1 Assert.assertEquals("value", ((List<String>) clonedContext.getProperty("key")).get(0));
86  1 Assert.assertNotSame(context.getProperty("key"), clonedContext.getProperty("key"));
87  1 Assert.assertSame(xwikicontext, clonedContext.getProperty("property1"));
88  1 Assert.assertNotSame(xwikicontext, clonedContext.getProperty("property2"));
89    }
90    }