Search in sources :

Example 11 with SpaceReference

use of org.xwiki.model.reference.SpaceReference 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 12 with SpaceReference

use of org.xwiki.model.reference.SpaceReference 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)

Example 13 with SpaceReference

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

the class RefactoringScriptServiceTest method rename.

@Test
public void rename() throws Exception {
    SpaceReference spaceReference = new SpaceReference("Alice", new SpaceReference("Users", new WikiReference("dev")));
    getService().rename(spaceReference, "Bob");
    ArgumentCaptor<MoveRequest> request = ArgumentCaptor.forClass(MoveRequest.class);
    verify(this.jobExecutor).execute(eq(RefactoringJobs.RENAME), request.capture());
    assertEquals(RefactoringJobs.RENAME, request.getValue().getJobType());
    assertEquals(Arrays.asList(spaceReference), request.getValue().getEntityReferences());
    assertEquals(new SpaceReference("Bob", spaceReference.getParent()), request.getValue().getDestination());
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 14 with SpaceReference

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

the class CreateJobTest method createSpaceFromTemplate.

@Test
public void createSpaceFromTemplate() throws Throwable {
    SpaceReference newSpaceReference = new SpaceReference("wiki", "Space");
    SpaceReference templateSpaceReference = new SpaceReference("wiki", "Code", "Template");
    DocumentReference templateDocumentReference = new DocumentReference("Index", templateSpaceReference);
    when(this.modelBridge.getDocumentReferences(templateSpaceReference)).thenReturn(Arrays.asList(templateDocumentReference));
    when(this.modelBridge.exists(templateDocumentReference)).thenReturn(true);
    DocumentReference newDocumentReference = new DocumentReference("Index", newSpaceReference);
    when(this.modelBridge.exists(newDocumentReference)).thenReturn(false);
    DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
    CreateRequest request = createRequest(newSpaceReference, templateSpaceReference);
    request.setUserReference(userReference);
    request.setCheckRights(false);
    run(request);
    verify(this.modelBridge).setContextUserReference(userReference);
    verify(this.modelBridge).copy(templateDocumentReference, newDocumentReference);
    verify(this.modelBridge, never()).removeLock(any(DocumentReference.class));
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) CreateRequest(org.xwiki.refactoring.job.CreateRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 15 with SpaceReference

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

the class DeleteJobTest method deleteSpace.

@Test
public void deleteSpace() throws Throwable {
    SpaceReference spaceReference = new SpaceReference("Space", new WikiReference("wiki"));
    DocumentReference aliceReference = new DocumentReference("wiki", "Space", "Alice");
    DocumentReference bobReference = new DocumentReference("wiki", "Space", "Bob");
    when(this.modelBridge.getDocumentReferences(spaceReference)).thenReturn(Arrays.asList(aliceReference, bobReference));
    run(createRequest(spaceReference));
    // We only verify that the code tries to delete the documents.
    verify(this.mocker.getMockedLogger()).warn("Skipping [{}] because it doesn't exist.", aliceReference);
    verify(this.mocker.getMockedLogger()).warn("Skipping [{}] because it doesn't exist.", bobReference);
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

SpaceReference (org.xwiki.model.reference.SpaceReference)142 DocumentReference (org.xwiki.model.reference.DocumentReference)96 Test (org.junit.Test)83 WikiReference (org.xwiki.model.reference.WikiReference)58 EntityReference (org.xwiki.model.reference.EntityReference)24 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)21 ArrayList (java.util.ArrayList)11 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)11 XWikiException (com.xpn.xwiki.XWikiException)9 QueryRestrictionGroup (com.celements.search.lucene.query.QueryRestrictionGroup)8 Expectations (org.jmock.Expectations)8 XWikiContext (com.xpn.xwiki.XWikiContext)7 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)7 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)7 ComponentManager (org.xwiki.component.manager.ComponentManager)7 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)7 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)7 EntityReferenceResolver (org.xwiki.model.reference.EntityReferenceResolver)7 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)7 DocumentResourceReference (org.xwiki.rendering.listener.reference.DocumentResourceReference)7