1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.internal.macro; |
21 |
|
|
22 |
|
import java.util.Set; |
23 |
|
|
24 |
|
import org.jmock.Expectations; |
25 |
|
import org.junit.Assert; |
26 |
|
import org.junit.Before; |
27 |
|
import org.junit.Test; |
28 |
|
import org.xwiki.rendering.internal.transformation.macro.DefaultMacroTransformationConfiguration; |
29 |
|
import org.xwiki.rendering.macro.Macro; |
30 |
|
import org.xwiki.rendering.macro.MacroCategoryManager; |
31 |
|
import org.xwiki.rendering.macro.MacroId; |
32 |
|
import org.xwiki.rendering.macro.descriptor.DefaultMacroDescriptor; |
33 |
|
import org.xwiki.rendering.syntax.Syntax; |
34 |
|
import org.xwiki.rendering.transformation.macro.MacroTransformationConfiguration; |
35 |
|
import org.xwiki.test.jmock.AbstractComponentTestCase; |
36 |
|
|
37 |
|
|
38 |
|
@link |
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (46) |
Complexity: 6 |
Complexity Density: 0.15 |
|
43 |
|
public class DefaultMacroCategoryManagerTest extends AbstractComponentTestCase |
44 |
|
{ |
45 |
|
private MacroCategoryManager macroCategoryManager; |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
47 |
3 |
@Override... |
48 |
|
@Before |
49 |
|
public void setUp() throws Exception |
50 |
|
{ |
51 |
3 |
super.setUp(); |
52 |
3 |
this.macroCategoryManager = getComponentManager().getInstance(MacroCategoryManager.class); |
53 |
|
} |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
55 |
1 |
@Test... |
56 |
|
public void testGetMacroCategories() throws Exception |
57 |
|
{ |
58 |
|
|
59 |
|
|
60 |
1 |
DefaultMacroTransformationConfiguration configuration = |
61 |
|
(DefaultMacroTransformationConfiguration) getComponentManager().getInstance( |
62 |
|
MacroTransformationConfiguration.class); |
63 |
1 |
configuration.addCategory(new MacroId("testcontentmacro"), "Content"); |
64 |
1 |
configuration.addCategory(new MacroId("testsimplemacro"), "Simple"); |
65 |
|
|
66 |
1 |
Set<String> macroCategories = this.macroCategoryManager.getMacroCategories(); |
67 |
|
|
68 |
|
|
69 |
1 |
Assert.assertTrue(macroCategories.contains("Test")); |
70 |
|
|
71 |
|
|
72 |
1 |
Assert.assertTrue(macroCategories.contains(null)); |
73 |
|
|
74 |
|
|
75 |
1 |
Assert.assertTrue(macroCategories.contains("Content")); |
76 |
1 |
Assert.assertTrue(macroCategories.contains("Simple")); |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
79 |
1 |
@Test... |
80 |
|
public void testGetMacroNamesForCategory() throws Exception |
81 |
|
{ |
82 |
|
|
83 |
1 |
final Macro testMacro1 = registerMockComponent(Macro.class, "mytestmacro1", "mock1"); |
84 |
1 |
final Macro testMacro2 = registerMockComponent(Macro.class, "mytestmacro2", "mock2"); |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
85 |
1 |
getMockery().checking(new Expectations(){{... |
86 |
1 |
allowing(testMacro1).getDescriptor(); |
87 |
1 |
will(returnValue(new DefaultMacroDescriptor(new MacroId("macro1"), "Test macro - 1"))); |
88 |
1 |
allowing(testMacro2).getDescriptor(); |
89 |
1 |
will(returnValue(new DefaultMacroDescriptor(new MacroId("macro2"), "Test macro - 2"))); |
90 |
|
}}); |
91 |
|
|
92 |
|
|
93 |
1 |
DefaultMacroTransformationConfiguration configuration = |
94 |
|
(DefaultMacroTransformationConfiguration) getComponentManager().getInstance( |
95 |
|
MacroTransformationConfiguration.class); |
96 |
1 |
configuration.addCategory(new MacroId("mytestmacro1"), "Cat1"); |
97 |
1 |
configuration.addCategory(new MacroId("mytestmacro2"), "Cat2"); |
98 |
|
|
99 |
|
|
100 |
1 |
Set<MacroId> macroIds = this.macroCategoryManager.getMacroIds("Cat1"); |
101 |
1 |
Assert.assertTrue(macroIds.contains(new MacroId("mytestmacro1"))); |
102 |
1 |
Assert.assertFalse(macroIds.contains(new MacroId("mytestmacro2"))); |
103 |
|
|
104 |
|
|
105 |
1 |
macroIds = this.macroCategoryManager.getMacroIds("Cat1", Syntax.JSPWIKI_1_0); |
106 |
1 |
Assert.assertTrue(macroIds.contains(new MacroId("mytestmacro1"))); |
107 |
|
|
108 |
|
|
109 |
1 |
getComponentManager().unregisterComponent(Macro.class, "mytestmacro1"); |
110 |
1 |
getComponentManager().unregisterComponent(Macro.class, "mytestmacro2"); |
111 |
|
} |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
113 |
1 |
@Test... |
114 |
|
public void testGetMacroIdsWithSyntaxSpecificMacros() throws Exception |
115 |
|
{ |
116 |
|
|
117 |
1 |
final Macro mockMacro = registerMockComponent(Macro.class, "mytestmacro/xwiki/2.0"); |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
118 |
1 |
getMockery().checking(new Expectations(){{... |
119 |
1 |
allowing(mockMacro).getDescriptor(); |
120 |
1 |
will(returnValue(new DefaultMacroDescriptor(new MacroId("test"), "Test macro"))); |
121 |
|
}}); |
122 |
|
|
123 |
|
|
124 |
1 |
DefaultMacroTransformationConfiguration configuration = |
125 |
|
(DefaultMacroTransformationConfiguration) getComponentManager().getInstance( |
126 |
|
MacroTransformationConfiguration.class); |
127 |
1 |
configuration.addCategory(new MacroId("mytestmacro", Syntax.XWIKI_2_0), "Test"); |
128 |
|
|
129 |
|
|
130 |
1 |
Set<MacroId> macroIds = this.macroCategoryManager.getMacroIds("Test"); |
131 |
1 |
Assert.assertTrue(macroIds.contains(new MacroId("mytestmacro", Syntax.XWIKI_2_0))); |
132 |
1 |
macroIds = this.macroCategoryManager.getMacroIds("Test", Syntax.XWIKI_2_0); |
133 |
1 |
Assert.assertTrue(macroIds.contains(new MacroId("mytestmacro", Syntax.XWIKI_2_0))); |
134 |
1 |
macroIds = this.macroCategoryManager.getMacroIds("Test", Syntax.JSPWIKI_1_0); |
135 |
1 |
Assert.assertFalse(macroIds.contains(new MacroId("mytestmacro"))); |
136 |
|
|
137 |
|
|
138 |
1 |
getComponentManager().unregisterComponent(Macro.class, "mytestmacro/xwiki/2.0"); |
139 |
|
} |
140 |
|
} |