1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.wiki.internal.provisioning

File DefaultWikiProvisioningJobExecutorTest.java

 

Code metrics

0
23
3
1
110
65
3
0.13
7.67
3
1

Classes

Class Line # Actions
DefaultWikiProvisioningJobExecutorTest 53 23 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.wiki.internal.provisioning;
21   
22    import java.util.ArrayList;
23    import java.util.List;
24   
25    import javax.inject.Provider;
26   
27    import org.junit.Before;
28    import org.junit.Rule;
29    import org.junit.Test;
30    import org.xwiki.context.Execution;
31    import org.xwiki.context.ExecutionContextManager;
32    import org.xwiki.job.Job;
33    import org.xwiki.model.reference.DocumentReference;
34    import org.xwiki.test.mockito.MockitoComponentMockingRule;
35    import org.xwiki.wiki.provisioning.WikiProvisioningJob;
36    import org.xwiki.wiki.provisioning.WikiProvisioningJobRequest;
37   
38    import com.xpn.xwiki.XWikiContext;
39   
40    import static org.junit.Assert.assertEquals;
41    import static org.junit.Assert.assertNull;
42    import static org.mockito.ArgumentMatchers.eq;
43    import static org.mockito.Mockito.mock;
44    import static org.mockito.Mockito.verify;
45    import static org.mockito.Mockito.when;
46   
47    /**
48    * Unit tests for {@link org.xwiki.wiki.internal.provisioning.DefaultWikiProvisioningJobExecutor}.
49    *
50    * @version $Id: c4310aa697d9ddcd031618141d93ed0243d17762 $
51    * @since 6.0M1
52    */
 
53    public class DefaultWikiProvisioningJobExecutorTest
54    {
55    @Rule
56    public MockitoComponentMockingRule<DefaultWikiProvisioningJobExecutor> mocker =
57    new MockitoComponentMockingRule(DefaultWikiProvisioningJobExecutor.class);
58   
59    private Provider<XWikiContext> xcontextProvider;
60   
61    private XWikiContext xcontext;
62   
 
63  2 toggle @Before
64    public void setUp() throws Exception
65    {
66  2 xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
67  2 xcontext = mock(XWikiContext.class);
68  2 when(xcontextProvider.get()).thenReturn(xcontext);
69    }
70   
 
71  1 toggle @Test
72    public void createAndExecuteJob() throws Exception
73    {
74    // Mocks
75  1 WikiProvisioningJob provisioningJob = mock(WikiProvisioningJob.class);
76  1 mocker.registerComponent(Job.class, "wikiprovisioning.test", provisioningJob);
77  1 ExecutionContextManager executionContextManager = mock(ExecutionContextManager.class);
78  1 mocker.registerComponent(ExecutionContextManager.class, executionContextManager);
79  1 Execution execution = mock(Execution.class);
80  1 mocker.registerComponent(Execution.class, execution);
81  1 DocumentReference user = new DocumentReference("xwiki", "XWiki", "User");
82  1 when(xcontext.getUserReference()).thenReturn(user);
83   
84    // Execute
85  1 WikiProvisioningJob job = mocker.getComponentUnderTest().createAndExecuteJob("wikiid", "wikiprovisioning.test",
86    "templateid");
87   
88    // Verify
89    // Id of the job.
90  1 List<String> jobId = new ArrayList<String>();
91  1 jobId.add("wiki");
92  1 jobId.add("provisioning");
93  1 jobId.add("wikiprovisioning.test");
94  1 jobId.add("wikiid");
95  1 verify(provisioningJob).initialize(eq(new WikiProvisioningJobRequest(jobId, "wikiid", "templateid", user)));
96  1 Thread.sleep(100);
97  1 verify(provisioningJob).run();
98   
99    // getJobs also works
100  1 assertEquals(mocker.getComponentUnderTest().getJob(jobId), job);
101    }
102   
 
103  1 toggle @Test
104    public void getJobWhenNoJob() throws Exception
105    {
106  1 List<String> jobId = new ArrayList<String>();
107  1 assertNull(mocker.getComponentUnderTest().getJob(jobId));
108    }
109   
110    }