Search in sources :

Example 11 with Object

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());
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) Object(org.xwiki.rest.model.jaxb.Object) Property(org.xwiki.rest.model.jaxb.Property) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 12 with Object

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());
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Object(org.xwiki.rest.model.jaxb.Object) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 13 with Object

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());
    }
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Page(org.xwiki.rest.model.jaxb.Page) Object(org.xwiki.rest.model.jaxb.Object) DocumentReference(org.xwiki.model.reference.DocumentReference) Link(org.xwiki.rest.model.jaxb.Link) Before(org.junit.Before)

Example 14 with Object

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());
}
Also used : GetMethod(org.apache.commons.httpclient.methods.GetMethod) PutMethod(org.apache.commons.httpclient.methods.PutMethod) Object(org.xwiki.rest.model.jaxb.Object) ObjectResource(org.xwiki.rest.resources.objects.ObjectResource) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 15 with Object

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());
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Object(org.xwiki.rest.model.jaxb.Object) Property(org.xwiki.rest.model.jaxb.Property) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Aggregations

Object (org.xwiki.rest.model.jaxb.Object)27 Test (org.junit.Test)16 GetMethod (org.apache.commons.httpclient.methods.GetMethod)15 Property (org.xwiki.rest.model.jaxb.Property)15 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)15 Link (org.xwiki.rest.model.jaxb.Link)11 PostMethod (org.apache.commons.httpclient.methods.PostMethod)8 Page (org.xwiki.rest.model.jaxb.Page)8 ObjectResource (org.xwiki.rest.resources.objects.ObjectResource)7 XWikiException (com.xpn.xwiki.XWikiException)6 Document (com.xpn.xwiki.api.Document)6 WebApplicationException (javax.ws.rs.WebApplicationException)6 PutMethod (org.apache.commons.httpclient.methods.PutMethod)6 ObjectSummary (org.xwiki.rest.model.jaxb.ObjectSummary)6 Objects (org.xwiki.rest.model.jaxb.Objects)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 XWikiRestException (org.xwiki.rest.XWikiRestException)5 BaseObject (com.xpn.xwiki.objects.BaseObject)3 NameValuePair (org.apache.commons.httpclient.NameValuePair)3 ArrayList (java.util.ArrayList)2