1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.wikimacro.internal; |
21 |
|
|
22 |
|
import org.jmock.Mock; |
23 |
|
import org.xwiki.model.reference.DocumentReference; |
24 |
|
import org.xwiki.rendering.macro.wikibridge.WikiMacro; |
25 |
|
import org.xwiki.rendering.macro.wikibridge.WikiMacroDescriptor; |
26 |
|
import org.xwiki.rendering.macro.wikibridge.WikiMacroFactory; |
27 |
|
import com.xpn.xwiki.XWiki; |
28 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
29 |
|
import com.xpn.xwiki.objects.BaseObject; |
30 |
|
import com.xpn.xwiki.test.AbstractBridgedXWikiComponentTestCase; |
31 |
|
import org.xwiki.rendering.macro.wikibridge.WikiMacroVisibility; |
32 |
|
|
33 |
|
|
34 |
|
@link |
35 |
|
|
36 |
|
@since |
37 |
|
@version |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (34) |
Complexity: 3 |
Complexity Density: 0.1 |
|
39 |
|
public class DefaultWikiMacroFactoryTest extends AbstractBridgedXWikiComponentTestCase |
40 |
|
{ |
41 |
|
private XWikiDocument macroDefinitionDoc; |
42 |
|
|
43 |
|
private Mock mockXWiki; |
44 |
|
|
45 |
|
private WikiMacroFactory wikiMacroFactory; |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
|
47 |
2 |
@Override... |
48 |
|
protected void setUp() throws Exception |
49 |
|
{ |
50 |
2 |
super.setUp(); |
51 |
|
|
52 |
2 |
this.wikiMacroFactory = getComponentManager().getInstance(WikiMacroFactory.class); |
53 |
|
|
54 |
|
|
55 |
2 |
BaseObject obj = new BaseObject(); |
56 |
2 |
obj.setClassName("XWiki.WikiMacroClass"); |
57 |
2 |
obj.setStringValue("id", "testmacro"); |
58 |
2 |
obj.setStringValue("name", "Test Macro"); |
59 |
2 |
obj.setStringValue("description", "This is a macro used for testing purposes."); |
60 |
2 |
obj.setStringValue("defaultCategory", "Test"); |
61 |
2 |
obj.setStringValue("visibility", "Current User"); |
62 |
2 |
obj.setIntValue("supportsInlineMode", 1); |
63 |
2 |
obj.setStringValue("contentType", "No content"); |
64 |
2 |
obj.setStringValue("code", "==Hi=="); |
65 |
2 |
macroDefinitionDoc = new XWikiDocument(new DocumentReference("xwiki", "Macros", "Test")); |
66 |
2 |
macroDefinitionDoc.addObject("XWiki.WikiMacroClass", obj); |
67 |
|
|
68 |
|
|
69 |
2 |
this.mockXWiki = mock(XWiki.class); |
70 |
2 |
this.mockXWiki.stubs().method("getDocument").will(returnValue(macroDefinitionDoc)); |
71 |
|
|
72 |
|
|
73 |
2 |
getContext().setWiki((XWiki) mockXWiki.proxy()); |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
76 |
1 |
public void testCreateWikiMacro() throws Exception... |
77 |
|
{ |
78 |
|
|
79 |
1 |
WikiMacro macro = this.wikiMacroFactory.createWikiMacro(new DocumentReference("xwiki", "Macros", "Test")); |
80 |
1 |
assertNotNull(macro); |
81 |
|
|
82 |
|
|
83 |
1 |
assertEquals("testmacro", macro.getId()); |
84 |
1 |
assertEquals("Test Macro", macro.getDescriptor().getName()); |
85 |
1 |
assertEquals("This is a macro used for testing purposes.", macro.getDescriptor().getDescription()); |
86 |
1 |
assertEquals("Test", macro.getDescriptor().getDefaultCategory()); |
87 |
1 |
assertEquals(WikiMacroVisibility.USER, ((WikiMacroDescriptor) macro.getDescriptor()).getVisibility()); |
88 |
1 |
assertTrue(macro.supportsInlineMode()); |
89 |
1 |
assertNull(macro.getDescriptor().getContentDescriptor()); |
90 |
|
} |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
92 |
1 |
public void testCreateWikiMacroWithoutName() throws Exception... |
93 |
|
{ |
94 |
1 |
BaseObject obj = macroDefinitionDoc.getObject("XWiki.WikiMacroClass"); |
95 |
1 |
obj.setStringValue("name", ""); |
96 |
|
|
97 |
|
|
98 |
1 |
WikiMacro macro = this.wikiMacroFactory.createWikiMacro(new DocumentReference("xwiki", "Macros", "Test")); |
99 |
1 |
assertNotNull(macro); |
100 |
|
|
101 |
|
|
102 |
1 |
assertEquals("testmacro", macro.getDescriptor().getName()); |
103 |
|
} |
104 |
|
} |