Search in sources :

Example 11 with Property

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());
}
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 12 with Property

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());
}
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 13 with Property

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);
}
Also used : ObjectPropertyReference(org.xwiki.model.reference.ObjectPropertyReference) ObjectReference(org.xwiki.model.reference.ObjectReference) Property(org.xwiki.rest.model.jaxb.Property) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) ObjectPropertyResource(org.xwiki.rest.resources.objects.ObjectPropertyResource)

Example 14 with Property

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

Example 15 with Property

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);
        }
    }
}
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)

Aggregations

Property (org.xwiki.rest.model.jaxb.Property)23 Object (org.xwiki.rest.model.jaxb.Object)15 Test (org.junit.Test)10 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)10 Link (org.xwiki.rest.model.jaxb.Link)9 GetMethod (org.apache.commons.httpclient.methods.GetMethod)8 XWikiException (com.xpn.xwiki.XWikiException)6 WebApplicationException (javax.ws.rs.WebApplicationException)6 Page (org.xwiki.rest.model.jaxb.Page)6 Document (com.xpn.xwiki.api.Document)5 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 XWikiRestException (org.xwiki.rest.XWikiRestException)5 ObjectResource (org.xwiki.rest.resources.objects.ObjectResource)5 PostMethod (org.apache.commons.httpclient.methods.PostMethod)4 PutMethod (org.apache.commons.httpclient.methods.PutMethod)4 ObjectSummary (org.xwiki.rest.model.jaxb.ObjectSummary)4 Objects (org.xwiki.rest.model.jaxb.Objects)4 BaseObject (com.xpn.xwiki.objects.BaseObject)3 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3