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();
}
}
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);
}
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);
}
}
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);
}
}
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());
}
Aggregations