| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.platform.wiki.creationjob.internal.steps; |
| 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.bridge.event.WikiCopiedEvent; |
| 28 |
|
import org.xwiki.bridge.event.WikiProvisionedEvent; |
| 29 |
|
import org.xwiki.bridge.event.WikiProvisioningEvent; |
| 30 |
|
import org.xwiki.bridge.event.WikiProvisioningFailedEvent; |
| 31 |
|
import org.xwiki.extension.ExtensionId; |
| 32 |
|
import org.xwiki.observation.ObservationManager; |
| 33 |
|
import org.xwiki.platform.wiki.creationjob.WikiCreationException; |
| 34 |
|
import org.xwiki.platform.wiki.creationjob.WikiCreationRequest; |
| 35 |
|
import org.xwiki.platform.wiki.creationjob.WikiSource; |
| 36 |
|
import org.xwiki.platform.wiki.creationjob.internal.ExtensionInstaller; |
| 37 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
| 38 |
|
import org.xwiki.wiki.provisioning.WikiCopier; |
| 39 |
|
|
| 40 |
|
import com.xpn.xwiki.XWikiContext; |
| 41 |
|
|
| 42 |
|
import static org.junit.Assert.assertEquals; |
| 43 |
|
import static org.junit.Assert.assertNotNull; |
| 44 |
|
import static org.mockito.ArgumentMatchers.eq; |
| 45 |
|
import static org.mockito.Mockito.doThrow; |
| 46 |
|
import static org.mockito.Mockito.mock; |
| 47 |
|
import static org.mockito.Mockito.verify; |
| 48 |
|
import static org.mockito.Mockito.verifyZeroInteractions; |
| 49 |
|
import static org.mockito.Mockito.when; |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
@version |
| 53 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (48) |
Complexity: 6 |
Complexity Density: 0.14 |
|
| 54 |
|
public class ProvisionWikiStepTest |
| 55 |
|
{ |
| 56 |
|
@Rule |
| 57 |
|
public MockitoComponentMockingRule<ProvisionWikiStep> mocker = |
| 58 |
|
new MockitoComponentMockingRule<>(ProvisionWikiStep.class); |
| 59 |
|
|
| 60 |
|
private WikiCopier wikiCopier; |
| 61 |
|
|
| 62 |
|
private ExtensionInstaller extensionInstaller; |
| 63 |
|
|
| 64 |
|
private ObservationManager observationManager; |
| 65 |
|
|
| 66 |
|
private Provider<XWikiContext> xcontextProvider; |
| 67 |
|
|
| 68 |
|
private XWikiContext xcontext; |
| 69 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 70 |
4 |
@Before... |
| 71 |
|
public void setUp() throws Exception |
| 72 |
|
{ |
| 73 |
4 |
wikiCopier = mocker.getInstance(WikiCopier.class); |
| 74 |
4 |
extensionInstaller = mocker.getInstance(ExtensionInstaller.class); |
| 75 |
4 |
observationManager = mocker.getInstance(ObservationManager.class); |
| 76 |
4 |
xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER); |
| 77 |
4 |
xcontext = mock(XWikiContext.class); |
| 78 |
4 |
when(xcontextProvider.get()).thenReturn(xcontext); |
| 79 |
|
} |
| 80 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
| 81 |
1 |
@Test... |
| 82 |
|
public void executeWhenSourceIsExtension() throws Exception |
| 83 |
|
{ |
| 84 |
1 |
WikiCreationRequest request = new WikiCreationRequest(); |
| 85 |
1 |
request.setWikiId("wikiId"); |
| 86 |
1 |
request.setWikiSource(WikiSource.EXTENSION); |
| 87 |
1 |
ExtensionId extensionId = new ExtensionId("id", "version"); |
| 88 |
1 |
request.setExtensionId(extensionId); |
| 89 |
|
|
| 90 |
|
|
| 91 |
1 |
mocker.getComponentUnderTest().execute(request); |
| 92 |
|
|
| 93 |
|
|
| 94 |
1 |
verify(extensionInstaller).installExtension(eq("wikiId"), eq(extensionId)); |
| 95 |
1 |
verify(observationManager).notify(eq(new WikiProvisioningEvent("wikiId")), eq("wikiId"), eq(xcontext)); |
| 96 |
1 |
verify(observationManager).notify(eq(new WikiProvisionedEvent("wikiId")), eq("wikiId"), eq(xcontext)); |
| 97 |
1 |
verifyZeroInteractions(wikiCopier); |
| 98 |
|
} |
| 99 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
| 100 |
1 |
@Test... |
| 101 |
|
public void executeWhenSourceIsTemplate() throws Exception |
| 102 |
|
{ |
| 103 |
1 |
WikiCreationRequest request = new WikiCreationRequest(); |
| 104 |
1 |
request.setWikiId("wikiId"); |
| 105 |
1 |
request.setWikiSource(WikiSource.TEMPLATE); |
| 106 |
1 |
request.setTemplateId("template"); |
| 107 |
|
|
| 108 |
|
|
| 109 |
1 |
mocker.getComponentUnderTest().execute(request); |
| 110 |
|
|
| 111 |
|
|
| 112 |
1 |
verify(wikiCopier).copyDocuments(eq("template"), eq("wikiId"), eq(false)); |
| 113 |
1 |
verify(observationManager).notify(eq(new WikiProvisioningEvent("wikiId")), eq("wikiId"), eq(xcontext)); |
| 114 |
1 |
verify(observationManager).notify(eq(new WikiCopiedEvent("template", "wikiId")), eq("template"), eq(xcontext)); |
| 115 |
1 |
verify(observationManager).notify(eq(new WikiProvisionedEvent("wikiId")), eq("wikiId"), eq(xcontext)); |
| 116 |
1 |
verifyZeroInteractions(extensionInstaller); |
| 117 |
|
} |
| 118 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 2 |
Complexity Density: 0.12 |
1PASS
|
|
| 119 |
1 |
@Test... |
| 120 |
|
public void executeWhenException() throws Exception |
| 121 |
|
{ |
| 122 |
1 |
WikiCreationRequest request = new WikiCreationRequest(); |
| 123 |
1 |
request.setWikiId("wikiId"); |
| 124 |
1 |
request.setWikiSource(WikiSource.EXTENSION); |
| 125 |
1 |
ExtensionId extensionId = new ExtensionId("id", "version"); |
| 126 |
1 |
request.setExtensionId(extensionId); |
| 127 |
|
|
| 128 |
|
|
| 129 |
1 |
WikiCreationException exception = new WikiCreationException("Exception in ExtensionInstaller"); |
| 130 |
1 |
doThrow(exception).when(extensionInstaller).installExtension("wikiId", extensionId); |
| 131 |
|
|
| 132 |
|
|
| 133 |
1 |
WikiCreationException caughtException = null; |
| 134 |
1 |
try { |
| 135 |
1 |
mocker.getComponentUnderTest().execute(request); |
| 136 |
|
} catch (WikiCreationException e) { |
| 137 |
1 |
caughtException = e; |
| 138 |
|
} |
| 139 |
|
|
| 140 |
|
|
| 141 |
1 |
assertNotNull(caughtException); |
| 142 |
1 |
assertEquals("Failed to provision the wiki [wikiId].", caughtException.getMessage()); |
| 143 |
1 |
assertEquals(exception, caughtException.getCause()); |
| 144 |
1 |
verify(observationManager).notify(eq(new WikiProvisioningEvent("wikiId")), eq("wikiId"), eq(xcontext)); |
| 145 |
1 |
verify(observationManager).notify(eq(new WikiProvisioningFailedEvent("wikiId")), eq("wikiId"), eq(xcontext)); |
| 146 |
|
} |
| 147 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 148 |
1 |
@Test... |
| 149 |
|
public void getOrder() throws Exception |
| 150 |
|
{ |
| 151 |
1 |
assertEquals(3000, mocker.getComponentUnderTest().getOrder()); |
| 152 |
|
} |
| 153 |
|
} |