Exemplo n.º 1
0
  @Test(dataProvider = "annotatedRequestHandlerData")
  public void testActionCollectionItemAnnotatedRequestHandler(
      Class<?> requestHandler,
      boolean collection,
      boolean create,
      boolean read,
      boolean update,
      boolean delete,
      boolean patch,
      boolean resourceAction,
      boolean collectionAction,
      boolean query)
      throws Exception {

    // Given
    Object provider = requestHandler.newInstance();
    Connection connection = Resources.newInternalConnection(createHandler(collection, provider));
    ActionRequest req1 = Requests.newActionRequest("/test/fred", "instanceAction1");
    ActionRequest req2 = Requests.newActionRequest("/test/fred", "instanceAction2");

    // When
    Promise<JsonValue, ResourceException> promise1 =
        connection.actionAsync(new RootContext(), req1);
    Promise<JsonValue, ResourceException> promise2 =
        connection.actionAsync(new RootContext(), req2);

    // Then
    if (collectionAction && collection) {
      AssertJJsonValueAssert.assertThat(promise1)
          .succeeded()
          .stringAt("result")
          .isEqualTo("instanceAction1-fred");
      AssertJJsonValueAssert.assertThat(promise2)
          .succeeded()
          .stringAt("result")
          .isEqualTo("instanceAction2-fred");
    } else if (collection) {
      AssertJJsonValueAssert.assertThat(promise1)
          .failedWithException()
          .isInstanceOf(NotSupportedException.class);
      AssertJJsonValueAssert.assertThat(promise2)
          .failedWithException()
          .isInstanceOf(NotSupportedException.class);
    } else {
      AssertJJsonValueAssert.assertThat(promise1)
          .failedWithException()
          .isInstanceOf(NotFoundException.class);
      AssertJJsonValueAssert.assertThat(promise2)
          .failedWithException()
          .isInstanceOf(NotFoundException.class);
    }
  }
Exemplo n.º 2
0
  @Test(dataProvider = "annotatedRequestHandlerData")
  public void testActionAnnotatedRequestHandler(
      Class<?> requestHandler,
      boolean collection,
      boolean create,
      boolean read,
      boolean update,
      boolean delete,
      boolean patch,
      boolean resourceAction,
      boolean collectionAction,
      boolean query)
      throws Exception {

    // Given
    Object provider = requestHandler.newInstance();
    Connection connection = Resources.newInternalConnection(createHandler(collection, provider));
    String actionId1 = collection ? "collectionAction1" : "instanceAction1";
    ActionRequest req1 = Requests.newActionRequest("/test", actionId1);
    String actionId2 = collection ? "collectionAction2" : "instanceAction2";
    ActionRequest req2 = Requests.newActionRequest("/test", actionId2);

    // When
    Promise<JsonValue, ResourceException> promise1 =
        connection.actionAsync(new RootContext(), req1);
    Promise<JsonValue, ResourceException> promise2 =
        connection.actionAsync(new RootContext(), req2);

    // Then
    if ((collection && collectionAction) || (!collection && resourceAction)) {
      assertThatJsonValue(promise1).succeeded().stringAt("result").isEqualTo(actionId1);
      assertThatJsonValue(promise2).succeeded().stringAt("result").isEqualTo(actionId2);
    } else {
      assertThatJsonValue(promise1).failedWithException().isInstanceOf(NotSupportedException.class);
      assertThatJsonValue(promise2).failedWithException().isInstanceOf(NotSupportedException.class);
    }
  }