Ejemplo n.º 1
0
  @Test
  public void testDeleteSilentLockExpire(TestContext context) {
    Async async = context.async();

    long expireAfter = 5;
    String path = "/lock/test/testcontent";
    String lockedContent = "{\"content\":\"unlocked\"}";
    String newContent = "{\"content\":\"new\"}";

    // perform a PUT without lock
    given()
        .body(lockedContent)
        .put(path)
        .then()
        .assertThat()
        .statusCode(StatusCode.OK.getStatusCode());
    get(path).then().assertThat().body("content", is("unlocked"));

    // perform DELETE with lock
    with()
        .headers(createLockHeaders("test", LockMode.SILENT, expireAfter))
        .delete(path)
        .then()
        .assertThat()
        .statusCode(StatusCode.OK.getStatusCode());
    get(path).then().assertThat().statusCode(StatusCode.NOT_FOUND.getStatusCode());

    // perform PUT without lock (should return ok)
    given()
        .body(newContent)
        .put(path)
        .then()
        .assertThat()
        .statusCode(StatusCode.OK.getStatusCode());
    get(path).then().assertThat().statusCode(StatusCode.NOT_FOUND.getStatusCode());

    // perform PUT without lock (wait at most 2 x expire time)
    await()
        .atMost(expireAfter * 2, SECONDS)
        .until(
            () -> {
              given()
                  .body(newContent)
                  .put(path)
                  .then()
                  .assertThat()
                  .statusCode(StatusCode.OK.getStatusCode());

              if (get(path).getStatusCode() == StatusCode.OK.getStatusCode()) {
                return get(path).getBody().jsonPath().getString("content");
              } else {
                return "notfound";
              }
            },
            is("new"));

    async.complete();
  }
Ejemplo n.º 2
0
  @Test
  public void testDeleteCollectionWithLockedResource(TestContext context) {
    Async async = context.async();

    String base = "/lock/test/lockcollection/";
    String path1 = base + "res1";
    String path2 = base + "res2";
    String path3 = base + "res3";

    String content1 = "{\"content\":\"res1\"}";
    String content2 = "{\"content\":\"locked\"}";
    String content3 = "{\"content\":\"res2\"}";

    // create collection
    given().body(content1).put(path1).then().assertThat().statusCode(StatusCode.OK.getStatusCode());
    given()
        .body(content2)
        .headers(createLockHeaders("test", LockMode.REJECT, 10))
        .put(path2)
        .then()
        .assertThat()
        .statusCode(StatusCode.OK.getStatusCode());
    given().body(content3).put(path3).then().assertThat().statusCode(StatusCode.OK.getStatusCode());

    // try to delete resource (should fail)
    delete(path2).then().statusCode(StatusCode.CONFLICT.getStatusCode());

    // try to delete collection (should succeed)
    delete(base).then().statusCode(StatusCode.OK.getStatusCode());
    get(path2).then().assertThat().statusCode(StatusCode.NOT_FOUND.getStatusCode());

    async.complete();
  }
Ejemplo n.º 3
0
  @Test
  public void testDeleteRejectLockSameOwner(TestContext context) {
    Async async = context.async();

    String path = "/lock/test/testcontent";
    String lockedContent = "{\"content\":\"unlocked\"}";

    // perform a PUT with lock
    given()
        .body(lockedContent)
        .headers(createLockHeaders("test", LockMode.REJECT, 10))
        .put(path)
        .then()
        .assertThat()
        .statusCode(StatusCode.OK.getStatusCode());
    get(path).then().assertThat().body("content", is("unlocked"));

    // perform DELETE with same lock owner
    with()
        .headers(createLockHeaders("test", LockMode.REJECT, 10))
        .delete(path)
        .then()
        .assertThat()
        .statusCode(StatusCode.OK.getStatusCode());
    get(path).then().assertThat().statusCode(StatusCode.NOT_FOUND.getStatusCode());

    async.complete();
  }