Search in sources :

Example 16 with Object

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

Example 17 with Object

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());
}
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 18 with Object

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

Example 19 with Object

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

Example 20 with Object

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);
        }
    }
}
Also used : GetMethod(org.apache.commons.httpclient.methods.GetMethod) Objects(org.xwiki.rest.model.jaxb.Objects) Page(org.xwiki.rest.model.jaxb.Page) Object(org.xwiki.rest.model.jaxb.Object) ObjectSummary(org.xwiki.rest.model.jaxb.ObjectSummary) Property(org.xwiki.rest.model.jaxb.Property) Link(org.xwiki.rest.model.jaxb.Link) 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