Search in sources :

Example 21 with LocalDocumentReference

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

the class XarUtilsTest method getReference.

@Test
public void getReference() throws XarException {
    LocalDocumentReference documentReference = new LocalDocumentReference("space.nestedspace", "page", Locale.ENGLISH);
    LocalDocumentReference nestedDocumentReference = new LocalDocumentReference(new EntityReference("page", EntityType.DOCUMENT, new EntityReference("nestedspace", EntityType.SPACE, new EntityReference("space", EntityType.SPACE))), Locale.ENGLISH);
    assertEquals(nestedDocumentReference, XarUtils.getReference(getClass().getResourceAsStream("/document/document.xml")));
    assertEquals(nestedDocumentReference, XarUtils.getReference(getClass().getResourceAsStream("/document/newdocument.xml")));
    assertEquals(documentReference, XarUtils.getReference(getClass().getResourceAsStream("/document/legacydocument.xml")));
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Example 22 with LocalDocumentReference

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

the class CreatePageIT method createExistingPageAndSpace.

/**
 * Tests that creating a page or a space that already exists displays an error.
 */
@Test
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146")
public void createExistingPageAndSpace() throws Exception {
    // Step 0: Setup the correct environment for the test
    EntityReference existingPageReference = getUtil().resolveDocumentReference(getTestClassName() + ".ExistingPage.WebHome");
    String existingSpaceName = getTestClassName() + "Existing";
    // All these pages are created during this test
    getUtil().rest().delete(existingPageReference);
    getUtil().rest().deletePage(existingSpaceName, "WebHome");
    // create a template to make sure that we have a template to create from
    String templateProviderName = TEMPLATE_NAME + "Provider";
    String templateContent = "Templates are fun";
    String templateTitle = "Funny templates";
    createTemplateAndTemplateProvider(templateProviderName, templateContent, templateTitle, false);
    // create a page and a space webhome
    getUtil().rest().savePage(existingPageReference, "Page that already exists", "Existing page");
    getUtil().rest().savePage(new LocalDocumentReference(existingSpaceName, "WebHome"), "Some content", "Existing space");
    // Step 1: Create an empty page for a page that already exists
    // First we must click on create from a page that already exists as otherwise we won't get the create UI
    ViewPage vp = getUtil().gotoPage(existingPageReference);
    CreatePagePage createPage = vp.createPage();
    createPage.getDocumentPicker().toggleLocationAdvancedEdit();
    createPage.getDocumentPicker().setParent(getTestClassName());
    createPage.getDocumentPicker().setName("ExistingPage");
    String currentURL = getDriver().getCurrentUrl();
    createPage.clickCreate();
    // make sure that we stay on the same page and that an error is displayed to the user. Maybe we should check the
    // error
    assertEquals(currentURL, getDriver().getCurrentUrl());
    createPage.waitForErrorMessage();
    // Step 2: Create a page from Template for a page that already exists
    // restart everything to make sure it's not the error before
    vp = getUtil().gotoPage(existingPageReference);
    createPage = vp.createPage();
    createPage.getDocumentPicker().toggleLocationAdvancedEdit();
    createPage.getDocumentPicker().setParent(getTestClassName());
    createPage.getDocumentPicker().setName("ExistingPage");
    createPage.setTemplate(getTestClassName() + "." + templateProviderName);
    currentURL = getDriver().getCurrentUrl();
    createPage.clickCreate();
    // make sure that we stay on the same page and that an error is displayed to the user. Maybe we should check the
    // error
    assertEquals(currentURL, getDriver().getCurrentUrl());
    createPage.waitForErrorMessage();
    // Step 3: Create a space that already exists
    // Since the Flamingo skin no longer supports creating a space from the UI, trigger the Space creation UI
    // by using directly the direct action URL for it.
    getUtil().gotoPage(getUtil().getURL("create", new String[] { getTestClassName(), "ExistingPage", "WebHome" }, "tocreate=space"));
    CreatePagePage createSpace = new CreatePagePage();
    // Check that the terminal choice is not displayed in this mode.
    assertFalse(createSpace.isTerminalOptionDisplayed());
    currentURL = getDriver().getCurrentUrl();
    // strip the parameters out of this URL
    currentURL = currentURL.substring(0, currentURL.indexOf('?') > 0 ? currentURL.indexOf('?') : currentURL.length());
    // Try to create the a space (non-terminal document) that already exist.
    createSpace.getDocumentPicker().toggleLocationAdvancedEdit();
    createSpace.fillForm(existingSpaceName, "", null, false);
    createSpace.clickCreate();
    String urlAfterSubmit = getDriver().getCurrentUrl();
    urlAfterSubmit = urlAfterSubmit.substring(0, urlAfterSubmit.indexOf('?') > 0 ? urlAfterSubmit.indexOf('?') : urlAfterSubmit.length());
    // make sure that we stay on the same page and that an error is displayed to the user. Maybe we should check the
    // error
    assertEquals(currentURL, urlAfterSubmit);
    createSpace.waitForErrorMessage();
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) CreatePagePage(org.xwiki.test.ui.po.CreatePagePage) EntityReference(org.xwiki.model.reference.EntityReference) ViewPage(org.xwiki.test.ui.po.ViewPage) Test(org.junit.Test) AbstractTest(org.xwiki.test.ui.AbstractTest) IgnoreBrowser(org.xwiki.test.ui.browser.IgnoreBrowser)

Example 23 with LocalDocumentReference

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

the class IconThemeListenerTest method onEventWhenEmptyListObjects.

@Test
public void onEventWhenEmptyListObjects() throws Exception {
    // Mocks
    XWikiDocument doc = mock(XWikiDocument.class);
    List<BaseObject> list = new ArrayList<BaseObject>();
    LocalDocumentReference iconThemeClassRef = new LocalDocumentReference("IconThemesCode", "IconThemeClass");
    when(doc.getXObjects(eq(iconThemeClassRef))).thenReturn(list);
    // Tests
    mocker.getComponentUnderTest().onEvent(null, doc, null);
    // Verify
    verify(iconSetCache, never()).clear(any(DocumentReference.class));
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArrayList(java.util.ArrayList) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 24 with LocalDocumentReference

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

the class AbstractMandatoryDocumentInitializer method updateDocumentFields.

// Helpers
/**
 * Set the fields of the document passed as parameter. Can generate content for both XWiki Syntax 1.0 and XWiki
 * Syntax 2.0. If new documents are set to be created in XWiki Syntax 1.0 then generate XWiki 1.0 Syntax otherwise
 * generate XWiki Syntax 2.0.
 *
 * @param document the document
 * @param title the page title to set (if null or blank the title won't be set)
 * @return true if the document has been modified, false otherwise
 */
protected boolean updateDocumentFields(XWikiDocument document, String title) {
    boolean needsUpdate = false;
    if (document.getCreatorReference() == null) {
        document.setCreator(XWikiRightService.SUPERADMIN_USER);
        needsUpdate = true;
    }
    if (document.getAuthorReference() == null) {
        document.setAuthorReference(document.getCreatorReference());
        needsUpdate = true;
    }
    if (document.getParentReference() == null) {
        // Use the current document's space homepage and default document name.
        EntityReference spaceReference = getDocumentReference().extractReference(EntityType.SPACE);
        DocumentReference fullReference = this.resolver.resolve(null, spaceReference);
        EntityReference localReference = new LocalDocumentReference(fullReference);
        document.setParentReference(localReference);
        needsUpdate = true;
    }
    if (StringUtils.isNotEmpty(title) && StringUtils.isBlank(document.getTitle())) {
        document.setTitle(title);
        needsUpdate = true;
    }
    if (!document.isHidden()) {
        document.setHidden(true);
        needsUpdate = true;
    }
    return needsUpdate;
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) EntityReference(org.xwiki.model.reference.EntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference)

Example 25 with LocalDocumentReference

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

the class AbstractTestDocumentConfigurationSource method setStringProperty.

protected void setStringProperty(DocumentReference documentReference, String propertyName, String propertyValue) throws XWikiException {
    XWikiContext xcontext = this.oldcore.getXWikiContext();
    XWikiDocument document = this.oldcore.getXWikiContext().getWiki().getDocument(documentReference, xcontext);
    LocalDocumentReference classReference = getClassReference();
    BaseObject baseOject = document.getXObject(classReference);
    if (baseOject == null) {
        baseOject = new BaseObject();
        baseOject.setDocumentReference(documentReference);
        baseOject.setXClassReference(classReference);
        document.addXObject(baseOject);
    }
    baseOject.setStringValue(propertyName, propertyValue);
    xcontext.getWiki().saveDocument(document, xcontext);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)58 Test (org.junit.Test)28 DocumentReference (org.xwiki.model.reference.DocumentReference)25 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)23 BaseObject (com.xpn.xwiki.objects.BaseObject)19 XWikiContext (com.xpn.xwiki.XWikiContext)10 EntityReference (org.xwiki.model.reference.EntityReference)10 ArrayList (java.util.ArrayList)8 ViewPage (org.xwiki.test.ui.po.ViewPage)6 Page (org.xwiki.rest.model.jaxb.Page)5 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)4 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)4 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)4 Event (org.xwiki.observation.event.Event)4 XWiki (com.xpn.xwiki.XWiki)3 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)2 Principal (java.security.Principal)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2