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

File DefaultModelConfigurationTest.java

 

Code metrics

0
19
3
1
84
52
3
0.16
6.33
3
1

Classes

Class Line # Actions
DefaultModelConfigurationTest 42 19 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.model.internal;
21   
22    import org.junit.Assert;
23    import org.junit.Before;
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.component.manager.ComponentLookupException;
27    import org.xwiki.configuration.internal.MemoryConfigurationSource;
28    import org.xwiki.model.EntityType;
29    import org.xwiki.model.ModelConfiguration;
30    import org.xwiki.model.internal.reference.DefaultStringEntityReferenceSerializer;
31    import org.xwiki.model.internal.reference.RelativeStringEntityReferenceResolver;
32    import org.xwiki.test.annotation.ComponentList;
33    import org.xwiki.test.mockito.MockitoComponentMockingRule;
34   
35    /**
36    * Unit tests for {@link DefaultModelConfiguration}.
37    *
38    * @version $Id: b90dc9d2f4b1b8c7bea436ee9a0d238c26ae6ce8 $
39    * @since 2.2M1
40    */
41    @ComponentList({RelativeStringEntityReferenceResolver.class, DefaultStringEntityReferenceSerializer.class})
 
42    public class DefaultModelConfigurationTest
43    {
44    @Rule
45    public final MockitoComponentMockingRule<ModelConfiguration> mocker =
46    new MockitoComponentMockingRule<ModelConfiguration>(DefaultModelConfiguration.class);
47   
48    private MemoryConfigurationSource configuration;
49   
 
50  2 toggle @Before
51    public void before() throws Exception
52    {
53  2 this.configuration = this.mocker.registerMemoryConfigurationSource();
54    }
55   
 
56  1 toggle @Test
57    public void testGetDefaultReferenceNameWhenDefinedInConfiguration() throws ComponentLookupException
58    {
59  1 this.configuration.setProperty("model.reference.default.wiki", "defaultWiki");
60  1 this.configuration.setProperty("model.reference.default.document", "defaultDocument");
61  1 this.configuration.setProperty("model.reference.default.space", "defaultSpace");
62  1 this.configuration.setProperty("model.reference.default.attachment", "defaultFilename");
63  1 this.configuration.setProperty("model.reference.default.object", "defaultObject");
64  1 this.configuration.setProperty("model.reference.default.object_property", "defaultProperty");
65   
66  1 Assert.assertEquals("defaultWiki", this.mocker.getComponentUnderTest().getDefaultReferenceValue(EntityType.WIKI));
67  1 Assert.assertEquals("defaultDocument", this.mocker.getComponentUnderTest().getDefaultReferenceValue(EntityType.DOCUMENT));
68  1 Assert.assertEquals("defaultSpace", this.mocker.getComponentUnderTest().getDefaultReferenceValue(EntityType.SPACE));
69  1 Assert.assertEquals("defaultFilename", this.mocker.getComponentUnderTest().getDefaultReferenceValue(EntityType.ATTACHMENT));
70  1 Assert.assertEquals("defaultObject", this.mocker.getComponentUnderTest().getDefaultReferenceValue(EntityType.OBJECT));
71  1 Assert.assertEquals("defaultProperty", this.mocker.getComponentUnderTest().getDefaultReferenceValue(EntityType.OBJECT_PROPERTY));
72    }
73   
 
74  1 toggle @Test
75    public void testGetDefaultReferenceNameWhenNotDefinedInConfiguration() throws ComponentLookupException
76    {
77  1 Assert.assertEquals("xwiki", this.mocker.getComponentUnderTest().getDefaultReferenceValue(EntityType.WIKI));
78  1 Assert.assertEquals("WebHome", this.mocker.getComponentUnderTest().getDefaultReferenceValue(EntityType.DOCUMENT));
79  1 Assert.assertEquals("Main", this.mocker.getComponentUnderTest().getDefaultReferenceValue(EntityType.SPACE));
80  1 Assert.assertEquals("filename", this.mocker.getComponentUnderTest().getDefaultReferenceValue(EntityType.ATTACHMENT));
81  1 Assert.assertEquals("object", mocker.getComponentUnderTest().getDefaultReferenceValue(EntityType.OBJECT));
82  1 Assert.assertEquals("property", mocker.getComponentUnderTest().getDefaultReferenceValue(EntityType.OBJECT_PROPERTY));
83    }
84    }