Search in sources :

Example 6 with CreateRequest

use of org.xwiki.refactoring.job.CreateRequest in project xwiki-platform by xwiki.

the class CreateJobTest method createDocumentDeep.

@Test
public void createDocumentDeep() throws Throwable {
    DocumentReference spaceHomeReference = new DocumentReference("wiki", "Space", "WebHome");
    DocumentReference templateHomeReference = new DocumentReference("wiki", Arrays.asList("Code", "Template"), "WebHome");
    DocumentReference templateDocumentReference = new DocumentReference("Index", templateHomeReference.getLastSpaceReference());
    when(this.modelBridge.getDocumentReferences(templateHomeReference.getLastSpaceReference())).thenReturn(Arrays.asList(templateDocumentReference));
    when(this.modelBridge.exists(templateDocumentReference)).thenReturn(true);
    DocumentReference newDocumentReference = new DocumentReference("Index", spaceHomeReference.getLastSpaceReference());
    when(this.modelBridge.exists(newDocumentReference)).thenReturn(false);
    CreateRequest request = createRequest(spaceHomeReference, templateHomeReference);
    request.setCheckRights(false);
    request.setDeep(true);
    run(request);
    verify(this.modelBridge).copy(templateDocumentReference, newDocumentReference);
}
Also used : CreateRequest(org.xwiki.refactoring.job.CreateRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 7 with CreateRequest

use of org.xwiki.refactoring.job.CreateRequest in project xwiki-platform by xwiki.

the class CreateJobTest method skipDocumentCreation.

@Test
public void skipDocumentCreation() throws Throwable {
    DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
    CreateRequest request = createRequest(documentReference, null);
    request.setSkippedEntities(Arrays.<EntityReference>asList(documentReference));
    run(request);
    verifyNoCreate();
    verify(this.mocker.getMockedLogger()).debug("Skipping creation of document [{}], as specified in the request.", documentReference);
}
Also used : CreateRequest(org.xwiki.refactoring.job.CreateRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 8 with CreateRequest

use of org.xwiki.refactoring.job.CreateRequest in project xwiki-platform by xwiki.

the class CreateJobTest method createDocumentFromTemplate.

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

Example 9 with CreateRequest

use of org.xwiki.refactoring.job.CreateRequest in project xwiki-platform by xwiki.

the class CreateJobTest method createDocumentWithoutTemplate.

@Test
public void createDocumentWithoutTemplate() throws Throwable {
    DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
    when(this.modelBridge.exists(documentReference)).thenReturn(false);
    CreateRequest request = createRequest(documentReference, null);
    request.setCheckRights(false);
    run(request);
    verify(this.modelBridge).create(documentReference);
    verify(this.modelBridge).removeLock(documentReference);
    verify(this.modelBridge, never()).copy(any(DocumentReference.class), any(DocumentReference.class));
}
Also used : CreateRequest(org.xwiki.refactoring.job.CreateRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 10 with CreateRequest

use of org.xwiki.refactoring.job.CreateRequest in project xwiki-platform by xwiki.

the class CreateJobTest method createDocumentFromMissingTemplate.

@Test
public void createDocumentFromMissingTemplate() throws Throwable {
    DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
    when(this.modelBridge.exists(documentReference)).thenReturn(false);
    DocumentReference templateReference = new DocumentReference("wiki", "Code", "Template");
    when(this.modelBridge.exists(templateReference)).thenReturn(false);
    CreateRequest request = createRequest(documentReference, templateReference);
    request.setCheckRights(false);
    run(request);
    verifyNoCreate();
    verify(this.mocker.getMockedLogger()).error("Template document [{}] does not exist.", templateReference);
}
Also used : CreateRequest(org.xwiki.refactoring.job.CreateRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

CreateRequest (org.xwiki.refactoring.job.CreateRequest)13 Test (org.junit.Test)10 DocumentReference (org.xwiki.model.reference.DocumentReference)10 SpaceReference (org.xwiki.model.reference.SpaceReference)2 XWikiException (com.xpn.xwiki.XWikiException)1 Job (org.xwiki.job.Job)1 EntityReference (org.xwiki.model.reference.EntityReference)1 RefactoringScriptService (org.xwiki.refactoring.script.RefactoringScriptService)1 ScriptService (org.xwiki.script.service.ScriptService)1