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

File CopyAsJobTest.java

 

Code metrics

0
20
2
1
84
49
2
0.1
10
2
1

Classes

Class Line # Actions
CopyAsJobTest 44 20 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.refactoring.internal.job;
21   
22    import java.util.Arrays;
23    import java.util.Collections;
24    import java.util.Map;
25   
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.xwiki.job.Job;
29    import org.xwiki.model.reference.DocumentReference;
30    import org.xwiki.refactoring.internal.LinkRefactoring;
31    import org.xwiki.refactoring.job.CopyRequest;
32    import org.xwiki.test.mockito.MockitoComponentMockingRule;
33   
34    import static org.mockito.ArgumentMatchers.any;
35    import static org.mockito.Mockito.never;
36    import static org.mockito.Mockito.verify;
37    import static org.mockito.Mockito.when;
38   
39    /**
40    * Unit test for {@link CopyAsJob}.
41    *
42    * @version $Id: de6b8778d83c3b88c648756cef902bc9aa84e977 $
43    */
 
44    public class CopyAsJobTest extends AbstractEntityJobTest
45    {
46    @Rule
47    public MockitoComponentMockingRule<Job> mocker = new MockitoComponentMockingRule<Job>(CopyAsJob.class);
48   
 
49  6 toggle @Override
50    protected MockitoComponentMockingRule<Job> getMocker()
51    {
52  6 return this.mocker;
53    }
54   
 
55  1 toggle @Test
56    public void copyAsDocument() throws Throwable
57    {
58  1 DocumentReference sourceReference = new DocumentReference("wiki", "Space", "Page");
59  1 when(this.modelBridge.exists(sourceReference)).thenReturn(true);
60   
61  1 DocumentReference copyReference = new DocumentReference("wiki", "Copy", "Page");
62  1 when(this.modelBridge.copy(sourceReference, copyReference)).thenReturn(true);
63   
64  1 CopyRequest request = new CopyRequest();
65  1 request.setEntityReferences(Arrays.asList(sourceReference));
66  1 request.setDestination(copyReference);
67  1 request.setCheckRights(false);
68  1 request.setCheckAuthorRights(false);
69  1 request.setInteractive(false);
70  1 Map<String, String> parameters = Collections.singletonMap("foo", "bar");
71  1 request.setEntityParameters(sourceReference, parameters);
72  1 run(request);
73   
74  1 verify(this.modelBridge).copy(sourceReference, copyReference);
75   
76  1 LinkRefactoring linkRefactoring = getMocker().getInstance(LinkRefactoring.class);
77  1 verify(linkRefactoring, never()).renameLinks(any(DocumentReference.class), any(DocumentReference.class),
78    any(DocumentReference.class));
79  1 verify(linkRefactoring).updateRelativeLinks(sourceReference, copyReference);
80   
81  1 verify(this.modelBridge, never()).delete(any(DocumentReference.class));
82  1 verify(this.modelBridge, never()).createRedirect(any(DocumentReference.class), any(DocumentReference.class));
83    }
84    }