Search in sources :

Example 81 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class MoveJobTest method updateLinksOnFarm.

@Test
public void updateLinksOnFarm() throws Throwable {
    DocumentReference oldReference = new DocumentReference("foo", "One", "Page");
    when(this.modelBridge.exists(oldReference)).thenReturn(true);
    DocumentReference newReference = new DocumentReference("foo", "Two", "Page");
    when(this.modelBridge.exists(newReference)).thenReturn(false);
    when(this.modelBridge.copy(oldReference, newReference)).thenReturn(true);
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getAllIds()).thenReturn(Arrays.asList("foo", "bar"));
    DocumentReference aliceReference = new DocumentReference("foo", "Alice", "BackLink");
    when(this.modelBridge.getBackLinkedReferences(oldReference, "foo")).thenReturn(Arrays.asList(aliceReference));
    DocumentReference bobReference = new DocumentReference("bar", "Bob", "BackLink");
    when(this.modelBridge.getBackLinkedReferences(oldReference, "bar")).thenReturn(Arrays.asList(bobReference));
    MoveRequest request = createRequest(oldReference, newReference.getParent());
    request.setCheckRights(false);
    request.setInteractive(false);
    request.setUpdateLinksOnFarm(true);
    GroupedJob job = (GroupedJob) run(request);
    assertEquals(RefactoringJobs.GROUP, job.getGroupPath().toString());
    LinkRefactoring linkRefactoring = getMocker().getInstance(LinkRefactoring.class);
    verify(linkRefactoring).renameLinks(aliceReference, oldReference, newReference);
    verify(linkRefactoring).renameLinks(bobReference, oldReference, newReference);
}
Also used : GroupedJob(org.xwiki.job.GroupedJob) LinkRefactoring(org.xwiki.refactoring.internal.LinkRefactoring) MoveRequest(org.xwiki.refactoring.job.MoveRequest) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 82 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class MoveJobTest method moveMissingDocument.

@Test
public void moveMissingDocument() throws Throwable {
    DocumentReference sourceReference = new DocumentReference("foo", "A", "Page");
    run(createRequest(sourceReference, new SpaceReference("B", new WikiReference("bar"))));
    verify(this.mocker.getMockedLogger()).warn("Skipping [{}] because it doesn't exist.", sourceReference);
    verifyNoMove();
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 83 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class MoveJobTest method moveToUnsupportedDestination.

@Test
public void moveToUnsupportedDestination() throws Throwable {
    run(createRequest(new DocumentReference("wiki", "Space", "Page"), new WikiReference("test")));
    verify(this.mocker.getMockedLogger()).error("Unsupported destination entity type [{}] for a document.", EntityType.WIKI);
    run(createRequest(new DocumentReference("wiki", "Space", "Page"), new DocumentReference("test", "A", "B")));
    verify(this.mocker.getMockedLogger()).error("Unsupported destination entity type [{}] for a document.", EntityType.DOCUMENT);
    run(createRequest(new SpaceReference("Space", new WikiReference("wiki")), new DocumentReference("test", "A", "B")));
    verify(this.mocker.getMockedLogger()).error("Unsupported destination entity type [{}] for a space.", EntityType.DOCUMENT);
    verifyNoMove();
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 84 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class MoveJobTest method copyDocument.

@Test
public void copyDocument() throws Throwable {
    DocumentReference sourceReference = new DocumentReference("wiki", "Space", "Page");
    when(this.modelBridge.exists(sourceReference)).thenReturn(true);
    DocumentReference copyReference = new DocumentReference("wiki", "Copy", "Page");
    when(this.modelBridge.copy(sourceReference, copyReference)).thenReturn(true);
    MoveRequest request = createRequest(sourceReference, copyReference.getParent());
    request.setCheckRights(false);
    request.setInteractive(false);
    request.setDeleteSource(false);
    Map<String, String> parameters = Collections.singletonMap("foo", "bar");
    request.setEntityParameters(sourceReference, parameters);
    run(request);
    verify(this.modelBridge).update(copyReference, parameters);
    LinkRefactoring linkRefactoring = getMocker().getInstance(LinkRefactoring.class);
    verify(linkRefactoring, never()).renameLinks(any(DocumentReference.class), any(DocumentReference.class), any(DocumentReference.class));
    verify(linkRefactoring).updateRelativeLinks(sourceReference, copyReference);
    verify(this.modelBridge, never()).delete(any(DocumentReference.class));
    verify(this.modelBridge, never()).createRedirect(any(DocumentReference.class), any(DocumentReference.class));
}
Also used : LinkRefactoring(org.xwiki.refactoring.internal.LinkRefactoring) MoveRequest(org.xwiki.refactoring.job.MoveRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 85 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class MoveJobTest method moveSpaceToSpaceHome.

@Test
public void moveSpaceToSpaceHome() throws Throwable {
    SpaceReference sourceSpace = new SpaceReference("wiki", "A", "B");
    DocumentReference sourceDoc = new DocumentReference("X", sourceSpace);
    when(this.modelBridge.getDocumentReferences(sourceSpace)).thenReturn(Arrays.asList(sourceDoc));
    when(this.modelBridge.exists(sourceDoc)).thenReturn(true);
    DocumentReference destination = new DocumentReference("wiki", "C", "WebHome");
    MoveRequest request = createRequest(sourceSpace, destination);
    request.setCheckRights(false);
    run(request);
    verify(this.modelBridge).copy(sourceDoc, new DocumentReference("wiki", Arrays.asList("C", "B"), "X"));
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

DocumentReference (org.xwiki.model.reference.DocumentReference)1324 Test (org.junit.Test)711 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)482 BaseObject (com.xpn.xwiki.objects.BaseObject)250 XWikiContext (com.xpn.xwiki.XWikiContext)186 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)157 ArrayList (java.util.ArrayList)128 WikiReference (org.xwiki.model.reference.WikiReference)127 XWikiException (com.xpn.xwiki.XWikiException)121 EntityReference (org.xwiki.model.reference.EntityReference)113 SpaceReference (org.xwiki.model.reference.SpaceReference)96 XWiki (com.xpn.xwiki.XWiki)82 HashMap (java.util.HashMap)54 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)52 Expectations (org.jmock.Expectations)50 Before (org.junit.Before)50 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)46 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)45 AttachmentReference (org.xwiki.model.reference.AttachmentReference)44 Date (java.util.Date)42