protocols/src/test/java/eu/internetofus/common/protocols/EatTogetherV2ProtocolITC.java
/**
   * Check that an user is accept to be volunteer of a task.
   *
   * @param vertx       event bus to use.
   * @param testContext context to do the test.
   */
Check that an user is accept to be volunteer of a task.
@param vertx       event bus to use.
@param testContext context to do the test.
Check that an user is accept to be volunteer of a task . @param vertx event bus to use . @param testContext context to do the test .
@Test
  @Order(8)
  public void shouldVolunteerForTask(final Vertx vertx, final VertxTestContext testContext) {
    this.assertLastSuccessfulTestWas(7, testContext);
    final var checkMessages = new ArrayList<Predicate<Message>>();
    final var checkInteractions = new ArrayList<Predicate<Interaction>>();
    final var checkStatus = new ArrayList<Predicate<TaskTransactionStatusBody>>();
    final var unanswered = this.task.attributes.getJsonArray("unanswered").copy();
    final var volunteers = new JsonArray();
    Future<?> future = Future.succeededFuture();
    for (var i = 2; i < this.users.size() - 1; i++) {
      final var volunteerId = this.users.get(i).id;
      unanswered.remove(volunteerId);
      volunteers.add(volunteerId);
      final var checkMessage = this.createMessagePredicate().and(MessagePredicates.labelIs("TaskVolunteerNotification"))
          .and(MessagePredicates.receiverIs(this.task.requesterId)).and(MessagePredicates.attributesAre(new JsonObject()
              .put("communityId", this.community.id).put("taskId", this.task.id).put("volunteerId", volunteerId)));
      checkMessages.add(checkMessage);
      final var taskTransaction = new TaskTransaction();
      taskTransaction.actioneerId = volunteerId;
      taskTransaction.taskId = this.task.id;
      taskTransaction.label = "volunteerForTask";
      taskTransaction.attributes = new JsonObject().put("volunteerId", volunteerId);
      checkStatus.add(this.createIncentiveServerTaskTransactionStatusPredicate()
          .and(TaskTransactionStatusBodyPredicates.labelIs(taskTransaction.label))
          .and(TaskTransactionStatusBodyPredicates.userIs(volunteerId)));
      final var checkTask = this.createTaskPredicate()
          .and(TaskPredicates.attributesSimilarTo(
              new JsonObject().put("unanswered", unanswered.copy()).put("volunteers", volunteers.copy())))
          .and(TaskPredicates.transactionSizeIs(i + 1))
          .and(TaskPredicates.transactionAt(i,
              this.createTaskTransactionPredicate().and(TaskTransactionPredicates.similarTo(taskTransaction))
                  .and(TaskTransactionPredicates.messagesSizeIs(1))
                  .and(TaskTransactionPredicates.messageAt(0, checkMessage))));
      future = future.compose(map -> WeNetTaskManager.createProxy(vertx).doTaskTransaction(taskTransaction))
          .compose(ignored -> this.waitUntilTask(vertx, testContext, checkTask));
    }
    future = future.compose(ignored -> this.waitUntilCallbacks(vertx, testContext, checkMessages))
        .compose(ignored -> this.waitUntilIncentiveServerHasTaskTransactionStatus(vertx, testContext, checkStatus))
        .compose(ignored -> this.waitUntilInteractions(vertx, testContext, checkInteractions));
    future.onComplete(testContext.succeeding(ignored -> this.assertSuccessfulCompleted(testContext)));
  }
@ Test @ Order ( 8 ) public void shouldVolunteerForTask ( final Vertx vertx , final VertxTestContext testContext ) { this . assertLastSuccessfulTestWas ( 7 , testContext ) ; final var checkMessages = new ArrayList < Predicate < Message > > ( ) ; final var checkInteractions = new ArrayList < Predicate < Interaction > > ( ) ; final var checkStatus = new ArrayList < Predicate < TaskTransactionStatusBody > > ( ) ; final var unanswered = this . task . attributes . getJsonArray ( "unanswered" ) . copy ( ) ; final var volunteers = new JsonArray ( ) ; Future < ? > future = Future . succeededFuture ( ) ; for ( var i = 2 ; i < this . users . size ( ) - 1 ; i ++ ) { final var volunteerId = this . users . get ( i ) . id ; unanswered . remove ( volunteerId ) ; volunteers . add ( volunteerId ) ; final var checkMessage = this . createMessagePredicate ( ) . and ( MessagePredicates . labelIs ( "TaskVolunteerNotification" ) ) . and ( MessagePredicates . receiverIs ( this . task . requesterId ) ) . and ( MessagePredicates . attributesAre ( new JsonObject ( ) . put ( "communityId" , this . community . id ) . put ( "taskId" , this . task . id ) . put ( "volunteerId" , volunteerId ) ) ) ; checkMessages . add ( checkMessage ) ; final var taskTransaction = new TaskTransaction ( ) ; taskTransaction . actioneerId = volunteerId ; taskTransaction . taskId = this . task . id ; taskTransaction . label = "volunteerForTask" ; taskTransaction . attributes = new JsonObject ( ) . put ( "volunteerId" , volunteerId ) ; checkStatus . add ( this . createIncentiveServerTaskTransactionStatusPredicate ( ) . and ( TaskTransactionStatusBodyPredicates . labelIs ( taskTransaction . label ) ) . and ( TaskTransactionStatusBodyPredicates . userIs ( volunteerId ) ) ) ; final var checkTask = this . createTaskPredicate ( ) . and ( TaskPredicates . attributesSimilarTo ( new JsonObject ( ) . put ( "unanswered" , unanswered . copy ( ) ) . put ( "volunteers" , volunteers . copy ( ) ) ) ) . and ( TaskPredicates . transactionSizeIs ( i + 1 ) ) . and ( TaskPredicates . transactionAt ( i , this . createTaskTransactionPredicate ( ) . and ( TaskTransactionPredicates . similarTo ( taskTransaction ) ) . and ( TaskTransactionPredicates . messagesSizeIs ( 1 ) ) . and ( TaskTransactionPredicates . messageAt ( 0 , checkMessage ) ) ) ) ; future = future . compose ( map -> WeNetTaskManager . createProxy ( vertx ) . doTaskTransaction ( taskTransaction ) ) . compose ( ignored -> this . waitUntilTask ( vertx , testContext , checkTask ) ) ; } future = future . compose ( ignored -> this . waitUntilCallbacks ( vertx , testContext , checkMessages ) ) . compose ( ignored -> this . waitUntilIncentiveServerHasTaskTransactionStatus ( vertx , testContext , checkStatus ) ) . compose ( ignored -> this . waitUntilInteractions ( vertx , testContext , checkInteractions ) ) ; future . onComplete ( testContext . succeeding ( ignored -> this . assertSuccessfulCompleted ( testContext ) ) ) ; }
Check that an user is accept to be volunteer of a task.
Check that an user is accept to be volunteer of a task .