protocols/src/test/java/eu/internetofus/common/protocols/EatTogetherV2ProtocolITC.java
/**
   * Check that an user can mark the task as completed.
   *
   * @param vertx       event bus to use.
   * @param testContext context to do the test.
   */
Check that an user can mark the task as completed.
@param vertx       event bus to use.
@param testContext context to do the test.
Check that an user can mark the task as completed . @param vertx event bus to use . @param testContext context to do the test .
@Test
  @Order(14)
  public void shouldTaskCompleted(final Vertx vertx, final VertxTestContext testContext) {
    this.assertLastSuccessfulTestWas(13, testContext);
    final var taskTransaction = new TaskTransaction();
    taskTransaction.actioneerId = this.task.requesterId;
    taskTransaction.taskId = this.task.id;
    taskTransaction.label = "taskCompleted";
    final var outcome = "completed";
    taskTransaction.attributes = new JsonObject().put("outcome", outcome);
    final var checkMessages = new ArrayList<Predicate<Message>>();
    final var checkStatus = new ArrayList<Predicate<TaskTransactionStatusBody>>();
    for (final var id : new String[] { this.users.get(2).id, this.users.get(4).id, this.users.get(5).id }) {
      checkMessages.add(this.createMessagePredicate().and(MessagePredicates.labelIs("TaskConcludedNotification"))
          .and(MessagePredicates.receiverIs(id)).and(MessagePredicates.attributesAre(new JsonObject()
              .put("communityId", this.community.id).put("taskId", this.task.id).put("outcome", outcome))));
      checkStatus.add(this.createIncentiveServerTaskTransactionStatusPredicate()
          .and(TaskTransactionStatusBodyPredicates.labelIs("TaskConcludedNotification"))
          .and(TaskTransactionStatusBodyPredicates.userIs(id)).and(TaskTransactionStatusBodyPredicates.countIs(1)));
    }
    final var checkTask = this.createTaskPredicate().and(TaskPredicates.isClosed())
        .and(TaskPredicates.attributesSimilarTo(
            new JsonObject().put("outcome", outcome).put("declined", new JsonArray().add(this.users.get(1).id))
                .put("accepted", new JsonArray().add(this.users.get(2).id))
                .put("refused", new JsonArray().add(this.users.get(3).id))
                .put("volunteers", new JsonArray().add(this.users.get(4).id))
                .put("unanswered", new JsonArray().add(this.users.get(5).id))))
        .and(TaskPredicates.transactionSizeIs(this.task.transactions.size() + 1))
        .and(TaskPredicates.transactionAt(this.task.transactions.size(),
            this.createTaskTransactionPredicate().and(TaskTransactionPredicates.similarTo(taskTransaction))
                .and(TaskTransactionPredicates.messagesSizeIs(checkMessages.size()))
                .and(TaskTransactionPredicates.containsMessages(checkMessages))));
    checkStatus.add(this.createIncentiveServerTaskTransactionStatusPredicate()
        .and(TaskTransactionStatusBodyPredicates.labelIs(taskTransaction.label))
        .and(TaskTransactionStatusBodyPredicates.userIs(this.task.requesterId))
        .and(TaskTransactionStatusBodyPredicates.countIs(1)));
    final var future = WeNetTaskManager.createProxy(vertx).doTaskTransaction(taskTransaction)
        .compose(ignored -> this.waitUntilTask(vertx, testContext, checkTask))
        .compose(ignored -> this.waitUntilCallbacks(vertx, testContext, checkMessages))
        .compose(ignored -> this.waitUntilIncentiveServerHasTaskTransactionStatus(vertx, testContext, checkStatus));
    future.onComplete(testContext.succeeding(ignored -> this.assertSuccessfulCompleted(testContext)));
  }
@ Test @ Order ( 14 ) public void shouldTaskCompleted ( final Vertx vertx , final VertxTestContext testContext ) { this . assertLastSuccessfulTestWas ( 13 , testContext ) ; final var taskTransaction = new TaskTransaction ( ) ; taskTransaction . actioneerId = this . task . requesterId ; taskTransaction . taskId = this . task . id ; taskTransaction . label = "taskCompleted" ; final var outcome = "completed" ; taskTransaction . attributes = new JsonObject ( ) . put ( "outcome" , outcome ) ; final var checkMessages = new ArrayList < Predicate < Message > > ( ) ; final var checkStatus = new ArrayList < Predicate < TaskTransactionStatusBody > > ( ) ; for ( final var id : new String [ ] { this . users . get ( 2 ) . id , this . users . get ( 4 ) . id , this . users . get ( 5 ) . id } ) { checkMessages . add ( this . createMessagePredicate ( ) . and ( MessagePredicates . labelIs ( "TaskConcludedNotification" ) ) . and ( MessagePredicates . receiverIs ( id ) ) . and ( MessagePredicates . attributesAre ( new JsonObject ( ) . put ( "communityId" , this . community . id ) . put ( "taskId" , this . task . id ) . put ( "outcome" , outcome ) ) ) ) ; checkStatus . add ( this . createIncentiveServerTaskTransactionStatusPredicate ( ) . and ( TaskTransactionStatusBodyPredicates . labelIs ( "TaskConcludedNotification" ) ) . and ( TaskTransactionStatusBodyPredicates . userIs ( id ) ) . and ( TaskTransactionStatusBodyPredicates . countIs ( 1 ) ) ) ; } final var checkTask = this . createTaskPredicate ( ) . and ( TaskPredicates . isClosed ( ) ) . and ( TaskPredicates . attributesSimilarTo ( new JsonObject ( ) . put ( "outcome" , outcome ) . put ( "declined" , new JsonArray ( ) . add ( this . users . get ( 1 ) . id ) ) . put ( "accepted" , new JsonArray ( ) . add ( this . users . get ( 2 ) . id ) ) . put ( "refused" , new JsonArray ( ) . add ( this . users . get ( 3 ) . id ) ) . put ( "volunteers" , new JsonArray ( ) . add ( this . users . get ( 4 ) . id ) ) . put ( "unanswered" , new JsonArray ( ) . add ( this . users . get ( 5 ) . id ) ) ) ) . and ( TaskPredicates . transactionSizeIs ( this . task . transactions . size ( ) + 1 ) ) . and ( TaskPredicates . transactionAt ( this . task . transactions . size ( ) , this . createTaskTransactionPredicate ( ) . and ( TaskTransactionPredicates . similarTo ( taskTransaction ) ) . and ( TaskTransactionPredicates . messagesSizeIs ( checkMessages . size ( ) ) ) . and ( TaskTransactionPredicates . containsMessages ( checkMessages ) ) ) ) ; checkStatus . add ( this . createIncentiveServerTaskTransactionStatusPredicate ( ) . and ( TaskTransactionStatusBodyPredicates . labelIs ( taskTransaction . label ) ) . and ( TaskTransactionStatusBodyPredicates . userIs ( this . task . requesterId ) ) . and ( TaskTransactionStatusBodyPredicates . countIs ( 1 ) ) ) ; final var future = WeNetTaskManager . createProxy ( vertx ) . doTaskTransaction ( taskTransaction ) . compose ( ignored -> this . waitUntilTask ( vertx , testContext , checkTask ) ) . compose ( ignored -> this . waitUntilCallbacks ( vertx , testContext , checkMessages ) ) . compose ( ignored -> this . waitUntilIncentiveServerHasTaskTransactionStatus ( vertx , testContext , checkStatus ) ) ; future . onComplete ( testContext . succeeding ( ignored -> this . assertSuccessfulCompleted ( testContext ) ) ) ; }
Check that an user can mark the task as completed.
Check that an user can mark the task as completed .