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

File WikiUIExtensionTest.java

 

Code metrics

0
17
2
1
132
85
2
0.12
8.5
2
1

Classes

Class Line # Actions
WikiUIExtensionTest 65 17 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.uiextension;
21   
22    import org.apache.commons.collections.MapUtils;
23    import org.junit.jupiter.api.BeforeEach;
24    import org.junit.jupiter.api.Test;
25    import org.xwiki.component.manager.ComponentLookupException;
26    import org.xwiki.component.manager.ComponentManager;
27    import org.xwiki.component.wiki.WikiComponentException;
28    import org.xwiki.component.wiki.WikiComponentScope;
29    import org.xwiki.component.wiki.internal.bridge.ContentParser;
30    import org.xwiki.job.JobException;
31    import org.xwiki.job.event.status.JobProgressManager;
32    import org.xwiki.model.reference.DocumentReference;
33    import org.xwiki.rendering.RenderingException;
34    import org.xwiki.rendering.async.AsyncContext;
35    import org.xwiki.rendering.async.internal.block.BlockAsyncRendererConfiguration;
36    import org.xwiki.rendering.async.internal.block.BlockAsyncRendererExecutor;
37    import org.xwiki.rendering.block.WordBlock;
38    import org.xwiki.rendering.block.XDOM;
39    import org.xwiki.rendering.syntax.Syntax;
40    import org.xwiki.rendering.transformation.RenderingContext;
41    import org.xwiki.rendering.util.ErrorBlockGenerator;
42    import org.xwiki.test.junit5.mockito.InjectComponentManager;
43    import org.xwiki.test.junit5.mockito.MockComponent;
44    import org.xwiki.uiextension.internal.WikiUIExtension;
45   
46    import com.xpn.xwiki.doc.XWikiDocument;
47    import com.xpn.xwiki.objects.BaseObject;
48    import com.xpn.xwiki.test.MockitoOldcore;
49    import com.xpn.xwiki.test.junit5.mockito.InjectMockitoOldcore;
50    import com.xpn.xwiki.test.junit5.mockito.OldcoreTest;
51    import com.xpn.xwiki.test.reference.ReferenceComponentList;
52   
53    import static org.junit.jupiter.api.Assertions.assertEquals;
54    import static org.mockito.ArgumentMatchers.any;
55    import static org.mockito.Mockito.when;
56   
57    /**
58    * Unit tests for {@link WikiUIExtension}.
59    *
60    * @version $Id: 88bd3aaff65bdf3cb74d71baed8f332784128501 $
61    * @since 4.2M3
62    */
63    @OldcoreTest
64    @ReferenceComponentList
 
65    public class WikiUIExtensionTest
66    {
67    private static final DocumentReference CLASS_REF = new DocumentReference("xwiki", "XWiki", "UIExtensionClass");
68   
69    private static final DocumentReference DOC_REF = new DocumentReference("xwiki", "XWiki", "MyUIExtension");
70   
71    private static final DocumentReference AUTHOR_REFERENCE = new DocumentReference("xwiki", "XWiki", "Admin");
72   
73    @MockComponent
74    private JobProgressManager jobProgressManager;
75   
76    @MockComponent
77    private ErrorBlockGenerator errorBlockGenerator;
78   
79    @MockComponent
80    private AsyncContext asyncContext;
81   
82    @MockComponent
83    private BlockAsyncRendererExecutor blockAsyncRendererExecutor;
84   
85    @MockComponent
86    private RenderingContext renderingContext;
87   
88    @MockComponent
89    private ContentParser contentParser;
90   
91    @InjectComponentManager
92    private ComponentManager componentManager;
93   
94    @InjectMockitoOldcore
95    private MockitoOldcore oldcore;
96   
97    private BaseObject baseObject;
98   
 
99  1 toggle @BeforeEach
100    public void setUp() throws Exception
101    {
102  1 XWikiDocument ownerDocument = new XWikiDocument(DOC_REF);
103  1 ownerDocument.setAuthorReference(AUTHOR_REFERENCE);
104   
105  1 this.baseObject = new BaseObject();
106  1 this.baseObject.setOwnerDocument(ownerDocument);
107  1 this.baseObject.setXClassReference(CLASS_REF);
108    }
109   
 
110  1 toggle @Test
111    public void createWikiUIExtension()
112    throws ComponentLookupException, WikiComponentException, JobException, RenderingException
113    {
114  1 when(this.contentParser.parse("", Syntax.XWIKI_2_1, DOC_REF)).thenReturn(XDOM.EMPTY);
115   
116  1 WikiUIExtension wikiUIX = new WikiUIExtension(this.baseObject, "roleHint", "id", "epId", this.componentManager);
117  1 wikiUIX.setScope(WikiComponentScope.WIKI);
118   
119  1 assertEquals("roleHint", wikiUIX.getRoleHint());
120  1 assertEquals("id", wikiUIX.getId());
121  1 assertEquals("epId", wikiUIX.getExtensionPointId());
122  1 assertEquals(AUTHOR_REFERENCE, wikiUIX.getAuthorReference());
123  1 assertEquals(UIExtension.class, wikiUIX.getRoleType());
124  1 assertEquals(WikiComponentScope.WIKI, wikiUIX.getScope());
125  1 assertEquals(MapUtils.EMPTY_MAP, wikiUIX.getParameters());
126   
127  1 when(this.blockAsyncRendererExecutor.execute(any(BlockAsyncRendererConfiguration.class)))
128    .thenReturn(new WordBlock(""));
129   
130  1 assertEquals(new WordBlock(""), wikiUIX.execute());
131    }
132    }