| 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; |
| 21 |
|
|
| 22 |
|
import java.util.Arrays; |
| 23 |
|
|
| 24 |
|
import org.junit.Before; |
| 25 |
|
import org.junit.Rule; |
| 26 |
|
import org.junit.Test; |
| 27 |
|
import org.xwiki.job.Job; |
| 28 |
|
import org.xwiki.job.JobException; |
| 29 |
|
import org.xwiki.job.JobExecutor; |
| 30 |
|
import org.xwiki.job.JobStatusStore; |
| 31 |
|
import org.xwiki.job.event.status.JobStatus; |
| 32 |
|
import org.xwiki.platform.wiki.creationjob.WikiCreationException; |
| 33 |
|
import org.xwiki.platform.wiki.creationjob.WikiCreationRequest; |
| 34 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
| 35 |
|
|
| 36 |
|
import static org.junit.Assert.assertEquals; |
| 37 |
|
import static org.junit.Assert.assertNotNull; |
| 38 |
|
import static org.mockito.Mockito.mock; |
| 39 |
|
import static org.mockito.Mockito.when; |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
@version |
| 43 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 5 |
Complexity Density: 0.2 |
|
| 44 |
|
public class DefaultWikiCreatorTest |
| 45 |
|
{ |
| 46 |
|
@Rule |
| 47 |
|
public MockitoComponentMockingRule<DefaultWikiCreator> mocker = |
| 48 |
|
new MockitoComponentMockingRule<>(DefaultWikiCreator.class); |
| 49 |
|
|
| 50 |
|
private JobExecutor jobExecutor; |
| 51 |
|
|
| 52 |
|
private JobStatusStore jobStatusStore; |
| 53 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 54 |
3 |
@Before... |
| 55 |
|
public void setUp() throws Exception |
| 56 |
|
{ |
| 57 |
3 |
jobExecutor = mocker.getInstance(JobExecutor.class); |
| 58 |
3 |
jobStatusStore = mocker.getInstance(JobStatusStore.class); |
| 59 |
|
} |
| 60 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
| 61 |
1 |
@Test... |
| 62 |
|
public void createWiki() throws Exception |
| 63 |
|
{ |
| 64 |
1 |
WikiCreationRequest request = new WikiCreationRequest(); |
| 65 |
1 |
request.setWikiId("wikiId"); |
| 66 |
|
|
| 67 |
|
|
| 68 |
1 |
Job job = mock(Job.class); |
| 69 |
1 |
when(jobExecutor.execute("wikicreationjob", request)).thenReturn(job); |
| 70 |
|
|
| 71 |
|
|
| 72 |
1 |
assertEquals(job, mocker.getComponentUnderTest().createWiki(request)); |
| 73 |
|
|
| 74 |
|
|
| 75 |
1 |
assertEquals(Arrays.asList("wikicreation", "createandinstall", "wikiId"), request.getId()); |
| 76 |
|
} |
| 77 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
1PASS
|
|
| 78 |
1 |
@Test... |
| 79 |
|
public void createWikiWithException() throws Exception |
| 80 |
|
{ |
| 81 |
1 |
WikiCreationRequest request = new WikiCreationRequest(); |
| 82 |
1 |
request.setWikiId("wikiId"); |
| 83 |
|
|
| 84 |
|
|
| 85 |
1 |
JobException jobException = new JobException("Error in JobException"); |
| 86 |
1 |
when(jobExecutor.execute("wikicreationjob", request)).thenThrow(jobException); |
| 87 |
|
|
| 88 |
|
|
| 89 |
1 |
WikiCreationException caughtException = null; |
| 90 |
1 |
try { |
| 91 |
1 |
mocker.getComponentUnderTest().createWiki(request); |
| 92 |
|
} catch (WikiCreationException e) { |
| 93 |
1 |
caughtException = e; |
| 94 |
|
} |
| 95 |
|
|
| 96 |
|
|
| 97 |
1 |
assertNotNull(caughtException); |
| 98 |
|
} |
| 99 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
| 100 |
1 |
@Test... |
| 101 |
|
public void getJobStatus() throws Exception |
| 102 |
|
{ |
| 103 |
|
|
| 104 |
1 |
Job job = mock(Job.class); |
| 105 |
1 |
JobStatus jobStatus1 = mock(JobStatus.class); |
| 106 |
1 |
when(job.getStatus()).thenReturn(jobStatus1); |
| 107 |
1 |
when(jobExecutor.getJob(Arrays.asList("wikicreation", "createandinstall", "wiki1"))).thenReturn(job); |
| 108 |
1 |
JobStatus jobStatus2 = mock(JobStatus.class); |
| 109 |
1 |
when(jobStatusStore.getJobStatus(Arrays.asList("wikicreation", "createandinstall", "wiki2"))). |
| 110 |
|
thenReturn(jobStatus2); |
| 111 |
|
|
| 112 |
|
|
| 113 |
1 |
assertEquals(jobStatus1, mocker.getComponentUnderTest().getJobStatus("wiki1")); |
| 114 |
1 |
assertEquals(jobStatus2, mocker.getComponentUnderTest().getJobStatus("wiki2")); |
| 115 |
|
} |
| 116 |
|
} |