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

File CopyJobTest.java

 

Code metrics

0
31
4
1
109
71
4
0.13
7.75
4
1

Classes

Class Line # Actions
CopyJobTest 47 31 0% 4 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.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.EntityType;
30    import org.xwiki.model.reference.DocumentReference;
31    import org.xwiki.model.reference.EntityReference;
32    import org.xwiki.model.reference.SpaceReference;
33    import org.xwiki.refactoring.internal.LinkRefactoring;
34    import org.xwiki.refactoring.job.CopyRequest;
35    import org.xwiki.test.mockito.MockitoComponentMockingRule;
36   
37    import static org.mockito.ArgumentMatchers.any;
38    import static org.mockito.Mockito.never;
39    import static org.mockito.Mockito.verify;
40    import static org.mockito.Mockito.when;
41   
42    /**
43    * Unit test for {@link CopyJob}.
44    *
45    * @version $Id: c5e220b3d94b7560fbeb974e4bbafe442077ce60 $
46    */
 
47    public class CopyJobTest extends AbstractEntityJobTest
48    {
49    @Rule
50    public MockitoComponentMockingRule<Job> mocker = new MockitoComponentMockingRule<Job>(CopyJob.class);
51   
 
52  11 toggle @Override
53    protected MockitoComponentMockingRule<Job> getMocker()
54    {
55  11 return this.mocker;
56    }
57   
 
58  2 toggle private CopyRequest createRequest(EntityReference source, EntityReference destination)
59    {
60  2 CopyRequest request = new CopyRequest();
61  2 request.setEntityReferences(Arrays.asList(source));
62  2 request.setDestination(destination);
63  2 request.setCheckRights(false);
64  2 request.setCheckAuthorRights(false);
65  2 request.setInteractive(false);
66  2 return request;
67    }
68   
 
69  1 toggle @Test
70    public void copyDocumentThrowErrorInCaseOfDocuments() throws Throwable
71    {
72  1 DocumentReference sourceReference = new DocumentReference("wiki", "Space", "Page");
73  1 when(this.modelBridge.exists(sourceReference)).thenReturn(true);
74   
75  1 DocumentReference copyReference = new DocumentReference("wiki", "Copy", "Page");
76  1 when(this.modelBridge.copy(sourceReference, copyReference)).thenReturn(true);
77   
78  1 CopyRequest request = this.createRequest(sourceReference, copyReference);
79  1 run(request);
80  1 verify(this.mocker.getMockedLogger()).error("Unsupported destination entity type [{}] for a document.",
81    EntityType.DOCUMENT);
82    }
83   
 
84  1 toggle @Test
85    public void copyDocument() throws Throwable
86    {
87  1 DocumentReference sourceReference = new DocumentReference("wiki", "Space", "Foo");
88  1 when(this.modelBridge.exists(sourceReference)).thenReturn(true);
89   
90  1 SpaceReference copyReference = new SpaceReference("wiki", "Copy", "Page");
91  1 DocumentReference copyDestination = new DocumentReference("Foo", copyReference);
92  1 when(this.modelBridge.copy(sourceReference, copyDestination)).thenReturn(true);
93   
94  1 CopyRequest request = this.createRequest(sourceReference, copyReference);
95  1 Map<String, String> parameters = Collections.singletonMap("foo", "bar");
96  1 request.setEntityParameters(sourceReference, parameters);
97  1 run(request);
98  1 verify(this.modelBridge).copy(sourceReference, copyDestination);
99   
100  1 LinkRefactoring linkRefactoring = getMocker().getInstance(LinkRefactoring.class);
101  1 verify(linkRefactoring, never()).renameLinks(any(DocumentReference.class), any(DocumentReference.class),
102    any(DocumentReference.class));
103  1 verify(linkRefactoring).updateRelativeLinks(sourceReference, copyDestination);
104   
105  1 verify(this.modelBridge, never()).delete(any(DocumentReference.class));
106  1 verify(this.modelBridge, never()).createRedirect(any(DocumentReference.class), any(DocumentReference.class));
107  1 verify(this.mocker.getMockedLogger(), never()).error(any());
108    }
109    }