use of org.xwiki.rest.model.jaxb.Object 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.Object in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testDELETEObject.
@Test
public void testDELETEObject() 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(), TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_NO_CONTENT, deleteMethod.getStatusCode());
GetMethod getMethod = executeGet(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, objectToBeDeleted.getClassName(), objectToBeDeleted.getNumber()).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode());
}
use of org.xwiki.rest.model.jaxb.Object in project xwiki-platform by xwiki.
the class ObjectsResourceTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
this.wikiName = getWiki();
this.spaces = Arrays.asList(getTestClassName());
this.pageName = getTestMethodName();
this.reference = new DocumentReference(this.wikiName, this.spaces, this.pageName);
// Create a clean test page.
this.testUtils.rest().delete(this.reference);
this.testUtils.rest().savePage(this.reference);
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);
/* Create a tag object if it doesn't exist yet */
if (link == null) {
Object object = objectFactory.createObject();
object.setClassName("XWiki.TagClass");
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());
}
}
use of org.xwiki.rest.model.jaxb.Object in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testPUTObjectUnauthorized.
@Test
public void testPUTObjectUnauthorized() 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 object = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
String originalTagValue = getProperty(object, "tags").getValue();
getProperty(object, "tags").setValue(TAG_VALUE);
PutMethod putMethod = executePutXml(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, objectToBePut.getClassName(), objectToBePut.getNumber()).toString(), object);
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_UNAUTHORIZED, putMethod.getStatusCode());
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 = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(originalTagValue, getProperty(object, "tags").getValue());
}
use of org.xwiki.rest.model.jaxb.Object 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());
}
Aggregations