コード例 #1
0
  @Test
  public void test() throws HttpException, IOException, JAXBException, InterruptedException {

    // create uri
    UserDocumentUriKey key = new UserDocumentUriKey(appUsage.getAUID(), user, documentName);

    String newContent =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + "<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\">"
            + "<list name=\"enemies\"/>"
            + "</resource-lists>";

    // send put request and get response
    Response initialPutResponse = client.put(key, appUsage.getMimetype(), newContent, null);

    // check put response
    assertTrue("Put response must exists", initialPutResponse != null);
    assertTrue("Put response code should be 201", initialPutResponse.getCode() == 201);

    // create uri
    LinkedList<ElementSelectorStep> elementSelectorSteps = new LinkedList<ElementSelectorStep>();
    ElementSelectorStep step1 = new ElementSelectorStep("resource-lists");
    ElementSelectorStep step2 = new ElementSelectorStep("list");
    elementSelectorSteps.add(step1);
    elementSelectorSteps.addLast(step2);
    UserAttributeUriKey attrKey =
        new UserAttributeUriKey(
            appUsage.getAUID(),
            user,
            documentName,
            new ElementSelector(elementSelectorSteps),
            new AttributeSelector("name"),
            null);

    // send put request and get response
    Response attrPutResponse = client.put(attrKey, AttributeResource.MIMETYPE, "friends", null);

    // check put response
    assertTrue("Put response must exists", attrPutResponse != null);
    assertTrue("Put response code should be 200", attrPutResponse.getCode() == 200);

    // send get request and get response
    Response attrGetResponse = client.get(attrKey, null);

    // check get response
    assertTrue("Get response must exists", attrGetResponse != null);
    assertTrue(
        "Get response code should be 200 and the attr value must equals the one sent in put",
        attrGetResponse.getCode() == 200
            && XMLValidator.weaklyEquals((String) attrGetResponse.getContent(), "friends"));

    // clean up
    client.delete(key, null);
  }
コード例 #2
0
  @Test
  public void test() throws HttpException, IOException, JAXBException, InterruptedException {

    // create uri
    UserDocumentUriKey key = new UserDocumentUriKey(appUsage.getAUID(), user, documentName);

    // the doc to put
    String document =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + "<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\">"
            + "<list name=\"friends\"/>"
            + "<list name=\"enemies\"/>"
            + "</resource-lists>";

    // send put request and get response
    Response initialPutResponse = client.put(key, appUsage.getMimetype(), document, null);

    // check put response
    assertTrue("Put response must exists", initialPutResponse != null);
    assertTrue("Put response code should be 201", initialPutResponse.getCode() == 201);

    // create uri
    LinkedList<ElementSelectorStep> elementSelectorSteps = new LinkedList<ElementSelectorStep>();
    ElementSelectorStep step1 = new ElementSelectorStep("resource-lists");
    ElementSelectorStep step2 = new ElementSelectorStepByPos("*", 2);
    elementSelectorSteps.add(step1);
    elementSelectorSteps.addLast(step2);
    UserElementUriKey elemKey =
        new UserElementUriKey(
            appUsage.getAUID(),
            user,
            documentName,
            new ElementSelector(elementSelectorSteps),
            null);

    // send delete request and get response
    Response elemDeleteResponse = client.delete(elemKey, null);

    // check delete response
    assertTrue("Delete response must exists", elemDeleteResponse != null);
    assertTrue("Delete response code should be 200", elemDeleteResponse.getCode() == 200);

    // send get request and get response
    Response elemGetResponse = client.get(elemKey, null);

    // check get response
    assertTrue("Get response must exists", elemGetResponse != null);
    assertTrue("Get response code should be 404", elemGetResponse.getCode() == 404);

    // clean up
    client.delete(key, null);
  }