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

File DefaultVelocityConfigurationTest.java

 

Code metrics

0
7
3
1
83
45
3
0.43
2.33
3
1

Classes

Class Line # Actions
DefaultVelocityConfigurationTest 45 7 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 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.velocity.internal;
21   
22    import java.util.Properties;
23   
24    import org.apache.commons.lang3.StringUtils;
25    import org.apache.velocity.tools.generic.ListTool;
26    import org.junit.Before;
27    import org.junit.Rule;
28    import org.junit.Test;
29    import org.xwiki.configuration.ConfigurationSource;
30    import org.xwiki.test.mockito.MockitoComponentMockingRule;
31    import org.xwiki.velocity.VelocityConfiguration;
32    import org.xwiki.velocity.introspection.DeprecatedCheckUberspector;
33    import org.xwiki.velocity.introspection.MethodArgumentsUberspector;
34    import org.xwiki.velocity.introspection.SecureUberspector;
35   
36    import static org.junit.Assert.assertEquals;
37    import static org.mockito.Mockito.when;
38   
39    /**
40    * Unit tests for {@link DefaultVelocityConfiguration}.
41    *
42    * @version $Id: 037821e19eddd6dd4bf17717695e1d46dfbb34f7 $
43    * @since 2.4RC1
44    */
 
45    public class DefaultVelocityConfigurationTest
46    {
47    @Rule
48    public MockitoComponentMockingRule<VelocityConfiguration> mocker =
49    new MockitoComponentMockingRule<VelocityConfiguration>(DefaultVelocityConfiguration.class);
50   
 
51  2 toggle @Before
52    public void configure() throws Exception
53    {
54  2 ConfigurationSource source = this.mocker.getInstance(ConfigurationSource.class);
55  2 when(source.getProperty("velocity.tools", Properties.class)).thenReturn(new Properties());
56  2 when(source.getProperty("velocity.properties", Properties.class)).thenReturn(new Properties());
57    }
58   
 
59  1 toggle @Test
60    public void testDefaultToolsPresent() throws Exception
61    {
62    // Verify for example that the List tool is present.
63  1 assertEquals(ListTool.class.getName(), this.mocker.getComponentUnderTest().getTools().get("listtool"));
64    }
65   
 
66  1 toggle @Test
67    public void testDefaultPropertiesPresent() throws Exception
68    {
69    // Verify that the secure uberspector is set by default
70  1 assertEquals(
71    StringUtils.join(new String[] { SecureUberspector.class.getName(),
72    DeprecatedCheckUberspector.class.getName(), MethodArgumentsUberspector.class.getName() }, ','),
73    this.mocker.getComponentUnderTest().getProperties().getProperty("runtime.introspector.uberspect"));
74   
75    // Verify that null values are allowed by default
76  1 assertEquals(Boolean.TRUE.toString(),
77    this.mocker.getComponentUnderTest().getProperties().getProperty("directive.set.null.allowed"));
78   
79    // Verify that Macros are isolated by default
80  1 assertEquals(Boolean.TRUE.toString(), this.mocker.getComponentUnderTest().getProperties()
81    .getProperty("velocimacro.permissions.allow.inline.local.scope"));
82    }
83    }