Search in sources :

Example 1 with Objects

use of org.xwiki.rest.model.jaxb.Objects in project xwiki-platform by xwiki.

the class PanelsTest method testModifyPanel.

@Test
public void testModifyPanel() throws Exception {
    String panelContent = "Hey I'm here !";
    String modifiedPanelContent = "Hey I'm still here !";
    String id = "testpanel";
    // Create panel on node 0
    getUtil().switchExecutor(0);
    Page panelPage = getUtil().rest().page(PANEL_REFERENCE);
    panelPage.setObjects(new Objects());
    org.xwiki.rest.model.jaxb.Object panelObject = object(PanelClassDocumentInitializer.CLASS_REFERENCE_STRING);
    panelObject.getProperties().add(property("content", "(%id='" + id + "'%)" + panelContent));
    panelPage.getObjects().getObjectSummaries().add(panelObject);
    getUtil().rest().save(panelPage);
    // Add the panel to wiki right panels
    getUtil().setWikiPreference("rightPanels", "Test.SharedPanel");
    getUtil().gotoPage(HOME_REFERENCE);
    assertEquals(panelContent, getUtil().getDriver().findElement(By.id(id)).getText());
    // Display panel on node 1
    getUtil().switchExecutor(1);
    getUtil().gotoPage(HOME_REFERENCE);
    assertEquals(panelContent, getUtil().getDriver().findElement(By.id(id)).getText());
    // Modify panel on node 1
    panelObject = getUtil().rest().object(PANEL_REFERENCE, PanelClassDocumentInitializer.CLASS_REFERENCE_STRING);
    panelObject.getProperties().add(property("content", "(%id='" + id + "'%)" + modifiedPanelContent));
    getUtil().rest().update(panelObject);
    // Reload the page after modifying the panel
    getUtil().getDriver().navigate().refresh();
    assertEquals(modifiedPanelContent, getUtil().getDriver().findElement(By.id(id)).getText());
    // Verify panel rendering on node 0
    // Since it can take time for the Cluster to propagate the change, we need to wait and set up a timeout.
    getUtil().switchExecutor(0);
    getUtil().gotoPage(HOME_REFERENCE);
    long t1 = System.currentTimeMillis();
    long t2;
    String result;
    assertEquals(modifiedPanelContent, getUtil().getDriver().findElement(By.id(id)).getText());
    while (!(result = getUtil().getDriver().findElement(By.id(id)).getText()).equalsIgnoreCase(modifiedPanelContent)) {
        t2 = System.currentTimeMillis();
        if (t2 - t1 > 10000L) {
            Assert.fail("Content should have been [" + modifiedPanelContent + "] but was [" + result + "]");
        }
        Thread.sleep(100);
        getUtil().getDriver().navigate().refresh();
    }
}
Also used : Objects(org.xwiki.rest.model.jaxb.Objects) Page(org.xwiki.rest.model.jaxb.Page) Test(org.junit.Test) AbstractClusterHttpTest(org.xwiki.test.cluster.framework.AbstractClusterHttpTest)

Example 2 with Objects

use of org.xwiki.rest.model.jaxb.Objects in project xwiki-platform by xwiki.

the class RepositoryTestUtils method addExtension.

public void addExtension(RemoteExtension extension) throws Exception {
    // Delete any pre existing extension
    this.testUtils.rest().delete(getExtensionPageReference(extension));
    // Create Page
    Page extensionPage = this.testUtils.rest().page(getExtensionPageReference(extension));
    extensionPage.setObjects(new Objects());
    // Add extension object
    extensionPage.getObjects().getObjectSummaries().add(extensionObject(extension));
    // Add the ExtensionVersion object
    extensionPage.getObjects().getObjectSummaries().add(extensionVersionObject(extension));
    // Add the ExtensionDependency objects
    extensionPage.getObjects().getObjectSummaries().addAll(extensionDependencyObjects(extension));
    // Save the extension page
    this.testUtils.rest().save(extensionPage, TestUtils.STATUS_CREATED);
    // Attach the extension file
    attachFile(extension);
}
Also used : Objects(org.xwiki.rest.model.jaxb.Objects) Page(org.xwiki.rest.model.jaxb.Page) ObjectEditPage(org.xwiki.test.ui.po.editor.ObjectEditPage)

Example 3 with Objects

use of org.xwiki.rest.model.jaxb.Objects in project xwiki-platform by xwiki.

the class ObjectsForClassNameResourceImpl method getObjects.

@Override
public Objects getObjects(String wikiName, String spaceName, String pageName, String className, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
        Document doc = documentInfo.getDocument();
        Objects objects = objectFactory.createObjects();
        List<com.xpn.xwiki.objects.BaseObject> objectList = getBaseObjects(doc, className);
        RangeIterable<com.xpn.xwiki.objects.BaseObject> ri = new RangeIterable<com.xpn.xwiki.objects.BaseObject>(objectList, start, number);
        for (com.xpn.xwiki.objects.BaseObject object : ri) {
            // By deleting objects, some of them might become null, so we must check for this
            if (object != null) {
                objects.getObjectSummaries().add(DomainObjectFactory.createObjectSummary(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, object, false, Utils.getXWikiApi(componentManager), withPrettyNames));
            }
        }
        return objects;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) Objects(org.xwiki.rest.model.jaxb.Objects) XWikiException(com.xpn.xwiki.XWikiException)

Example 4 with Objects

use of org.xwiki.rest.model.jaxb.Objects in project xwiki-platform by xwiki.

the class AllObjectsForClassNameResourceImpl method getObjects.

@Override
public Objects getObjects(String wikiName, String className, Integer start, Integer number, String order, Boolean withPrettyNames) throws XWikiRestException {
    String database = Utils.getXWikiContext(componentManager).getWikiId();
    try {
        Objects objects = new Objects();
        Utils.getXWikiContext(componentManager).setWikiId(wikiName);
        String query = "select doc, obj from BaseObject as obj, XWikiDocument as doc where obj.name=doc.fullName and obj.className=:className";
        if ("date".equals(order)) {
            query += " order by doc.date desc";
        }
        List<Object> queryResult = null;
        queryResult = queryManager.createQuery(query, Query.XWQL).bindValue("className", className).setLimit(number).setOffset(start).execute();
        for (Object object : queryResult) {
            Object[] fields = (Object[]) object;
            XWikiDocument xwikiDocument = (XWikiDocument) fields[0];
            xwikiDocument.setDatabase(wikiName);
            Document doc = new Document(xwikiDocument, Utils.getXWikiContext(componentManager));
            BaseObject xwikiObject = (BaseObject) fields[1];
            ObjectSummary objectSummary = DomainObjectFactory.createObjectSummary(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, xwikiObject, false, Utils.getXWikiApi(componentManager), withPrettyNames);
            objects.getObjectSummaries().add(objectSummary);
        }
        return objects;
    } catch (Exception e) {
        throw new XWikiRestException(e);
    } finally {
        Utils.getXWikiContext(componentManager).setWikiId(database);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiRestException(org.xwiki.rest.XWikiRestException) Objects(org.xwiki.rest.model.jaxb.Objects) BaseObject(com.xpn.xwiki.objects.BaseObject) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ObjectSummary(org.xwiki.rest.model.jaxb.ObjectSummary) XWikiRestException(org.xwiki.rest.XWikiRestException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 5 with Objects

use of org.xwiki.rest.model.jaxb.Objects in project xwiki-platform by xwiki.

the class ObjectsResourceTest method testPUTPropertyFormUrlEncoded.

@Test
public void testPUTPropertyFormUrlEncoded() throws Exception {
    final String TAG_VALUE = UUID.randomUUID().toString();
    /* Make sure that an Object with the TagClass exists. */
    createObjectIfDoesNotExists("XWiki.TagClass", this.spaces, this.pageName);
    GetMethod getMethod = executeGet(buildURI(PageResource.class, getWiki(), this.spaces, this.pageName).toString());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Page page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Link link = getFirstLinkByRelation(page, Relations.OBJECTS);
    Assert.assertNotNull(link);
    getMethod = executeGet(link.getHref());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Objects objects = (Objects) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertFalse(objects.getObjectSummaries().isEmpty());
    Object currentObject = null;
    for (ObjectSummary objectSummary : objects.getObjectSummaries()) {
        if (objectSummary.getClassName().equals("XWiki.TagClass")) {
            link = getFirstLinkByRelation(objectSummary, Relations.OBJECT);
            Assert.assertNotNull(link);
            getMethod = executeGet(link.getHref());
            Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
            currentObject = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
            break;
        }
    }
    Assert.assertNotNull(currentObject);
    Property tagsProperty = getProperty(currentObject, "tags");
    Assert.assertNotNull(tagsProperty);
    Link tagsPropertyLink = getFirstLinkByRelation(tagsProperty, Relations.SELF);
    Assert.assertNotNull(tagsPropertyLink);
    NameValuePair[] nameValuePairs = new NameValuePair[1];
    nameValuePairs[0] = new NameValuePair("property#tags", TAG_VALUE);
    PostMethod postMethod = executePostForm(String.format("%s?method=PUT", tagsPropertyLink.getHref()), nameValuePairs, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
    Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_ACCEPTED, postMethod.getStatusCode());
    getMethod = executeGet(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, currentObject.getClassName(), currentObject.getNumber()).toString());
    Assert.assertEquals(HttpStatus.SC_OK, getMethod.getStatusCode());
    currentObject = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    tagsProperty = getProperty(currentObject, "tags");
    Assert.assertEquals(TAG_VALUE, tagsProperty.getValue());
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostMethod(org.apache.commons.httpclient.methods.PostMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Objects(org.xwiki.rest.model.jaxb.Objects) Page(org.xwiki.rest.model.jaxb.Page) Object(org.xwiki.rest.model.jaxb.Object) ObjectResource(org.xwiki.rest.resources.objects.ObjectResource) ObjectSummary(org.xwiki.rest.model.jaxb.ObjectSummary) Property(org.xwiki.rest.model.jaxb.Property) Link(org.xwiki.rest.model.jaxb.Link) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Aggregations

Objects (org.xwiki.rest.model.jaxb.Objects)13 Page (org.xwiki.rest.model.jaxb.Page)8 Test (org.junit.Test)6 Object (org.xwiki.rest.model.jaxb.Object)6 ObjectSummary (org.xwiki.rest.model.jaxb.ObjectSummary)6 GetMethod (org.apache.commons.httpclient.methods.GetMethod)5 Link (org.xwiki.rest.model.jaxb.Link)5 Document (com.xpn.xwiki.api.Document)4 XWikiRestException (org.xwiki.rest.XWikiRestException)4 Property (org.xwiki.rest.model.jaxb.Property)4 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)4 XWikiException (com.xpn.xwiki.XWikiException)3 RangeIterable (org.xwiki.rest.internal.RangeIterable)3 ObjectResource (org.xwiki.rest.resources.objects.ObjectResource)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 BaseObject (com.xpn.xwiki.objects.BaseObject)2 PostMethod (org.apache.commons.httpclient.methods.PostMethod)2 PutMethod (org.apache.commons.httpclient.methods.PutMethod)2 Random (java.util.Random)1 JAXBContext (javax.xml.bind.JAXBContext)1