1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.extension.job.history.internal

File ReplayJobTest.java

 

Code metrics

0
35
3
1
117
73
3
0.09
11.67
3
1

Classes

Class Line # Actions
ReplayJobTest 49 35 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.extension.job.history.internal;
21   
22    import java.util.ArrayList;
23    import java.util.Arrays;
24    import java.util.List;
25   
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.xwiki.extension.job.ExtensionRequest;
29    import org.xwiki.extension.job.InstallRequest;
30    import org.xwiki.extension.job.UninstallRequest;
31    import org.xwiki.extension.job.history.ExtensionJobHistoryRecord;
32    import org.xwiki.extension.job.history.ReplayJobStatus;
33    import org.xwiki.extension.job.history.ReplayRequest;
34    import org.xwiki.extension.job.internal.AbstractExtensionJob;
35    import org.xwiki.job.GroupedJob;
36    import org.xwiki.job.Job;
37    import org.xwiki.job.JobGroupPath;
38    import org.xwiki.test.mockito.MockitoComponentMockingRule;
39   
40    import static org.junit.Assert.*;
41    import static org.mockito.Mockito.*;
42   
43    /**
44    * Unit tests for {@link ReplayJob}.
45    *
46    * @version $Id: 4463f3f5d95de18becc5e6d121af9e53e9d274e8 $
47    * @since 7.1RC1
48    */
 
49    public class ReplayJobTest
50    {
51    @Rule
52    public MockitoComponentMockingRule<Job> mocker = new MockitoComponentMockingRule<Job>(ReplayJob.class);
53   
 
54  1 toggle @Test
55    public void replay() throws Exception
56    {
57  1 InstallRequest installRequest = new InstallRequest();
58  1 ExtensionJobHistoryRecord installRecord =
59    new ExtensionJobHistoryRecord("install", installRequest, null, null, null);
60  1 Job installJob = this.mocker.registerMockComponent(Job.class, "install");
61   
62  1 UninstallRequest uninstallRequest = new UninstallRequest();
63  1 ExtensionJobHistoryRecord uninstallRecord =
64    new ExtensionJobHistoryRecord("uninstall", uninstallRequest, null, null, null);
65  1 Job uninstallJob = this.mocker.registerMockComponent(Job.class, "uninstall");
66   
67  1 ReplayRequest request = new ReplayRequest();
68  1 request.setRecords(Arrays.asList(installRecord, uninstallRecord));
69   
70  1 Job replayJob = this.mocker.getComponentUnderTest();
71  1 replayJob.initialize(request);
72  1 replayJob.run();
73   
74  1 verify(installJob).initialize(installRequest);
75  1 verify(installJob).run();
76   
77  1 verify(uninstallJob).initialize(uninstallRequest);
78  1 verify(uninstallJob).run();
79   
80  1 assertEquals(1, ((ReplayJobStatus) replayJob.getStatus()).getCurrentRecordNumber());
81    }
82   
 
83  1 toggle @Test
84    public void getGroupPath() throws Exception
85    {
86  1 InstallRequest installOnTech = new InstallRequest();
87  1 installOnTech.addNamespace("wiki:tech");
88   
89  1 InstallRequest installOnDesign = new InstallRequest();
90  1 installOnDesign.addNamespace("wiki:design");
91   
92  1 InstallRequest installGlobally = new InstallRequest();
93   
94  1 InstallRequest installOnTechAndDesign = new InstallRequest();
95  1 installOnTechAndDesign.addNamespace("wiki:tech");
96  1 installOnTechAndDesign.addNamespace("wiki:design");
97   
98  1 assertGroupPath(new JobGroupPath("wiki:tech", AbstractExtensionJob.ROOT_GROUP), installOnTech, installOnTech);
99  1 assertGroupPath(AbstractExtensionJob.ROOT_GROUP, installOnTech, installOnDesign);
100  1 assertGroupPath(AbstractExtensionJob.ROOT_GROUP, installOnTech, installGlobally);
101    }
102   
 
103  3 toggle private void assertGroupPath(JobGroupPath expected, ExtensionRequest... requests) throws Exception
104    {
105  3 List<ExtensionJobHistoryRecord> records = new ArrayList<>();
106  3 for (ExtensionRequest request : requests) {
107  6 records.add(new ExtensionJobHistoryRecord(null, request, null, null, null));
108    }
109   
110  3 ReplayRequest request = new ReplayRequest();
111  3 request.setRecords(records);
112   
113  3 Job replayJob = this.mocker.getComponentUnderTest();
114  3 replayJob.initialize(request);
115  3 assertEquals(expected, ((GroupedJob) replayJob).getGroupPath());
116    }
117    }