Search in sources :

Example 91 with DocumentReference

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

the class CreateJobTest method createExistingDocument.

@Test
public void createExistingDocument() throws Throwable {
    DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
    when(this.modelBridge.exists(documentReference)).thenReturn(true);
    run(createRequest(documentReference, null));
    verifyNoCreate();
    verify(this.mocker.getMockedLogger()).warn("Skipping creation of document [{}] because it already exists.", documentReference);
}
Also used : DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 92 with DocumentReference

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

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

the class DeleteJobTest method deleteDocument.

@Test
public void deleteDocument() throws Throwable {
    DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
    when(this.modelBridge.exists(documentReference)).thenReturn(true);
    DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
    EntityRequest request = createRequest(documentReference);
    request.setCheckRights(false);
    request.setUserReference(userReference);
    run(request);
    verify(this.modelBridge).setContextUserReference(userReference);
    verify(this.modelBridge).delete(documentReference);
}
Also used : EntityRequest(org.xwiki.refactoring.job.EntityRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 94 with DocumentReference

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

Example 95 with DocumentReference

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

the class EntityJobTest method processEachEntity.

@Test
public void processEachEntity() {
    final List<EntityReference> references = new ArrayList<>();
    NoopEntityJob job = new NoopEntityJob() {

        @Override
        protected void process(EntityReference entityReference) {
            references.add(entityReference);
        }
    };
    DocumentReference documentReference = new DocumentReference("chess", Arrays.asList("Path", "To"), "Success");
    EntityRequest request = new EntityRequest();
    request.setEntityReferences(documentReference.getReversedReferenceChain());
    initialize(job, request);
    job.run();
    assertEquals(request.getEntityReferences(), references);
}
Also used : EntityRequest(org.xwiki.refactoring.job.EntityRequest) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) 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