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

File DefaultVelocityConfigurationTest.java

 

Code metrics

0
7
3
1
82
44
3
0.43
2.33
3
1

Classes

Class Line # Actions
DefaultVelocityConfigurationTest 46 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.jupiter.api.BeforeEach;
27    import org.junit.jupiter.api.Test;
28    import org.xwiki.component.manager.ComponentManager;
29    import org.xwiki.configuration.ConfigurationSource;
30    import org.xwiki.test.junit5.mockito.ComponentTest;
31    import org.xwiki.test.junit5.mockito.InjectMockComponents;
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.jupiter.api.Assertions.assertEquals;
37    import static org.mockito.Mockito.when;
38   
39    /**
40    * Unit tests for {@link DefaultVelocityConfiguration}.
41    *
42    * @version $Id: 224aee715bb5c144a179f38364c0ade5ec2728fb $
43    * @since 2.4RC1
44    */
45    @ComponentTest
 
46    public class DefaultVelocityConfigurationTest
47    {
48    @InjectMockComponents
49    private DefaultVelocityConfiguration configuration;
50   
 
51  2 toggle @BeforeEach
52    public void configure(ComponentManager componentManager) throws Exception
53    {
54  2 ConfigurationSource source = componentManager.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 getToolsReturnsDefaultTools()
61    {
62    // Verify for example that the List tool is present.
63  1 assertEquals(ListTool.class.getName(), this.configuration.getTools().get("listtool"));
64    }
65   
 
66  1 toggle @Test
67    public void getPropertiesReturnsDefaultProperties() throws Exception
68    {
69    // Verify that the secure uberspector is set by default
70  1 assertEquals(StringUtils.join(new String[] { SecureUberspector.class.getName(),
71    DeprecatedCheckUberspector.class.getName(), MethodArgumentsUberspector.class.getName() }, ','),
72    this.configuration.getProperties().getProperty("runtime.introspector.uberspect"));
73   
74    // Verify that null values are allowed by default
75  1 assertEquals(Boolean.TRUE.toString(),
76    this.configuration.getProperties().getProperty("directive.set.null.allowed"));
77   
78    // Verify that Macros are isolated by default
79  1 assertEquals(Boolean.TRUE.toString(),
80    this.configuration.getProperties().getProperty("velocimacro.permissions.allow.inline.local.scope"));
81    }
82    }