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

File StubVelocityManager.java

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

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
41% of files have more coverage

Code metrics

6
18
5
1
126
72
9
0.5
3.6
5
1.8

Classes

Class Line # Actions
StubVelocityManager 49 18 0% 9 3
0.896551789.7%
 

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: 97936f70bdef0b0537ebc6b0c6dd0be1850ef98c $
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  15 this.velocityEngine.initialize(new Properties());
70    } catch (XWikiVelocityException e) {
71  0 throw new InitializationException("Failed to initialize Velocity Engine", e);
72    }
73    Test failure here }
74   
 
75  22 toggle @Override
76    public VelocityContext getVelocityContext()
77    {
78    // Copy current JSR223 ScriptContext binding
79  22 for (Map.Entry<String, Object> entry : this.scriptContextManager.getScriptContext()
80    .getBindings(ScriptContext.ENGINE_SCOPE).entrySet()) {
81    // Not ideal since it does not allow to modify a binding but it's too dangerous for existing velocity script
82    // otherwise
83  25 if (!this.velocityContext.containsKey(entry.getKey())) {
84  16 this.velocityContext.put(entry.getKey(), entry.getValue());
85    }
86    }
87   
88  22 return this.velocityContext;
89    }
90   
 
91  22 toggle @Override
92    public VelocityContext getCurrentVelocityContext()
93    {
94  22 return this.velocityContext;
95    }
96   
 
97  50 toggle @Override
98    public VelocityEngine getVelocityEngine() throws XWikiVelocityException
99    {
100  50 return this.velocityEngine;
101    }
102   
 
103  22 toggle @Override
104    public boolean evaluate(Writer out, String templateName, Reader source) throws XWikiVelocityException
105    {
106    // Get up to date Velocity context
107  22 VelocityContext velocityContext = getVelocityContext();
108   
109    // Execute Velocity context
110  22 boolean result = getVelocityEngine().evaluate(velocityContext, out, templateName, source);
111   
112    // Update current script context with potentially modified Velocity context
113  22 ScriptContext scontext = this.scriptContextManager.getCurrentScriptContext();
114  22 for (Object vkey : velocityContext.getKeys()) {
115  29 if (vkey instanceof String) {
116  29 String svkey = (String) vkey;
117    // context is a reserved binding in JSR223 specification
118  29 if (!"context".equals(svkey)) {
119  29 scontext.setAttribute(svkey, velocityContext.get(svkey), ScriptContext.ENGINE_SCOPE);
120    }
121    }
122    }
123   
124  22 return result;
125    }
126    }