| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.wiki.template.internal; |
| 21 |
|
|
| 22 |
|
import javax.inject.Provider; |
| 23 |
|
|
| 24 |
|
import org.junit.Before; |
| 25 |
|
import org.junit.Rule; |
| 26 |
|
import org.junit.Test; |
| 27 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
| 28 |
|
import org.xwiki.wiki.internal.descriptor.document.WikiDescriptorDocumentHelper; |
| 29 |
|
import org.xwiki.wiki.manager.WikiManagerException; |
| 30 |
|
import org.xwiki.wiki.properties.WikiPropertyGroup; |
| 31 |
|
import org.xwiki.wiki.properties.WikiPropertyGroupException; |
| 32 |
|
import org.xwiki.wiki.properties.WikiPropertyGroupProvider; |
| 33 |
|
import org.xwiki.wiki.template.WikiTemplatePropertyGroup; |
| 34 |
|
|
| 35 |
|
import com.xpn.xwiki.XWiki; |
| 36 |
|
import com.xpn.xwiki.XWikiContext; |
| 37 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 38 |
|
import com.xpn.xwiki.objects.BaseObject; |
| 39 |
|
|
| 40 |
|
import static org.junit.Assert.assertEquals; |
| 41 |
|
import static org.junit.Assert.assertFalse; |
| 42 |
|
import static org.junit.Assert.assertTrue; |
| 43 |
|
import static org.mockito.ArgumentMatchers.eq; |
| 44 |
|
import static org.mockito.Mockito.mock; |
| 45 |
|
import static org.mockito.Mockito.when; |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
@link |
| 49 |
|
|
| 50 |
|
@since |
| 51 |
|
@version |
| 52 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (41) |
Complexity: 5 |
Complexity Density: 0.14 |
|
| 53 |
|
public class WikiTemplatePropertyGroupProviderTest |
| 54 |
|
{ |
| 55 |
|
@Rule |
| 56 |
|
public MockitoComponentMockingRule<WikiPropertyGroupProvider> mocker = |
| 57 |
|
new MockitoComponentMockingRule(WikiTemplatePropertyGroupProvider.class, WikiPropertyGroupProvider.class, |
| 58 |
|
"template"); |
| 59 |
|
|
| 60 |
|
private Provider<XWikiContext> xcontextProvider; |
| 61 |
|
|
| 62 |
|
private WikiDescriptorDocumentHelper wikiDescriptorDocumentHelper; |
| 63 |
|
|
| 64 |
|
private XWikiContext xcontext; |
| 65 |
|
|
| 66 |
|
private XWiki xwiki; |
| 67 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 68 |
3 |
@Before... |
| 69 |
|
public void setUp() throws Exception |
| 70 |
|
{ |
| 71 |
3 |
wikiDescriptorDocumentHelper = mocker.getInstance(WikiDescriptorDocumentHelper.class); |
| 72 |
3 |
xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER); |
| 73 |
3 |
xcontext = mock(XWikiContext.class); |
| 74 |
3 |
when(xcontextProvider.get()).thenReturn(xcontext); |
| 75 |
3 |
xwiki = mock(com.xpn.xwiki.XWiki.class); |
| 76 |
3 |
when(xcontext.getWiki()).thenReturn(xwiki); |
| 77 |
|
} |
| 78 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
| 79 |
1 |
@Test... |
| 80 |
|
public void get() throws Exception |
| 81 |
|
{ |
| 82 |
1 |
XWikiDocument descriptorDocument = mock(XWikiDocument.class); |
| 83 |
1 |
when(wikiDescriptorDocumentHelper.getDocumentFromWikiId("wikiId")).thenReturn(descriptorDocument); |
| 84 |
1 |
BaseObject object = mock(BaseObject.class); |
| 85 |
1 |
when(descriptorDocument.getXObject(eq(WikiTemplateClassDocumentInitializer.SERVER_CLASS))).thenReturn(object); |
| 86 |
1 |
when(object.getIntValue("iswikitemplate", 0)).thenReturn(1); |
| 87 |
|
|
| 88 |
|
|
| 89 |
1 |
WikiPropertyGroup result = mocker.getComponentUnderTest().get("wikiId"); |
| 90 |
|
|
| 91 |
|
|
| 92 |
1 |
assertEquals(true, result.get("isTemplate")); |
| 93 |
1 |
assertTrue(result instanceof WikiTemplatePropertyGroup); |
| 94 |
1 |
assertTrue(((WikiTemplatePropertyGroup)result).isTemplate()); |
| 95 |
|
|
| 96 |
1 |
XWikiDocument descriptorDocument2 = mock(XWikiDocument.class); |
| 97 |
1 |
when(wikiDescriptorDocumentHelper.getDocumentFromWikiId("wikiId2")).thenReturn(descriptorDocument2); |
| 98 |
1 |
BaseObject object2 = mock(BaseObject.class); |
| 99 |
1 |
when(descriptorDocument2.getXObject(eq(WikiTemplateClassDocumentInitializer.SERVER_CLASS))).thenReturn(object2); |
| 100 |
1 |
when(object2.getIntValue("iswikitemplate", 0)).thenReturn(0); |
| 101 |
|
|
| 102 |
|
|
| 103 |
1 |
WikiPropertyGroup result2 = mocker.getComponentUnderTest().get("wikiId2"); |
| 104 |
|
|
| 105 |
|
|
| 106 |
1 |
assertEquals(false, result2.get("isTemplate")); |
| 107 |
1 |
assertTrue(result2 instanceof WikiTemplatePropertyGroup); |
| 108 |
1 |
assertFalse(((WikiTemplatePropertyGroup) result2).isTemplate()); |
| 109 |
|
} |
| 110 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 111 |
1 |
@Test... |
| 112 |
|
public void getWhenNoObject() throws Exception |
| 113 |
|
{ |
| 114 |
1 |
XWikiDocument descriptorDocument = mock(XWikiDocument.class); |
| 115 |
1 |
when(wikiDescriptorDocumentHelper.getDocumentFromWikiId("wikiId")).thenReturn(descriptorDocument); |
| 116 |
|
|
| 117 |
|
|
| 118 |
1 |
WikiPropertyGroup result = mocker.getComponentUnderTest().get("wikiId"); |
| 119 |
|
|
| 120 |
|
|
| 121 |
1 |
assertEquals(false, result.get("isTemplate")); |
| 122 |
|
} |
| 123 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
1PASS
|
|
| 124 |
1 |
@Test... |
| 125 |
|
public void getWhenException() throws Exception |
| 126 |
|
{ |
| 127 |
1 |
WikiManagerException exception = new WikiManagerException("error in WikiManager"); |
| 128 |
1 |
when(wikiDescriptorDocumentHelper.getDocumentFromWikiId("wikiId")).thenThrow(exception); |
| 129 |
|
|
| 130 |
|
|
| 131 |
1 |
boolean exceptionCaught = false; |
| 132 |
1 |
try { |
| 133 |
1 |
mocker.getComponentUnderTest().get("wikiId"); |
| 134 |
|
} catch(WikiPropertyGroupException e) { |
| 135 |
1 |
exceptionCaught = true; |
| 136 |
1 |
assertEquals("Unable to load descriptor document for wiki [wikiId].", e.getMessage()); |
| 137 |
1 |
assertEquals(exception, e.getCause()); |
| 138 |
|
} |
| 139 |
|
|
| 140 |
1 |
assertTrue(exceptionCaught); |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
} |