コード例 #1
0
  @Test
  public void testGETObjectAtPageVersion() throws Exception {
    Object objectToBePut = getObject("XWiki.TagClass");

    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(
              getUriBuilder(ObjectResource.class)
                  .build(
                      getWiki(),
                      "Main",
                      "WebHome",
                      objectToBePut.getClassName(),
                      objectToBePut.getNumber())
                  .toString(),
              objectToBePut,
              "Admin",
              "admin");
      Assert.assertEquals(
          getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.getStatusCode());

      GetMethod getMethod =
          executeGet(
              getUriBuilder(PageResource.class).build(getWiki(), "Main", "WebHome").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(
              getUriBuilder(ObjectAtPageVersionResource.class)
                  .build(
                      getWiki(),
                      "Main",
                      "WebHome",
                      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);
      }
    }
  }