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

File StubVelocityManager.java

 
testDisplayMacroWhenSectionSpecified: Failed to lookup default document displayer.
testIncludeMacroWhenSectionSpecified: Failed to lookup default document displayer.
verifySubHeadingVelocityVariableCorrectlyEvaluatedWhenUsedInSection: Failed to lookup default document displayer.
webRssFiltersHiddenDocuments: Failed to lookup default document displayer.
testDisplayMacroShowsVelocityMacrosAreIsolated: Failed to lookup component [org.xwiki.test.rendering.velo...
executeWithIdGeneratedByVelocityMacro: Failed to lookup component [org.xwiki.test.rendering.velo...
testIncludeMacroWhenIncludingDocumentWithRelativeReferences: Failed to lookup default document displayer.
testIncludeMacroWithCurrentContextShowsVelocityMacrosAreShared: Failed to lookup component [org.xwiki.test.rendering.velo...
testIncludeMacroWithNewContextShowsVelocityMacrosAreIsolated: Failed to lookup component [org.xwiki.test.rendering.velo...
webRssDisplay: Failed to lookup default document displayer.
executeWhenNoIdAndSameContent: Failed to lookup component [org.xwiki.test.rendering.velo...
executeWhenNoIdAndDifferentContent: Failed to lookup component [org.xwiki.test.rendering.velo...
testIncludeMacroWithNewContextShowsPassingOnRestrictedFlag: Failed to lookup default document displayer.
testDisplayMacroWhenDisplayingDocumentWithRelativeReferences: Failed to lookup default document displayer.
executeWhenSameIdAndDifferentContent: Failed to lookup component [org.xwiki.test.rendering.velo...
 

Coverage histogram

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

Code metrics

6
20
5
1
131
74
9
0.45
4
5
1.8

Classes

Class Line # Actions
StubVelocityManager 49 20 0% 9 2
0.935483993.5%
 

Contributing tests

This file is covered by 15 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.rendering.velocity;
21   
22    import java.io.Reader;
23    import java.io.Writer;
24    import java.util.Map;
25    import java.util.Properties;
26   
27    import javax.inject.Inject;
28    import javax.inject.Singleton;
29    import javax.script.ScriptContext;
30   
31    import org.apache.velocity.VelocityContext;
32    import org.xwiki.component.annotation.Component;
33    import org.xwiki.component.phase.Initializable;
34    import org.xwiki.component.phase.InitializationException;
35    import org.xwiki.script.ScriptContextManager;
36    import org.xwiki.velocity.VelocityEngine;
37    import org.xwiki.velocity.VelocityManager;
38    import org.xwiki.velocity.XWikiVelocityException;
39   
40    /**
41    * Mock VelocityManager implementation used for testing, since we don't want to pull any dependency on the
42    * Model/Skin/etc for the Rendering module's unit tests.
43    *
44    * @version $Id: b452be253d28b702c54d004678a1ef0406fe2e33 $
45    * @since 1.5M2
46    */
47    @Component
48    @Singleton
 
49    public class StubVelocityManager implements VelocityManager, Initializable
50    {
51    /**
52    * Note that we use a single Velocity Engine instance in this Mock.
53    */
54    @Inject
55    private VelocityEngine velocityEngine;
56   
57    /**
58    * Used to get the current script context.
59    */
60    @Inject
61    private ScriptContextManager scriptContextManager;
62   
63    private VelocityContext velocityContext = new VelocityContext();
64   
 
65  15 toggle @Override
66    public void initialize() throws InitializationException
67    {
68  15 try {
69    // Configure the Velocity Engine not to use the Resource Webapp Loader since we don't
70    // need it and we would need to setup the Container component's ApplicationContext
71    // otherwise.
72  15 Properties properties = new Properties();
73  15 properties.setProperty("resource.loader", "file");
74  15 this.velocityEngine.initialize(properties);
75    } catch (XWikiVelocityException e) {
76  0 throw new InitializationException("Failed to initialize Velocity Engine", e);
77    }
78    Test failure here }
79   
 
80  22 toggle @Override
81    public VelocityContext getVelocityContext()
82    {
83    // Copy current JSR223 ScriptContext binding
84  22 for (Map.Entry<String, Object> entry : this.scriptContextManager.getScriptContext()
85    .getBindings(ScriptContext.ENGINE_SCOPE).entrySet()) {
86    // Not ideal since it does not allow to modify a binding but it's too dangerous for existing velocity script
87    // otherwise
88  28 if (!this.velocityContext.containsKey(entry.getKey())) {
89  19 this.velocityContext.put(entry.getKey(), entry.getValue());
90    }
91    }
92   
93  22 return this.velocityContext;
94    }
95   
 
96  22 toggle @Override
97    public VelocityContext getCurrentVelocityContext()
98    {
99  22 return this.velocityContext;
100    }
101   
 
102  50 toggle @Override
103    public VelocityEngine getVelocityEngine() throws XWikiVelocityException
104    {
105  50 return this.velocityEngine;
106    }
107   
 
108  22 toggle @Override
109    public boolean evaluate(Writer out, String templateName, Reader source) throws XWikiVelocityException
110    {
111    // Get up to date Velocity context
112  22 VelocityContext velocityContext = getVelocityContext();
113   
114    // Execute Velocity context
115  22 boolean result = getVelocityEngine().evaluate(velocityContext, out, templateName, source);
116   
117    // Update current script context with potentially modified Velocity context
118  22 ScriptContext scontext = this.scriptContextManager.getCurrentScriptContext();
119  22 for (Object vkey : velocityContext.getKeys()) {
120  32 if (vkey instanceof String) {
121  32 String svkey = (String) vkey;
122    // context is a reserved binding in JSR223 specification
123  32 if (!"context".equals(svkey)) {
124  31 scontext.setAttribute(svkey, velocityContext.get(svkey), ScriptContext.ENGINE_SCOPE);
125    }
126    }
127    }
128   
129  22 return result;
130    }
131    }