1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 2 |
Complexity Density: 0.08 |
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
57 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
68 |
1 |
@Test... |
69 |
|
public void verifyExtensionsAreSortedAlphabeticallyById() throws Exception |
70 |
|
{ |
71 |
|
|
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 |
|
} |