1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal.cache.rendering

File DefaultRenderingCacheConfigurationTest.java

 

Code metrics

0
32
10
1
171
115
10
0.31
3.2
10
1

Classes

Class Line # Actions
DefaultRenderingCacheConfigurationTest 56 32 0% 10 0
1.0100%
 

Contributing tests

This file is covered by 9 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 com.xpn.xwiki.internal.cache.rendering;
21   
22    import java.util.Arrays;
23    import java.util.Collections;
24   
25    import org.junit.Assert;
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.model.internal.DefaultModelConfiguration;
31    import org.xwiki.model.internal.DefaultModelContext;
32    import org.xwiki.model.internal.reference.DefaultStringEntityReferenceSerializer;
33    import org.xwiki.model.internal.reference.DefaultSymbolScheme;
34    import org.xwiki.model.reference.DocumentReference;
35    import org.xwiki.test.annotation.ComponentList;
36    import org.xwiki.test.internal.MockConfigurationSource;
37   
38    import com.xpn.xwiki.internal.model.reference.CompactWikiStringEntityReferenceSerializer;
39    import com.xpn.xwiki.internal.model.reference.CurrentEntityReferenceProvider;
40    import com.xpn.xwiki.test.MockitoOldcoreRule;
41   
42    /**
43    * Unit test for {@link DefaultRenderingCacheConfiguration}.
44    *
45    * @version $Id: cfeabf9a54dce3eec0740fea1d516fa66e4a5f43 $
46    */
47    @ComponentList(value = {
48    DefaultRenderingCacheConfiguration.class,
49    DefaultModelContext.class,
50    CompactWikiStringEntityReferenceSerializer.class,
51    DefaultStringEntityReferenceSerializer.class,
52    CurrentEntityReferenceProvider.class,
53    DefaultModelConfiguration.class,
54    DefaultSymbolScheme.class
55    })
 
56    public class DefaultRenderingCacheConfigurationTest
57    {
58    @Rule
59    public MockitoOldcoreRule oldcore = new MockitoOldcoreRule();
60   
61    private RenderingCacheConfiguration configuration;
62   
63    private MockConfigurationSource xwikipropertiesConfiguration;
64   
65    private MockConfigurationSource wikiConfiguration;
66   
67    private DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
68   
 
69  9 toggle @Before
70    public void before() throws Exception
71    {
72  9 this.oldcore.getXWikiContext().setWikiId("wiki");
73   
74  9 this.oldcore.getMocker().registerComponent(MockConfigurationSource.getDescriptor("xwikiproperties"));
75  9 this.oldcore.getMocker().registerComponent(MockConfigurationSource.getDescriptor("wiki"));
76   
77  9 this.xwikipropertiesConfiguration =
78    this.oldcore.getMocker().getInstance(ConfigurationSource.class, "xwikiproperties");
79  9 this.wikiConfiguration = this.oldcore.getMocker().getInstance(ConfigurationSource.class, "wiki");
80   
81  9 this.configuration = this.oldcore.getMocker().getInstance(RenderingCacheConfiguration.class);
82    }
83   
 
84  1 toggle @Test
85    public void testIsCachedWithNoConfiguration() throws Exception
86    {
87  1 Assert.assertFalse(this.configuration.isCached(this.documentReference));
88    }
89   
 
90  1 toggle @Test
91    public void testIsCachedWhenDisabled() throws Exception
92    {
93  1 this.xwikipropertiesConfiguration.setProperty("core.renderingcache.enabled", false);
94   
95  1 Assert.assertFalse(this.configuration.isCached(this.documentReference));
96    }
97   
 
98  1 toggle @Test
99    public void testIsCachedWhenDisabledWithNoConfiguration() throws Exception
100    {
101  1 this.xwikipropertiesConfiguration.setProperty("core.renderingcache.enabled", true);
102   
103  1 Assert.assertFalse(this.configuration.isCached(this.documentReference));
104    }
105   
 
106  1 toggle @Test
107    public void testIsCachedWithExactReference() throws Exception
108    {
109  1 this.xwikipropertiesConfiguration.setProperty("core.renderingcache.enabled", true);
110  1 this.xwikipropertiesConfiguration.setProperty("core.renderingcache.documents",
111    Collections.singletonList("wiki:space.page"));
112   
113  1 Assert.assertTrue(this.configuration.isCached(this.documentReference));
114    }
115   
 
116  1 toggle @Test
117    public void testIsCachedWithWrongReference() throws Exception
118    {
119  1 this.xwikipropertiesConfiguration.setProperty("core.renderingcache.enabled", true);
120  1 this.xwikipropertiesConfiguration.setProperty("core.renderingcache.documents",
121    Collections.singletonList("wrongreference"));
122   
123  1 Assert.assertFalse(this.configuration.isCached(this.documentReference));
124    }
125   
 
126  1 toggle @Test
127    public void testIsCachedWithOnePattern() throws Exception
128    {
129  1 this.xwikipropertiesConfiguration.setProperty("core.renderingcache.enabled", true);
130  1 this.xwikipropertiesConfiguration.setProperty("core.renderingcache.documents",
131    Collections.singletonList("wiki:space.*"));
132   
133  1 Assert.assertTrue(this.configuration.isCached(this.documentReference));
134    }
135   
 
136  1 toggle @Test
137    public void testIsCachedWithSeveralPattern() throws Exception
138    {
139  1 this.xwikipropertiesConfiguration.setProperty("core.renderingcache.enabled", true);
140  1 this.xwikipropertiesConfiguration.setProperty("core.renderingcache.documents",
141    Arrays.asList("wrongreference", "wiki:space.*"));
142   
143  1 Assert.assertTrue(this.configuration.isCached(this.documentReference));
144    }
145   
 
146  1 toggle @Test
147    public void testIsCachedWithSeveralPattern2() throws Exception
148    {
149  1 this.xwikipropertiesConfiguration.setProperty("core.renderingcache.enabled", true);
150  1 this.xwikipropertiesConfiguration.setProperty("core.renderingcache.documents",
151    Arrays.asList("wiki:space.*", "wrongreference"));
152   
153  1 Assert.assertTrue(this.configuration.isCached(this.documentReference));
154    }
155   
 
156  1 toggle @Test
157    public void testIsCachedWithWikiConfiguration() throws Exception
158    {
159  1 this.xwikipropertiesConfiguration.setProperty("core.renderingcache.enabled", true);
160   
161  1 this.wikiConfiguration.setProperty("core.renderingcache.enabled", true);
162  1 this.wikiConfiguration.setProperty("core.renderingcache.documents",
163    Arrays.asList("wiki:space.*", "wrongreference"));
164   
165  1 Assert.assertTrue(this.configuration.isCached(this.documentReference));
166   
167  1 this.wikiConfiguration.setProperty("core.renderingcache.documents", Arrays.asList("space.*", "wrongreference"));
168   
169  1 Assert.assertTrue(this.configuration.isCached(this.documentReference));
170    }
171    }