1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.wikimacro.internal

File DefaultWikiMacroFactoryTest.java

 

Code metrics

0
31
3
1
104
58
3
0.1
10.33
3
1

Classes

Class Line # Actions
DefaultWikiMacroFactoryTest 39 31 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

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.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    * Unit test for {@link DefaultWikiMacroFactory}.
35    *
36    * @since 2.0M3
37    * @version $Id: 50bd6b09f45727914ec805f576eebe6403712508 $
38    */
 
39    public class DefaultWikiMacroFactoryTest extends AbstractBridgedXWikiComponentTestCase
40    {
41    private XWikiDocument macroDefinitionDoc;
42   
43    private Mock mockXWiki;
44   
45    private WikiMacroFactory wikiMacroFactory;
46   
 
47  2 toggle @Override
48    protected void setUp() throws Exception
49    {
50  2 super.setUp();
51   
52  2 this.wikiMacroFactory = getComponentManager().getInstance(WikiMacroFactory.class);
53   
54    // Build the macro definition document.
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    // Setup the mock xwiki.
69  2 this.mockXWiki = mock(XWiki.class);
70  2 this.mockXWiki.stubs().method("getDocument").will(returnValue(macroDefinitionDoc));
71   
72    // Set this mock xwiki in context.
73  2 getContext().setWiki((XWiki) mockXWiki.proxy());
74    }
75   
 
76  1 toggle public void testCreateWikiMacro() throws Exception
77    {
78    // Build a wiki macro.
79  1 WikiMacro macro = this.wikiMacroFactory.createWikiMacro(new DocumentReference("xwiki", "Macros", "Test"));
80  1 assertNotNull(macro);
81   
82    // Check if the macro was built correctly.
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   
 
92  1 toggle public void testCreateWikiMacroWithoutName() throws Exception
93    {
94  1 BaseObject obj = macroDefinitionDoc.getObject("XWiki.WikiMacroClass");
95  1 obj.setStringValue("name", "");
96   
97    // Build a wiki macro.
98  1 WikiMacro macro = this.wikiMacroFactory.createWikiMacro(new DocumentReference("xwiki", "Macros", "Test"));
99  1 assertNotNull(macro);
100   
101    // Check if the macro was built correctly.
102  1 assertEquals("testmacro", macro.getDescriptor().getName());
103    }
104    }