protocols/src/test/java/eu/internetofus/common/protocols/Ask4HelpV1_2ProtocolITC.java
/**
   * Check that an user answer.
   *
   * @param vertx       event bus to use.
   * @param testContext context to do the test.
   */
Check that an user answer.
@param vertx       event bus to use.
@param testContext context to do the test.
Check that an user answer . @param vertx event bus to use . @param testContext context to do the test .
@Test
  @Order(6)
  public void shouldAnswer(final Vertx vertx, final VertxTestContext testContext) {
    this.assertLastSuccessfulTestWas(5, testContext);
    final var checkMessages = new ArrayList<Predicate<Message>>();
    final var checkStatus = new ArrayList<Predicate<TaskTransactionStatusBody>>();
    Future<?> future = Future.succeededFuture();
    for (var i = 1; i < 4; i++) {
      final var index = i;
      final var transaction = new TaskTransaction();
      transaction.actioneerId = this.users.get(i).id;
      transaction.taskId = this.task.id;
      transaction.label = "answerTransaction";
      final var answer = "Response question " + i;
      transaction.attributes = new JsonObject().put("answer", answer);
      final var checkMessage = this.createMessagePredicate().and(MessagePredicates.labelIs("AnsweredQuestionMessage"))
          .and(MessagePredicates.receiverIs(this.task.requesterId))
          .and(MessagePredicates.attributesSimilarTo(new JsonObject().put("answer", answer).put("taskId", this.task.id)
              .put("userId", transaction.actioneerId)));
      checkMessages.add(checkMessage);
      final var checkTask = this.createTaskPredicate().and(TaskPredicates.transactionSizeIs(i + 1))
          .and(TaskPredicates.transactionAt(i,
              this.createTaskTransactionPredicate().and(TaskTransactionPredicates.similarTo(transaction))
                  .and(TaskTransactionPredicates.messagesSizeIs(1))
                  .and(TaskTransactionPredicates.messageAt(0, checkMessage))
                  .and(source -> source.id.equals(source.messages.get(0).attributes.getString("transactionId")))));
      checkStatus.add(this.createIncentiveServerTaskTransactionStatusPredicate()
          .and(TaskTransactionStatusBodyPredicates.userIs(transaction.actioneerId))
          .and(TaskTransactionStatusBodyPredicates.labelIs(transaction.label))
          .and(TaskTransactionStatusBodyPredicates.countIs(1)));
      checkStatus.add(this.createIncentiveServerTaskTransactionStatusPredicate()
          .and(TaskTransactionStatusBodyPredicates.userIs(this.task.requesterId))
          .and(TaskTransactionStatusBodyPredicates.labelIs("AnsweredQuestionMessage"))
          .and(TaskTransactionStatusBodyPredicates.countIs(index)));
      future = future.compose(ignored -> WeNetTaskManager.createProxy(vertx).doTaskTransaction(transaction))
          .compose(ignored -> this.waitUntilTask(vertx, testContext, checkTask));
    }
    future = future.compose(ignored -> this.waitUntilCallbacks(vertx, testContext, checkMessages))
        .compose(ignored -> this.waitUntilIncentiveServerHasTaskTransactionStatus(vertx, testContext, checkStatus));
    future.onComplete(testContext.succeeding(ignored -> this.assertSuccessfulCompleted(testContext)));
  }
@ Test @ Order ( 6 ) public void shouldAnswer ( final Vertx vertx , final VertxTestContext testContext ) { this . assertLastSuccessfulTestWas ( 5 , testContext ) ; final var checkMessages = new ArrayList < Predicate < Message > > ( ) ; final var checkStatus = new ArrayList < Predicate < TaskTransactionStatusBody > > ( ) ; Future < ? > future = Future . succeededFuture ( ) ; for ( var i = 1 ; i < 4 ; i ++ ) { final var index = i ; final var transaction = new TaskTransaction ( ) ; transaction . actioneerId = this . users . get ( i ) . id ; transaction . taskId = this . task . id ; transaction . label = "answerTransaction" ; final var answer = "Response question " + i ; transaction . attributes = new JsonObject ( ) . put ( "answer" , answer ) ; final var checkMessage = this . createMessagePredicate ( ) . and ( MessagePredicates . labelIs ( "AnsweredQuestionMessage" ) ) . and ( MessagePredicates . receiverIs ( this . task . requesterId ) ) . and ( MessagePredicates . attributesSimilarTo ( new JsonObject ( ) . put ( "answer" , answer ) . put ( "taskId" , this . task . id ) . put ( "userId" , transaction . actioneerId ) ) ) ; checkMessages . add ( checkMessage ) ; final var checkTask = this . createTaskPredicate ( ) . and ( TaskPredicates . transactionSizeIs ( i + 1 ) ) . and ( TaskPredicates . transactionAt ( i , this . createTaskTransactionPredicate ( ) . and ( TaskTransactionPredicates . similarTo ( transaction ) ) . and ( TaskTransactionPredicates . messagesSizeIs ( 1 ) ) . and ( TaskTransactionPredicates . messageAt ( 0 , checkMessage ) ) . and ( source -> source . id . equals ( source . messages . get ( 0 ) . attributes . getString ( "transactionId" ) ) ) ) ) ; checkStatus . add ( this . createIncentiveServerTaskTransactionStatusPredicate ( ) . and ( TaskTransactionStatusBodyPredicates . userIs ( transaction . actioneerId ) ) . and ( TaskTransactionStatusBodyPredicates . labelIs ( transaction . label ) ) . and ( TaskTransactionStatusBodyPredicates . countIs ( 1 ) ) ) ; checkStatus . add ( this . createIncentiveServerTaskTransactionStatusPredicate ( ) . and ( TaskTransactionStatusBodyPredicates . userIs ( this . task . requesterId ) ) . and ( TaskTransactionStatusBodyPredicates . labelIs ( "AnsweredQuestionMessage" ) ) . and ( TaskTransactionStatusBodyPredicates . countIs ( index ) ) ) ; future = future . compose ( ignored -> WeNetTaskManager . createProxy ( vertx ) . doTaskTransaction ( transaction ) ) . compose ( ignored -> this . waitUntilTask ( vertx , testContext , checkTask ) ) ; } future = future . 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 answer.
Check that an user answer .