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

File UIExtensionScriptServiceTest.java

 

Code metrics

0
26
2
1
101
65
2
0.08
13
2
1

Classes

Class Line # Actions
UIExtensionScriptServiceTest 45 26 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.script;
21   
22    import java.util.ArrayList;
23    import java.util.HashMap;
24    import java.util.List;
25   
26    import javax.inject.Provider;
27   
28    import org.junit.Before;
29    import org.junit.Rule;
30    import org.junit.Test;
31    import org.xwiki.component.manager.ComponentLookupException;
32    import org.xwiki.component.manager.ComponentManager;
33    import org.xwiki.component.util.DefaultParameterizedType;
34    import org.xwiki.script.service.ScriptService;
35    import org.xwiki.test.mockito.MockitoComponentMockingRule;
36    import org.xwiki.uiextension.UIExtension;
37    import org.xwiki.uiextension.UIExtensionFilter;
38    import org.xwiki.uiextension.UIExtensionManager;
39    import org.xwiki.uiextension.internal.WikiUIExtensionConstants;
40    import org.xwiki.uiextension.internal.filter.SortByIdFilter;
41    import static org.mockito.Mockito.*;
42   
43    import org.junit.Assert;
44   
 
45    public class UIExtensionScriptServiceTest implements WikiUIExtensionConstants
46    {
47    private ComponentManager contextComponentManager;
48   
49    private List<UIExtension> epExtensions = new ArrayList<UIExtension>();
50   
51    private UIExtensionManager uiExtensionManager;
52   
53    @Rule
54    public MockitoComponentMockingRule<ScriptService> componentManager =
55    new MockitoComponentMockingRule<ScriptService>(UIExtensionScriptService.class);
56   
 
57  1 toggle @Before
58    public void setUp() throws Exception
59    {
60  1 contextComponentManager = mock(ComponentManager.class);
61  1 Provider<ComponentManager> componentManagerProvider = componentManager.registerMockComponent(
62    new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
63  1 when(componentManagerProvider.get()).thenReturn(contextComponentManager);
64   
65  1 this.uiExtensionManager = componentManager.getInstance(UIExtensionManager.class);
66    }
67   
 
68  1 toggle @Test
69    public void verifyExtensionsAreSortedAlphabeticallyById() throws Exception
70    {
71    // The UIX are voluntarily added in a wrong order.
72  1 UIExtension uix3 = mock(UIExtension.class, "uix3");
73  1 when(uix3.getId()).thenReturn("id3");
74  1 when(uix3.getExtensionPointId()).thenReturn("epId");
75  1 epExtensions.add(uix3);
76   
77  1 UIExtension uix1 = mock(UIExtension.class, "uix1");
78  1 when(uix1.getId()).thenReturn("id1");
79  1 when(uix1.getExtensionPointId()).thenReturn("epId");
80  1 epExtensions.add(uix1);
81   
82  1 UIExtension uix2 = mock(UIExtension.class, "uix2");
83  1 when(uix2.getId()).thenReturn("id2");
84  1 when(uix2.getExtensionPointId()).thenReturn("epId");
85  1 epExtensions.add(uix2);
86   
87  1 when(contextComponentManager.getInstance(UIExtensionManager.class, "epId"))
88    .thenThrow(new ComponentLookupException("No specific manager for extension point epId"));
89  1 when(uiExtensionManager.get("epId")).thenReturn(epExtensions);
90  1 when(contextComponentManager.getInstance(UIExtensionFilter.class, "sortById")).thenReturn(new SortByIdFilter());
91   
92  1 HashMap<String, String> filters = new HashMap<String, String>();
93  1 filters.put("sortById", "");
94  1 UIExtensionScriptService service = (UIExtensionScriptService) componentManager.getComponentUnderTest();
95  1 List<UIExtension> extensions = service.getExtensions("epId", filters);
96   
97  1 Assert.assertEquals("id1", extensions.get(0).getId());
98  1 Assert.assertEquals("id2", extensions.get(1).getId());
99  1 Assert.assertEquals("id3", extensions.get(2).getId());
100    }
101    }