use of org.xwiki.rest.model.jaxb.Property in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testPUTProperty.
@Test
public void testPUTProperty() 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);
Property newTags = objectFactory.createProperty();
newTags.setValue(TAG_VALUE);
PutMethod putMethod = executePutXml(tagsPropertyLink.getHref(), newTags, 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.Property in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testPOSTObjectNotAuthorized.
@Test
public void testPOSTObjectNotAuthorized() throws Exception {
final String TAG_VALUE = "TAG";
Property property = new Property();
property.setName("tags");
property.setValue(TAG_VALUE);
Object object = objectFactory.createObject();
object.setClassName("XWiki.TagClass");
object.getProperties().add(property);
PostMethod postMethod = executePostXml(buildURI(ObjectsResource.class, getWiki(), this.spaces, this.pageName).toString(), object);
Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_UNAUTHORIZED, postMethod.getStatusCode());
}
use of org.xwiki.rest.model.jaxb.Property in project xwiki-platform by xwiki.
the class TestUtils method disableSyntaxHighlighting.
/**
* Disable Syntax Highlighting.
*
* @since 9.7RC1
*/
public void disableSyntaxHighlighting() throws Exception {
ObjectPropertyReference enabledPropertyReference = new ObjectPropertyReference("enabled", new ObjectReference("SyntaxHighlighting.ConfigurationClass[0]", new DocumentReference(getCurrentWiki(), "SyntaxHighlighting", "Configuration")));
Property property = new Property();
property.setValue("0");
TestUtils.assertStatusCodes(rest().executePut(ObjectPropertyResource.class, property, rest().toElements(enabledPropertyReference)), true, STATUS_ACCEPTED);
}
use of org.xwiki.rest.model.jaxb.Property in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testPOSTObject.
@Test
public void testPOSTObject() throws Exception {
final String TAG_VALUE = "TAG";
Property property = new Property();
property.setName("tags");
property.setValue(TAG_VALUE);
Object object = objectFactory.createObject();
object.setClassName("XWiki.TagClass");
object.getProperties().add(property);
PostMethod postMethod = executePostXml(buildURI(ObjectsResource.class, getWiki(), this.spaces, this.pageName).toString(), object, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_CREATED, postMethod.getStatusCode());
object = (Object) unmarshaller.unmarshal(postMethod.getResponseBodyAsStream());
Assert.assertEquals(TAG_VALUE, getProperty(object, "tags").getValue());
GetMethod getMethod = executeGet(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, object.getClassName(), object.getNumber()).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
object = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(TAG_VALUE, getProperty(object, "tags").getValue());
}
use of org.xwiki.rest.model.jaxb.Property 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);
}
}
}
Aggregations