1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.refactoring.internal.job

File RenameJobTest.java

 

Code metrics

0
44
7
1
142
91
7
0.16
6.29
7
1

Classes

Class Line # Actions
RenameJobTest 40 44 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 6 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   
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.job.Job;
27    import org.xwiki.model.reference.DocumentReference;
28    import org.xwiki.model.reference.EntityReference;
29    import org.xwiki.model.reference.SpaceReference;
30    import org.xwiki.refactoring.job.MoveRequest;
31    import org.xwiki.test.mockito.MockitoComponentMockingRule;
32   
33    import static org.mockito.Mockito.*;
34   
35    /**
36    * Unit tests for {@link RenameJob}.
37    *
38    * @version $Id: b2c080c3ed061656de5ecc929c3116a9cf3fa296 $
39    */
 
40    public class RenameJobTest extends AbstractMoveJobTest
41    {
42    @Rule
43    public MockitoComponentMockingRule<Job> mocker = new MockitoComponentMockingRule<Job>(RenameJob.class);
44   
 
45  24 toggle @Override
46    protected MockitoComponentMockingRule<Job> getMocker()
47    {
48  24 return this.mocker;
49    }
50   
 
51  1 toggle @Test
52    public void renameMultipleEntities() throws Exception
53    {
54  1 DocumentReference blackReference = new DocumentReference("wiki", "Color", "Black");
55  1 DocumentReference whiteReference = new DocumentReference("wiki", "Color", "White");
56  1 DocumentReference orangeReference = new DocumentReference("wiki", "Color", "Orange");
57   
58  1 MoveRequest request = new MoveRequest();
59  1 request.setEntityReferences(Arrays.<EntityReference>asList(blackReference, whiteReference));
60  1 request.setDestination(orangeReference);
61  1 run(request);
62   
63  1 verifyNoMove();
64    }
65   
 
66  1 toggle @Test
67    public void changeEntityType() throws Exception
68    {
69  1 DocumentReference aliceReference = new DocumentReference("wiki", "Users", "Alice");
70  1 SpaceReference bobReference = new SpaceReference("wiki", "Bob");
71   
72  1 run(createRequest(aliceReference, bobReference));
73   
74  1 verifyNoMove();
75  1 verify(this.mocker.getMockedLogger()).error("You cannot change the entity type (from [{}] to [{}]).",
76    aliceReference.getType(), bobReference.getType());
77    }
78   
 
79  1 toggle @Test
80    public void convertNotTerminalDocumentToTerminalDocumentPreservingChildren() throws Exception
81    {
82  1 DocumentReference nonTerminalReference = new DocumentReference("wiki", "One", "WebHome");
83  1 DocumentReference terminalReference = new DocumentReference("wiki", "Zero", "One");
84   
85  1 MoveRequest request = createRequest(nonTerminalReference, terminalReference);
86  1 request.setDeep(true);
87  1 run(request);
88   
89  1 verifyNoMove();
90  1 verify(this.mocker.getMockedLogger()).error(
91    "You cannot transform a non-terminal document [{}] into a terminal document [{}]"
92    + " and preserve its child documents at the same time.", nonTerminalReference, terminalReference);
93    }
94   
 
95  1 toggle @Test
96    public void renameSpaceHomeDeep() throws Exception
97    {
98  1 DocumentReference aliceReference = new DocumentReference("wiki", "Alice", "WebHome");
99  1 DocumentReference bobReference = new DocumentReference("wiki", "Bob", "WebHome");
100   
101  1 MoveRequest request = createRequest(aliceReference, bobReference);
102  1 request.setDeep(true);
103  1 run(request);
104   
105    // We verify that job fetches the space children.
106  1 verify(this.modelBridge).getDocumentReferences(aliceReference.getLastSpaceReference());
107    }
108   
 
109  1 toggle @Test
110    public void renameSpace() throws Exception
111    {
112  1 SpaceReference aliceReference = new SpaceReference("wiki", "Alice");
113  1 SpaceReference bobReference = new SpaceReference("wiki", "Bob");
114   
115  1 run(createRequest(aliceReference, bobReference));
116   
117    // We verify that job fetches the space children.
118  1 verify(this.modelBridge).getDocumentReferences(aliceReference);
119    }
120   
 
121  1 toggle @Test
122    public void renameDocument() throws Exception
123    {
124  1 DocumentReference oldReference = new DocumentReference("wiki", "Space", "Old");
125  1 when(this.modelBridge.exists(oldReference)).thenReturn(true);
126   
127  1 DocumentReference newReference = new DocumentReference("wiki", "Space", "New");
128  1 DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
129   
130  1 when(this.modelBridge.copy(oldReference, newReference)).thenReturn(true);
131   
132  1 MoveRequest request = createRequest(oldReference, newReference);
133  1 request.setCheckRights(false);
134  1 request.setInteractive(false);
135  1 request.setUserReference(userReference);
136  1 run(request);
137   
138  1 verify(this.modelBridge).setContextUserReference(userReference);
139  1 verify(this.modelBridge).delete(oldReference);
140  1 verify(this.modelBridge).createRedirect(oldReference, newReference);
141    }
142    }