use of org.xwiki.rest.model.jaxb.Object in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testGETObjectAtPageVersion.
@Test
public void testGETObjectAtPageVersion() throws Exception {
Object objectToBePut = createObjectIfDoesNotExists("XWiki.TagClass", this.spaces, this.pageName);
Map<String, String> versionToValueMap = new HashMap<String, String>();
for (int i = 0; i < 5; i++) {
String value = String.format("Value%d", i);
Property property = getProperty(objectToBePut, "tags");
property.setValue(value);
PutMethod putMethod = executePutXml(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, objectToBePut.getClassName(), objectToBePut.getNumber()).toString(), objectToBePut, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.getStatusCode());
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());
versionToValueMap.put(page.getVersion(), value);
}
for (String version : versionToValueMap.keySet()) {
GetMethod getMethod = executeGet(buildURI(ObjectAtPageVersionResource.class, getWiki(), this.spaces, this.pageName, version, objectToBePut.getClassName(), objectToBePut.getNumber()).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Object currentObject = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Property property = getProperty(currentObject, "tags");
Assert.assertEquals(versionToValueMap.get(version), property.getValue());
checkLinks(currentObject);
for (Property p : currentObject.getProperties()) {
checkLinks(p);
}
}
}
use of org.xwiki.rest.model.jaxb.Object in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testDELETEObjectUnAuthorized.
@Test
public void testDELETEObjectUnAuthorized() throws Exception {
Object objectToBeDeleted = createObjectIfDoesNotExists("XWiki.TagClass", this.spaces, this.pageName);
DeleteMethod deleteMethod = executeDelete(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, objectToBeDeleted.getClassName(), objectToBeDeleted.getNumber()).toString());
Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_UNAUTHORIZED, deleteMethod.getStatusCode());
GetMethod getMethod = executeGet(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, objectToBeDeleted.getClassName(), objectToBeDeleted.getNumber()).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
}
use of org.xwiki.rest.model.jaxb.Object in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testPUTObject.
@Test
public void testPUTObject() throws Exception {
final String TAG_VALUE = UUID.randomUUID().toString();
Object objectToBePut = createObjectIfDoesNotExists("XWiki.TagClass", this.spaces, this.pageName);
GetMethod getMethod = executeGet(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, objectToBePut.getClassName(), objectToBePut.getNumber()).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Object objectSummary = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
getProperty(objectSummary, "tags").setValue(TAG_VALUE);
PutMethod putMethod = executePutXml(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, objectToBePut.getClassName(), objectToBePut.getNumber()).toString(), objectSummary, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.getStatusCode());
Object updatedObjectSummary = (Object) unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());
Assert.assertEquals(TAG_VALUE, getProperty(updatedObjectSummary, "tags").getValue());
Assert.assertEquals(objectSummary.getClassName(), updatedObjectSummary.getClassName());
Assert.assertEquals(objectSummary.getNumber(), updatedObjectSummary.getNumber());
}
use of org.xwiki.rest.model.jaxb.Object in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testPUTPropertyWithTextPlain.
@Test
public void testPUTPropertyWithTextPlain() 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);
PutMethod putMethod = executePut(tagsPropertyLink.getHref(), TAG_VALUE, MediaType.TEXT_PLAIN, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.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());
}
use of org.xwiki.rest.model.jaxb.Object in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testRepresentation.
@Override
@Test
public void testRepresentation() throws Exception {
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());
for (ObjectSummary objectSummary : objects.getObjectSummaries()) {
link = getFirstLinkByRelation(objectSummary, Relations.OBJECT);
getMethod = executeGet(link.getHref());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Object object = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
checkLinks(objectSummary);
for (Property property : object.getProperties()) {
checkLinks(property);
}
}
}
Aggregations