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

File MoveJobTest.java

 

Code metrics

0
260
22
1
538
410
22
0.08
11.82
22
1

Classes

Class Line # Actions
MoveJobTest 63 260 0% 22 0
1.0100%
 

Contributing tests

This file is covered by 20 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.ArrayList;
23    import java.util.Arrays;
24    import java.util.Collections;
25    import java.util.List;
26    import java.util.Map;
27   
28    import org.junit.Rule;
29    import org.junit.Test;
30    import org.mockito.stubbing.Answer;
31    import org.xwiki.bridge.event.DocumentsDeletingEvent;
32    import org.xwiki.job.GroupedJob;
33    import org.xwiki.job.Job;
34    import org.xwiki.job.JobGroupPath;
35    import org.xwiki.model.EntityType;
36    import org.xwiki.model.reference.DocumentReference;
37    import org.xwiki.model.reference.EntityReference;
38    import org.xwiki.model.reference.SpaceReference;
39    import org.xwiki.model.reference.WikiReference;
40    import org.xwiki.observation.ObservationManager;
41    import org.xwiki.refactoring.internal.LinkRefactoring;
42    import org.xwiki.refactoring.internal.job.AbstractEntityJob.Visitor;
43    import org.xwiki.refactoring.job.MoveRequest;
44    import org.xwiki.refactoring.job.RefactoringJobs;
45    import org.xwiki.refactoring.job.question.EntitySelection;
46    import org.xwiki.security.authorization.Right;
47    import org.xwiki.test.mockito.MockitoComponentMockingRule;
48    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
49   
50    import static org.junit.Assert.assertEquals;
51    import static org.mockito.ArgumentMatchers.any;
52    import static org.mockito.ArgumentMatchers.eq;
53    import static org.mockito.Mockito.doAnswer;
54    import static org.mockito.Mockito.never;
55    import static org.mockito.Mockito.verify;
56    import static org.mockito.Mockito.when;
57   
58    /**
59    * Unit tests for {@link MoveJob}.
60    *
61    * @version $Id: 5de72b311aab016f38fd53f7605075519144b31d $
62    */
 
63    public class MoveJobTest extends AbstractMoveJobTest
64    {
65    @Rule
66    public MockitoComponentMockingRule<Job> mocker = new MockitoComponentMockingRule<Job>(MoveJob.class);
67   
 
68  105 toggle @Override
69    protected MockitoComponentMockingRule<Job> getMocker()
70    {
71  105 return this.mocker;
72    }
73   
 
74  1 toggle @Test
75    public void moveInsideItsOwnHierarchy() throws Throwable
76    {
77  1 SpaceReference spaceReference =
78    new SpaceReference("Entity", new SpaceReference("Model", new WikiReference("code")));
79   
80  1 run(createRequest(spaceReference.getParent(), spaceReference));
81  1 verify(this.mocker.getMockedLogger()).error("Cannot make [{}] a descendant of itself.",
82    spaceReference.getParent());
83   
84  1 verifyNoMove();
85    }
86   
 
87  1 toggle @Test
88    public void moveToTheSameLocation() throws Throwable
89    {
90  1 SpaceReference spaceReference =
91    new SpaceReference("Entity", new SpaceReference("Model", new WikiReference("code")));
92   
93  1 run(createRequest(spaceReference, spaceReference.getParent()));
94  1 verify(this.mocker.getMockedLogger()).error("Cannot move [{}] into [{}], it's already there.", spaceReference,
95    spaceReference.getParent());
96   
97  1 verifyNoMove();
98    }
99   
 
100  1 toggle @Test
101    public void moveUnsupportedEntity() throws Throwable
102    {
103  1 run(createRequest(new WikiReference("from"), new WikiReference("to")));
104  1 verify(this.mocker.getMockedLogger()).error("Unsupported source entity type [{}].", EntityType.WIKI);
105   
106  1 verifyNoMove();
107    }
108   
 
109  1 toggle @Test
110    public void moveToUnsupportedDestination() throws Throwable
111    {
112  1 run(createRequest(new DocumentReference("wiki", "Space", "Page"), new WikiReference("test")));
113  1 verify(this.mocker.getMockedLogger()).error("Unsupported destination entity type [{}] for a document.",
114    EntityType.WIKI);
115   
116  1 run(createRequest(new DocumentReference("wiki", "Space", "Page"), new DocumentReference("test", "A", "B")));
117  1 verify(this.mocker.getMockedLogger()).error("Unsupported destination entity type [{}] for a document.",
118    EntityType.DOCUMENT);
119   
120  1 run(createRequest(new SpaceReference("Space", new WikiReference("wiki")), new DocumentReference("test", "A",
121    "B")));
122  1 verify(this.mocker.getMockedLogger()).error("Unsupported destination entity type [{}] for a space.",
123    EntityType.DOCUMENT);
124   
125  1 verifyNoMove();
126    }
127   
 
128  1 toggle @Test
129    public void moveMissingDocument() throws Throwable
130    {
131  1 DocumentReference sourceReference = new DocumentReference("foo", "A", "Page");
132  1 run(createRequest(sourceReference, new SpaceReference("B", new WikiReference("bar"))));
133  1 verify(this.mocker.getMockedLogger()).warn("Skipping [{}] because it doesn't exist.", sourceReference);
134   
135  1 verifyNoMove();
136    }
137   
 
138  1 toggle @Test
139    public void moveDocumentWithoutDeleteRight() throws Throwable
140    {
141  1 DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
142  1 when(this.modelBridge.exists(documentReference)).thenReturn(true);
143   
144  1 DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
145  1 when(this.authorization.hasAccess(Right.DELETE, userReference, documentReference)).thenReturn(false);
146   
147  1 DocumentReference authorReference = new DocumentReference("wiki", "Users", "Bob");
148  1 when(this.authorization.hasAccess(Right.DELETE, authorReference, documentReference)).thenReturn(true);
149   
150  1 MoveRequest request = createRequest(documentReference, new SpaceReference("Foo", new WikiReference("bar")));
151  1 request.setCheckRights(true);
152  1 request.setUserReference(userReference);
153  1 request.setCheckAuthorRights(true);
154  1 request.setAuthorReference(authorReference);
155  1 run(request);
156   
157  1 verify(this.mocker.getMockedLogger()).error("You are not allowed to delete [{}].", documentReference);
158   
159  1 verifyNoMove();
160    }
161   
 
162  1 toggle @Test
163    public void moveDocumentWithoutDeleteRightAuthor() throws Throwable
164    {
165  1 DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
166  1 when(this.modelBridge.exists(documentReference)).thenReturn(true);
167   
168  1 DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
169  1 when(this.authorization.hasAccess(Right.DELETE, userReference, documentReference)).thenReturn(true);
170   
171  1 DocumentReference authorReference = new DocumentReference("wiki", "Users", "Bob");
172  1 when(this.authorization.hasAccess(Right.DELETE, authorReference, documentReference)).thenReturn(false);
173   
174  1 MoveRequest request = createRequest(documentReference, new SpaceReference("Foo", new WikiReference("bar")));
175  1 request.setCheckRights(true);
176  1 request.setUserReference(userReference);
177  1 request.setCheckAuthorRights(true);
178  1 request.setAuthorReference(authorReference);
179  1 run(request);
180   
181  1 verify(this.mocker.getMockedLogger()).error("You are not allowed to delete [{}].", documentReference);
182   
183  1 verifyNoMove();
184    }
185   
 
186  1 toggle @Test
187    public void moveDocumentToRestrictedDestination() throws Throwable
188    {
189  1 DocumentReference oldReference = new DocumentReference("wiki", "One", "Page");
190  1 DocumentReference newReference = new DocumentReference("wiki", "Two", "Page");
191  1 when(this.modelBridge.exists(oldReference)).thenReturn(true);
192   
193  1 DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
194  1 when(this.authorization.hasAccess(Right.DELETE, userReference, oldReference)).thenReturn(true);
195  1 when(this.authorization.hasAccess(Right.VIEW, userReference, newReference)).thenReturn(false);
196  1 when(this.authorization.hasAccess(Right.VIEW, userReference, oldReference)).thenReturn(true);
197   
198  1 DocumentReference authorReference = new DocumentReference("wiki", "Users", "Bob");
199  1 when(this.authorization.hasAccess(Right.DELETE, authorReference, oldReference)).thenReturn(true);
200  1 when(this.authorization.hasAccess(Right.VIEW, authorReference, newReference)).thenReturn(true);
201  1 when(this.authorization.hasAccess(Right.VIEW, authorReference, oldReference)).thenReturn(true);
202   
203  1 MoveRequest request = createRequest(oldReference, newReference.getParent());
204  1 request.setCheckRights(true);
205  1 request.setCheckAuthorRights(true);
206  1 request.setUserReference(userReference);
207  1 request.setAuthorReference(authorReference);
208  1 run(request);
209   
210  1 verify(this.mocker.getMockedLogger()).error(
211    "You don't have sufficient permissions over the destination document [{}].", newReference);
212   
213  1 verifyNoMove();
214    }
215   
 
216  1 toggle @Test
217    public void moveDocumentToRestrictedDestinationAuthor() throws Throwable
218    {
219  1 DocumentReference oldReference = new DocumentReference("wiki", "One", "Page");
220  1 DocumentReference newReference = new DocumentReference("wiki", "Two", "Page");
221  1 when(this.modelBridge.exists(oldReference)).thenReturn(true);
222   
223  1 DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
224  1 when(this.authorization.hasAccess(Right.DELETE, userReference, oldReference)).thenReturn(true);
225  1 when(this.authorization.hasAccess(Right.VIEW, userReference, newReference)).thenReturn(true);
226  1 when(this.authorization.hasAccess(Right.VIEW, userReference, oldReference)).thenReturn(true);
227   
228  1 DocumentReference authorReference = new DocumentReference("wiki", "Users", "Bob");
229  1 when(this.authorization.hasAccess(Right.DELETE, authorReference, oldReference)).thenReturn(true);
230  1 when(this.authorization.hasAccess(Right.VIEW, authorReference, newReference)).thenReturn(false);
231  1 when(this.authorization.hasAccess(Right.VIEW, authorReference, oldReference)).thenReturn(true);
232   
233  1 MoveRequest request = createRequest(oldReference, newReference.getParent());
234  1 request.setCheckRights(true);
235  1 request.setCheckAuthorRights(true);
236  1 request.setUserReference(userReference);
237  1 request.setAuthorReference(authorReference);
238  1 run(request);
239   
240  1 verify(this.mocker.getMockedLogger()).error(
241    "You don't have sufficient permissions over the destination document [{}].", newReference);
242   
243  1 verifyNoMove();
244    }
245   
 
246  1 toggle @Test
247    public void moveDocumentFromRestrictedSource() throws Throwable
248    {
249  1 DocumentReference oldReference = new DocumentReference("wiki", "One", "Page");
250  1 DocumentReference newReference = new DocumentReference("wiki", "Two", "Page");
251  1 when(this.modelBridge.exists(oldReference)).thenReturn(true);
252   
253  1 DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
254  1 when(this.authorization.hasAccess(Right.DELETE, userReference, oldReference)).thenReturn(true);
255  1 when(this.authorization.hasAccess(Right.VIEW, userReference, newReference)).thenReturn(true);
256  1 when(this.authorization.hasAccess(Right.VIEW, userReference, oldReference)).thenReturn(false);
257   
258  1 DocumentReference authorReference = new DocumentReference("wiki", "Users", "Bob");
259  1 when(this.authorization.hasAccess(Right.DELETE, authorReference, oldReference)).thenReturn(true);
260  1 when(this.authorization.hasAccess(Right.VIEW, authorReference, newReference)).thenReturn(true);
261  1 when(this.authorization.hasAccess(Right.VIEW, authorReference, oldReference)).thenReturn(true);
262   
263  1 MoveRequest request = createRequest(oldReference, newReference.getParent());
264  1 request.setCheckRights(true);
265  1 request.setCheckAuthorRights(true);
266  1 request.setUserReference(userReference);
267  1 request.setAuthorReference(authorReference);
268  1 run(request);
269   
270  1 verify(this.mocker.getMockedLogger()).error(
271    "You don't have sufficient permissions over the source document [{}].", oldReference);
272   
273  1 verifyNoMove();
274    }
275   
 
276  1 toggle @Test
277    public void moveDocumentFromRestrictedSourceAuthor() throws Throwable
278    {
279  1 DocumentReference oldReference = new DocumentReference("wiki", "One", "Page");
280  1 DocumentReference newReference = new DocumentReference("wiki", "Two", "Page");
281  1 when(this.modelBridge.exists(oldReference)).thenReturn(true);
282   
283  1 DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
284  1 when(this.authorization.hasAccess(Right.DELETE, userReference, oldReference)).thenReturn(true);
285  1 when(this.authorization.hasAccess(Right.VIEW, userReference, newReference)).thenReturn(true);
286  1 when(this.authorization.hasAccess(Right.VIEW, userReference, oldReference)).thenReturn(true);
287   
288  1 DocumentReference authorReference = new DocumentReference("wiki", "Users", "Bob");
289  1 when(this.authorization.hasAccess(Right.DELETE, authorReference, oldReference)).thenReturn(true);
290  1 when(this.authorization.hasAccess(Right.VIEW, authorReference, newReference)).thenReturn(true);
291  1 when(this.authorization.hasAccess(Right.VIEW, authorReference, oldReference)).thenReturn(false);
292   
293  1 MoveRequest request = createRequest(oldReference, newReference.getParent());
294  1 request.setCheckRights(true);
295  1 request.setCheckAuthorRights(true);
296  1 request.setUserReference(userReference);
297  1 request.setAuthorReference(authorReference);
298  1 run(request);
299   
300  1 verify(this.mocker.getMockedLogger()).error(
301    "You don't have sufficient permissions over the source document [{}].", oldReference);
302   
303  1 verifyNoMove();
304    }
305   
 
306  1 toggle @Test
307    public void moveDocumentToSpace() throws Throwable
308    {
309  1 DocumentReference oldReference = new DocumentReference("wiki", "One", "Page");
310  1 when(this.modelBridge.exists(oldReference)).thenReturn(true);
311   
312  1 DocumentReference backLinkReference = new DocumentReference("wiki", "Three", "BackLink");
313  1 when(this.modelBridge.getBackLinkedReferences(oldReference, "wiki"))
314    .thenReturn(Arrays.asList(backLinkReference));
315   
316  1 DocumentReference newReference = new DocumentReference("wiki", "Two", "Page");
317  1 when(this.modelBridge.exists(newReference)).thenReturn(true);
318   
319  1 DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
320   
321  1 when(this.modelBridge.delete(newReference)).thenReturn(true);
322  1 when(this.modelBridge.copy(oldReference, newReference)).thenReturn(true);
323   
324  1 MoveRequest request = createRequest(oldReference, newReference.getParent());
325  1 request.setCheckRights(false);
326  1 request.setCheckAuthorRights(false);
327  1 request.setInteractive(false);
328  1 request.setUserReference(userReference);
329  1 run(request);
330   
331  1 LinkRefactoring linkRefactoring = getMocker().getInstance(LinkRefactoring.class);
332  1 verify(linkRefactoring).renameLinks(backLinkReference, oldReference, newReference);
333  1 verify(linkRefactoring).updateRelativeLinks(oldReference, newReference);
334   
335  1 verify(this.modelBridge).setContextUserReference(userReference);
336  1 verify(this.modelBridge).delete(oldReference);
337  1 verify(this.modelBridge).createRedirect(oldReference, newReference);
338  1 verify(this.modelBridge).updateParentField(oldReference, newReference);
339    }
340   
 
341  1 toggle @Test
342    public void updateLinksOnFarm() throws Throwable
343    {
344  1 DocumentReference oldReference = new DocumentReference("foo", "One", "Page");
345  1 when(this.modelBridge.exists(oldReference)).thenReturn(true);
346   
347  1 DocumentReference newReference = new DocumentReference("foo", "Two", "Page");
348  1 when(this.modelBridge.exists(newReference)).thenReturn(false);
349   
350  1 when(this.modelBridge.copy(oldReference, newReference)).thenReturn(true);
351   
352  1 WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
353  1 when(wikiDescriptorManager.getAllIds()).thenReturn(Arrays.asList("foo", "bar"));
354   
355  1 DocumentReference aliceReference = new DocumentReference("foo", "Alice", "BackLink");
356  1 when(this.modelBridge.getBackLinkedReferences(oldReference, "foo")).thenReturn(Arrays.asList(aliceReference));
357   
358  1 DocumentReference bobReference = new DocumentReference("bar", "Bob", "BackLink");
359  1 when(this.modelBridge.getBackLinkedReferences(oldReference, "bar")).thenReturn(Arrays.asList(bobReference));
360   
361  1 MoveRequest request = createRequest(oldReference, newReference.getParent());
362  1 request.setCheckRights(false);
363  1 request.setCheckAuthorRights(false);
364  1 request.setInteractive(false);
365  1 request.setUpdateLinksOnFarm(true);
366   
367  1 GroupedJob job = (GroupedJob) run(request);
368  1 assertEquals(RefactoringJobs.GROUP, job.getGroupPath().toString());
369   
370  1 LinkRefactoring linkRefactoring = getMocker().getInstance(LinkRefactoring.class);
371  1 verify(linkRefactoring).renameLinks(aliceReference, oldReference, newReference);
372  1 verify(linkRefactoring).renameLinks(bobReference, oldReference, newReference);
373    }
374   
 
375  1 toggle @Test
376    public void moveDocumentToSpaceHome() throws Throwable
377    {
378  1 DocumentReference source = new DocumentReference("wiki", "A", "B");
379  1 when(this.modelBridge.exists(source)).thenReturn(true);
380  1 DocumentReference destination = new DocumentReference("wiki", "C", "WebHome");
381   
382  1 when(this.modelBridge.copy(source, new DocumentReference("wiki", "C", "B"))).thenReturn(true);
383   
384  1 MoveRequest request = createRequest(source, destination);
385  1 request.setCheckRights(false);
386  1 request.setCheckAuthorRights(false);
387  1 request.setAutoRedirect(false);
388  1 request.setUpdateLinks(false);
389  1 run(request);
390   
391  1 verify(this.modelBridge).delete(source);
392  1 verify(this.modelBridge, never()).createRedirect(any(DocumentReference.class), any(DocumentReference.class));
393   
394  1 LinkRefactoring linkRefactoring = getMocker().getInstance(LinkRefactoring.class);
395  1 verify(linkRefactoring, never()).renameLinks(any(DocumentReference.class), any(DocumentReference.class),
396    any(DocumentReference.class));
397  1 verify(linkRefactoring, never()).updateRelativeLinks(any(DocumentReference.class),
398    any(DocumentReference.class));
399    }
400   
 
401  1 toggle @Test
402    public void moveSpaceHomeDeep() throws Throwable
403    {
404  1 DocumentReference spaceHome = new DocumentReference("chess", Arrays.asList("A", "B", "C"), "WebHome");
405  1 DocumentReference docFromSpace = new DocumentReference("X", spaceHome.getLastSpaceReference());
406  1 when(this.modelBridge.getDocumentReferences(spaceHome.getLastSpaceReference()))
407    .thenReturn(Arrays.asList(docFromSpace));
408  1 when(this.modelBridge.exists(docFromSpace)).thenReturn(true);
409   
410  1 WikiReference newWiki = new WikiReference("tennis");
411   
412  1 MoveRequest request = createRequest(spaceHome, newWiki);
413  1 request.setCheckRights(false);
414  1 request.setCheckAuthorRights(false);
415  1 request.setDeep(true);
416  1 run(request);
417   
418  1 verify(this.modelBridge).copy(docFromSpace, new DocumentReference("tennis", "C", "X"));
419   
420  1 ObservationManager observationManager = this.mocker.getInstance(ObservationManager.class);
421  1 verify(observationManager).notify(any(DocumentsDeletingEvent.class), any(MoveJob.class),
422    eq(Collections.singletonMap(docFromSpace, new EntitySelection(docFromSpace))));
423    }
424   
 
425  1 toggle @Test
426    public void moveSpaceToSpaceHome() throws Throwable
427    {
428  1 SpaceReference sourceSpace = new SpaceReference("wiki", "A", "B");
429  1 DocumentReference sourceDoc = new DocumentReference("X", sourceSpace);
430  1 when(this.modelBridge.getDocumentReferences(sourceSpace)).thenReturn(Arrays.asList(sourceDoc));
431  1 when(this.modelBridge.exists(sourceDoc)).thenReturn(true);
432   
433  1 DocumentReference destination = new DocumentReference("wiki", "C", "WebHome");
434   
435  1 MoveRequest request = createRequest(sourceSpace, destination);
436  1 request.setCheckRights(false);
437  1 request.setCheckAuthorRights(false);
438  1 run(request);
439   
440  1 verify(this.modelBridge).copy(sourceDoc, new DocumentReference("wiki", Arrays.asList("C", "B"), "X"));
441    }
442   
 
443  1 toggle @Test
444    public void getGroupPath() throws Exception
445    {
446  1 DocumentReference alice = new DocumentReference("chess", Arrays.asList("A", "B"), "C");
447  1 DocumentReference bob = new DocumentReference("chess", Arrays.asList("A", "B"), "D");
448  1 DocumentReference carol = new DocumentReference("chess", Arrays.asList("A", "E"), "F");
449   
450  1 MoveRequest request = new MoveRequest();
451  1 request.setEntityReferences(Arrays.asList(alice, bob));
452  1 request.setDestination(carol);
453   
454  1 GroupedJob job = (GroupedJob) getMocker().getComponentUnderTest();
455  1 job.initialize(request);
456   
457  1 assertEquals(new JobGroupPath(Arrays.asList("refactoring", "chess", "A")), job.getGroupPath());
458   
459  1 request.setUpdateLinksOnFarm(true);
460  1 job.initialize(request);
461   
462  1 assertEquals(new JobGroupPath(Arrays.asList("refactoring")), job.getGroupPath());
463    }
464   
 
465  1 toggle @Test
466    public void cancelMove() throws Throwable
467    {
468  1 DocumentReference sourceReference = new DocumentReference("wiki", Arrays.asList("Path", "To"), "Source");
469  1 when(this.modelBridge.exists(sourceReference)).thenReturn(true);
470  1 DocumentReference destinationReference = new DocumentReference("wiki", "Destination", "WebHome");
471  1 MoveRequest request = createRequest(sourceReference, destinationReference);
472  1 request.setCheckRights(false);
473   
474  1 ObservationManager observationManager = this.mocker.getInstance(ObservationManager.class);
475  1 doAnswer((Answer<Void>) invocation -> {
476  1 DocumentsDeletingEvent event = invocation.getArgument(0);
477  1 event.cancel();
478  1 return null;
479    }).when(observationManager).notify(any(DocumentsDeletingEvent.class), any(MoveJob.class), any(Map.class));
480   
481  1 run(request);
482   
483  1 verify(this.modelBridge, never()).copy(any(DocumentReference.class), any(DocumentReference.class));
484    }
485   
 
486  1 toggle @Test
487    public void checkEntitySelection() throws Throwable
488    {
489  1 DocumentReference sourceReference = new DocumentReference("wiki", Arrays.asList("Path", "To"), "Source");
490  1 when(this.modelBridge.exists(sourceReference)).thenReturn(true);
491  1 DocumentReference destinationReference = new DocumentReference("wiki", "Destination", "WebHome");
492  1 MoveRequest request = createRequest(sourceReference, destinationReference);
493  1 request.setCheckRights(false);
494   
495  1 ObservationManager observationManager = this.mocker.getInstance(ObservationManager.class);
496  1 doAnswer((Answer<Void>) invocation -> {
497  1 Map<EntityReference, EntitySelection> concernedEntities =
498    (Map<EntityReference, EntitySelection>) invocation.getArgument(2);
499  1 concernedEntities.get(sourceReference).setSelected(false);
500  1 return null;
501    }).when(observationManager).notify(any(DocumentsDeletingEvent.class), any(MoveJob.class), any(Map.class));
502   
503  1 run(request);
504   
505  1 verify(this.modelBridge, never()).copy(eq(sourceReference), any(DocumentReference.class));
506    }
507   
 
508  1 toggle @Test
509    public void visitDocuments() throws Exception
510    {
511  1 SpaceReference sourceReference = new SpaceReference("wiki", "Path", "To", "Space");
512  1 SpaceReference destinationReference = new SpaceReference("wiki", "Other", "Space");
513  1 SpaceReference nestedSpaceReference = new SpaceReference("WebPreferences", sourceReference);
514  1 DocumentReference one = new DocumentReference("WebPreference", nestedSpaceReference);
515  1 DocumentReference two = new DocumentReference("WebHome", nestedSpaceReference);
516  1 DocumentReference three = new DocumentReference("ZZZ", sourceReference);
517  1 DocumentReference four = new DocumentReference("WebPreferences", sourceReference);
518  1 DocumentReference five = new DocumentReference("AAA", sourceReference);
519  1 DocumentReference six = new DocumentReference("WebHome", sourceReference);
520  1 when(this.modelBridge.getDocumentReferences(sourceReference))
521    .thenReturn(Arrays.asList(one, two, three, four, five, six));
522   
523  1 MoveJob job = ((MoveJob) getMocker().getComponentUnderTest());
524  1 job.initialize(createRequest(sourceReference, destinationReference));
525   
526  1 List<DocumentReference> visitedPages = new ArrayList<>();
527  1 job.visitDocuments(sourceReference, new Visitor<DocumentReference>()
528    {
 
529  6 toggle @Override
530    public void visit(DocumentReference node)
531    {
532  6 visitedPages.add(node);
533    }
534    });
535   
536  1 assertEquals(Arrays.asList(five, six, two, one, three, four), visitedPages);
537    }
538    }