protocols/src/test/java/eu/internetofus/common/protocols/AbstractAsk4HelpV2_2ProtocolRandomUsersITC.java
/**
   * Check that the requester can ask for more answers.
   *
   * @param vertx       event bus to use.
   * @param testContext context to do the test.
   */
Check that the requester can ask for more answers.
@param vertx       event bus to use.
@param testContext context to do the test.
Check that the requester can ask for more answers . @param vertx event bus to use . @param testContext context to do the test .
@Test
  @Order(8)
  public void shouldAskForMoreAnswers(final Vertx vertx, final VertxTestContext testContext) {
    this.assertLastSuccessfulTestWas(6, testContext);
    this.lastSuccessfulTest = 7;
    for (final var user : this.users) {
      final var userId = user.id;
      if (!this.task.requesterId.equals(userId) && !this.participants.contains(userId)) {
        this.expectedNewParticipants.add(userId);
      }
    }
    final var checkMessages = new ArrayList<Predicate<Message>>();
    final var checkIncentiveTransactionStatus = new ArrayList<Predicate<TaskTransactionStatusBody>>();
    final var checkSocialNotification = new ArrayList<Predicate<UserMessage>>();
    final var checkInteractions = new ArrayList<Predicate<Interaction>>();
    final var transactionId = String.valueOf(this.task.transactions.size());
    final var maxUsers = this.expectedNewParticipants.size();
    for (var i = 0; i < maxUsers; i++) {
      checkMessages
          .add(this.createMessagePredicate().and(MessagePredicates.labelIs("QuestionToAnswerMessage")).and(msg -> {
            if (!this.expectedNewParticipants.contains(msg.receiverId)) {
              return false;
            }
            this.participants.add(msg.receiverId);
            return true;
          }).and(MessagePredicates
              .attributesSimilarTo(new JsonObject().put("question", this.task.goal.name).put("taskId", this.task.id)
                  .put("userId", this.task.requesterId).put("sensitive", false).put("anonymous", false))));
      checkIncentiveTransactionStatus.add(this.createIncentiveServerTaskTransactionStatusPredicate()
          .and(TaskTransactionStatusBodyPredicates.labelIs("QuestionToAnswerMessage"))
          .and(transaction -> this.participants.contains(transaction.user_id))
          .and(TaskTransactionStatusBodyPredicates.countIs(1)));
      checkSocialNotification
          .add(this.createSocialNotificationPredicate().and(UserMessagePredicates.senderId(this.task.requesterId))
              .and(UserMessagePredicates.transactionId(transactionId))
              .and(UserMessagePredicates
                  .message(this.createMessagePredicate().and(MessagePredicates.labelIs("QuestionToAnswerMessage"))
                      .and(msg -> this.participants.contains(msg.receiverId))
                      .and(MessagePredicates.attributesSimilarTo(new JsonObject().put("taskId", this.task.id)
                          .put("question", this.task.goal.name).put("userId", this.task.requesterId)
                          .put("sensitive", false).put("anonymous", false))))));
      checkInteractions.add(this.createInteractionPredicate().and(InteractionPredicates.senderIs(this.task.requesterId))
          .and(InteractionPredicates.transactionLabelIs("moreAnswerTransaction"))
          .and(interaction -> this.participants.contains(interaction.receiverId))
          .and(InteractionPredicates.messageLabelIs("QuestionToAnswerMessage")));
    }
    final var moreAnswerTransaction = new TaskTransaction();
    moreAnswerTransaction.taskId = this.task.id;
    moreAnswerTransaction.actioneerId = this.task.requesterId;
    moreAnswerTransaction.label = "moreAnswerTransaction";
    final var checkTask = this.createTaskPredicate()
        .and(TaskPredicates.lastTransactionIs(
            this.createTaskTransactionPredicate().and(TaskTransactionPredicates.similarTo(moreAnswerTransaction))
                .and(TaskTransactionPredicates.messagesSizeIs(maxUsers))
                .and(TaskTransactionPredicates.containsMessages(checkMessages))));
    final Future<?> future = WeNetTaskManager.createProxy(vertx).doTaskTransaction(moreAnswerTransaction)
        .compose(ignored -> this.waitUntilTask(vertx, testContext, checkTask))
        .compose(ignored -> this.waitUntilCallbacks(vertx, testContext, checkMessages))
        .compose(ignored -> this.waitUntilIncentiveServerHasTaskTransactionStatus(vertx, testContext,
            checkIncentiveTransactionStatus))
        .compose(ignored -> this.waitUntilSocialNotification(vertx, testContext, checkSocialNotification))
        .compose(ignored -> this.waitUntilInteractions(vertx, testContext, checkInteractions));
    future.onComplete(testContext.succeeding(ignored -> testContext.verify(() -> {
      assertThat(this.participants).hasSize(8);
      this.assertSuccessfulCompleted(testContext);
    })));
  }
@ Test @ Order ( 8 ) public void shouldAskForMoreAnswers ( final Vertx vertx , final VertxTestContext testContext ) { this . assertLastSuccessfulTestWas ( 6 , testContext ) ; this . lastSuccessfulTest = 7 ; for ( final var user : this . users ) { final var userId = user . id ; if ( ! this . task . requesterId . equals ( userId ) && ! this . participants . contains ( userId ) ) { this . expectedNewParticipants . add ( userId ) ; } } final var checkMessages = new ArrayList < Predicate < Message > > ( ) ; final var checkIncentiveTransactionStatus = new ArrayList < Predicate < TaskTransactionStatusBody > > ( ) ; final var checkSocialNotification = new ArrayList < Predicate < UserMessage > > ( ) ; final var checkInteractions = new ArrayList < Predicate < Interaction > > ( ) ; final var transactionId = String . valueOf ( this . task . transactions . size ( ) ) ; final var maxUsers = this . expectedNewParticipants . size ( ) ; for ( var i = 0 ; i < maxUsers ; i ++ ) { checkMessages . add ( this . createMessagePredicate ( ) . and ( MessagePredicates . labelIs ( "QuestionToAnswerMessage" ) ) . and ( msg -> { if ( ! this . expectedNewParticipants . contains ( msg . receiverId ) ) { return false ; } this . participants . add ( msg . receiverId ) ; return true ; } ) . and ( MessagePredicates . attributesSimilarTo ( new JsonObject ( ) . put ( "question" , this . task . goal . name ) . put ( "taskId" , this . task . id ) . put ( "userId" , this . task . requesterId ) . put ( "sensitive" , false ) . put ( "anonymous" , false ) ) ) ) ; checkIncentiveTransactionStatus . add ( this . createIncentiveServerTaskTransactionStatusPredicate ( ) . and ( TaskTransactionStatusBodyPredicates . labelIs ( "QuestionToAnswerMessage" ) ) . and ( transaction -> this . participants . contains ( transaction . user_id ) ) . and ( TaskTransactionStatusBodyPredicates . countIs ( 1 ) ) ) ; checkSocialNotification . add ( this . createSocialNotificationPredicate ( ) . and ( UserMessagePredicates . senderId ( this . task . requesterId ) ) . and ( UserMessagePredicates . transactionId ( transactionId ) ) . and ( UserMessagePredicates . message ( this . createMessagePredicate ( ) . and ( MessagePredicates . labelIs ( "QuestionToAnswerMessage" ) ) . and ( msg -> this . participants . contains ( msg . receiverId ) ) . and ( MessagePredicates . attributesSimilarTo ( new JsonObject ( ) . put ( "taskId" , this . task . id ) . put ( "question" , this . task . goal . name ) . put ( "userId" , this . task . requesterId ) . put ( "sensitive" , false ) . put ( "anonymous" , false ) ) ) ) ) ) ; checkInteractions . add ( this . createInteractionPredicate ( ) . and ( InteractionPredicates . senderIs ( this . task . requesterId ) ) . and ( InteractionPredicates . transactionLabelIs ( "moreAnswerTransaction" ) ) . and ( interaction -> this . participants . contains ( interaction . receiverId ) ) . and ( InteractionPredicates . messageLabelIs ( "QuestionToAnswerMessage" ) ) ) ; } final var moreAnswerTransaction = new TaskTransaction ( ) ; moreAnswerTransaction . taskId = this . task . id ; moreAnswerTransaction . actioneerId = this . task . requesterId ; moreAnswerTransaction . label = "moreAnswerTransaction" ; final var checkTask = this . createTaskPredicate ( ) . and ( TaskPredicates . lastTransactionIs ( this . createTaskTransactionPredicate ( ) . and ( TaskTransactionPredicates . similarTo ( moreAnswerTransaction ) ) . and ( TaskTransactionPredicates . messagesSizeIs ( maxUsers ) ) . and ( TaskTransactionPredicates . containsMessages ( checkMessages ) ) ) ) ; final Future < ? > future = WeNetTaskManager . createProxy ( vertx ) . doTaskTransaction ( moreAnswerTransaction ) . compose ( ignored -> this . waitUntilTask ( vertx , testContext , checkTask ) ) . compose ( ignored -> this . waitUntilCallbacks ( vertx , testContext , checkMessages ) ) . compose ( ignored -> this . waitUntilIncentiveServerHasTaskTransactionStatus ( vertx , testContext , checkIncentiveTransactionStatus ) ) . compose ( ignored -> this . waitUntilSocialNotification ( vertx , testContext , checkSocialNotification ) ) . compose ( ignored -> this . waitUntilInteractions ( vertx , testContext , checkInteractions ) ) ; future . onComplete ( testContext . succeeding ( ignored -> testContext . verify ( ( ) -> { assertThat ( this . participants ) . hasSize ( 8 ) ; this . assertSuccessfulCompleted ( testContext ) ; } ) ) ) ; }
Check that the requester can ask for more answers.
Check that the requester can ask for more answers .
// Undefined user