1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.platform.wiki.creationjob.internal

File DefaultWikiCreatorTest.java

 

Code metrics

0
25
4
1
116
69
5
0.2
6.25
4
1.25

Classes

Class Line # Actions
DefaultWikiCreatorTest 44 25 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 3 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.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 $Id: 73166669dab59b14bf04a927e7a99fa709ca3d45 $
43    */
 
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   
 
54  3 toggle @Before
55    public void setUp() throws Exception
56    {
57  3 jobExecutor = mocker.getInstance(JobExecutor.class);
58  3 jobStatusStore = mocker.getInstance(JobStatusStore.class);
59    }
60   
 
61  1 toggle @Test
62    public void createWiki() throws Exception
63    {
64  1 WikiCreationRequest request = new WikiCreationRequest();
65  1 request.setWikiId("wikiId");
66   
67    // Mock
68  1 Job job = mock(Job.class);
69  1 when(jobExecutor.execute("wikicreationjob", request)).thenReturn(job);
70   
71    // Test
72  1 assertEquals(job, mocker.getComponentUnderTest().createWiki(request));
73   
74    // Verify
75  1 assertEquals(Arrays.asList("wikicreation", "createandinstall", "wikiId"), request.getId());
76    }
77   
 
78  1 toggle @Test
79    public void createWikiWithException() throws Exception
80    {
81  1 WikiCreationRequest request = new WikiCreationRequest();
82  1 request.setWikiId("wikiId");
83   
84    // Mock
85  1 JobException jobException = new JobException("Error in JobException");
86  1 when(jobExecutor.execute("wikicreationjob", request)).thenThrow(jobException);
87   
88    // Test
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    // Verify
97  1 assertNotNull(caughtException);
98    }
99   
 
100  1 toggle @Test
101    public void getJobStatus() throws Exception
102    {
103    // Mocks
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    // Tests
113  1 assertEquals(jobStatus1, mocker.getComponentUnderTest().getJobStatus("wiki1"));
114  1 assertEquals(jobStatus2, mocker.getComponentUnderTest().getJobStatus("wiki2"));
115    }
116    }