protocols/src/test/java/eu/internetofus/common/protocols/AbstractAsk4HelpV2_2ProtocolRandomUsersITC.java
/**
   * Check that a task is created.
   *
   * @param vertx       event bus to use.
   * @param testContext context to do the test.
   */
Check that a task is created.
@param vertx       event bus to use.
@param testContext context to do the test.
Check that a task is created . @param vertx event bus to use . @param testContext context to do the test .
@Test
  @Order(5)
  public void shouldCreateTask(final Vertx vertx, final VertxTestContext testContext) {
    this.assertLastSuccessfulTestWas(4, testContext);
    final var source = this.createTaskForProtocol();
    final var checkMessages = new ArrayList<Predicate<Message>>();
    final var checkIncentiveTypeStatus = new ArrayList<Predicate<TaskTypeStatusBody>>();
    final var checkIncentiveTransactionStatus = new ArrayList<Predicate<TaskTransactionStatusBody>>();
    final var checkSocialNotification = new ArrayList<Predicate<UserMessage>>();
    final var checkInteractions = new ArrayList<Predicate<Interaction>>();
    checkIncentiveTypeStatus.add(this.createIncentiveServerTaskTypeStatusPredicate()
        .and(TaskTypeStatusBodyPredicates.userIs(source.requesterId)).and(TaskTypeStatusBodyPredicates.countIs(1)));
    final var maxUsers = source.attributes.getInteger("maxUsers");
    for (var i = 0; i < maxUsers; i++) {
      checkMessages
          .add(this.createMessagePredicate().and(MessagePredicates.labelIs("QuestionToAnswerMessage")).and(msg -> {
            if (this.getUserbyId(msg.receiverId) == null) {
              return false;
            }
            this.participants.add(msg.receiverId);
            return true;
          }).and(MessagePredicates.attributesSimilarTo(new JsonObject().put("question", source.goal.name)
              .put("userId", source.requesterId).put("sensitive", false).put("anonymous", false)))
              .and(MessagePredicates.attributesAre(target -> {
                return this.task.id.equals(target.getString("taskId"));
              })));
      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(msg -> {
        if (this.task == null) {
          return false;
        }
        return UserMessagePredicates.senderId(this.task.requesterId).test(msg);
      }).and(UserMessagePredicates.transactionId("0"))
          .and(UserMessagePredicates
              .message(this.createMessagePredicate().and(MessagePredicates.labelIs("QuestionToAnswerMessage"))
                  .and(msg -> this.participants.contains(msg.receiverId))
                  .and(MessagePredicates.attributesSimilarTo(new JsonObject().put("question", source.goal.name)
                      .put("userId", source.requesterId).put("sensitive", false).put("anonymous", false)))
                  .and(MessagePredicates.attributesAre(target -> {
                    return this.task.id.equals(target.getString("taskId"));
                  })))));
      checkInteractions.add(this.createInteractionPredicate().and(InteractionPredicates.senderIs(source.requesterId))
          .and(InteractionPredicates.transactionLabelIs(TaskTransaction.CREATE_TASK_LABEL))
          .and(interaction -> this.participants.contains(interaction.receiverId))
          .and(InteractionPredicates.messageLabelIs("QuestionToAnswerMessage")));
    }
    final var createTransaction = new TaskTransaction();
    createTransaction.label = TaskTransaction.CREATE_TASK_LABEL;
    createTransaction.actioneerId = source.requesterId;
    final var checkTask = this.createTaskPredicate().and(TaskPredicates.similarTo(source))
        .and(TaskPredicates.transactionSizeIs(1))
        .and(TaskPredicates.transactionAt(0,
            this.createTaskTransactionPredicate().and(TaskTransactionPredicates.similarTo(createTransaction))
                .and(TaskTransactionPredicates.messagesSizeIs(maxUsers))
                .and(TaskTransactionPredicates.containsMessages(checkMessages))));
    final Future<?> future = this.waitUntilTaskCreated(source, vertx, testContext, checkTask)
        .compose(ignored -> this.waitUntilCallbacks(vertx, testContext, checkMessages))
        .compose(
            ignored -> this.waitUntilIncentiveServerHasTaskTypeStatus(vertx, testContext, checkIncentiveTypeStatus))
        .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(5);
      this.assertSuccessfulCompleted(testContext);
    })));
  }
@ Test @ Order ( 5 ) public void shouldCreateTask ( final Vertx vertx , final VertxTestContext testContext ) { this . assertLastSuccessfulTestWas ( 4 , testContext ) ; final var source = this . createTaskForProtocol ( ) ; final var checkMessages = new ArrayList < Predicate < Message > > ( ) ; final var checkIncentiveTypeStatus = new ArrayList < Predicate < TaskTypeStatusBody > > ( ) ; final var checkIncentiveTransactionStatus = new ArrayList < Predicate < TaskTransactionStatusBody > > ( ) ; final var checkSocialNotification = new ArrayList < Predicate < UserMessage > > ( ) ; final var checkInteractions = new ArrayList < Predicate < Interaction > > ( ) ; checkIncentiveTypeStatus . add ( this . createIncentiveServerTaskTypeStatusPredicate ( ) . and ( TaskTypeStatusBodyPredicates . userIs ( source . requesterId ) ) . and ( TaskTypeStatusBodyPredicates . countIs ( 1 ) ) ) ; final var maxUsers = source . attributes . getInteger ( "maxUsers" ) ; for ( var i = 0 ; i < maxUsers ; i ++ ) { checkMessages . add ( this . createMessagePredicate ( ) . and ( MessagePredicates . labelIs ( "QuestionToAnswerMessage" ) ) . and ( msg -> { if ( this . getUserbyId ( msg . receiverId ) == null ) { return false ; } this . participants . add ( msg . receiverId ) ; return true ; } ) . and ( MessagePredicates . attributesSimilarTo ( new JsonObject ( ) . put ( "question" , source . goal . name ) . put ( "userId" , source . requesterId ) . put ( "sensitive" , false ) . put ( "anonymous" , false ) ) ) . and ( MessagePredicates . attributesAre ( target -> { return this . task . id . equals ( target . getString ( "taskId" ) ) ; } ) ) ) ; 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 ( msg -> { if ( this . task == null ) { return false ; } return UserMessagePredicates . senderId ( this . task . requesterId ) . test ( msg ) ; } ) . and ( UserMessagePredicates . transactionId ( "0" ) ) . and ( UserMessagePredicates . message ( this . createMessagePredicate ( ) . and ( MessagePredicates . labelIs ( "QuestionToAnswerMessage" ) ) . and ( msg -> this . participants . contains ( msg . receiverId ) ) . and ( MessagePredicates . attributesSimilarTo ( new JsonObject ( ) . put ( "question" , source . goal . name ) . put ( "userId" , source . requesterId ) . put ( "sensitive" , false ) . put ( "anonymous" , false ) ) ) . and ( MessagePredicates . attributesAre ( target -> { return this . task . id . equals ( target . getString ( "taskId" ) ) ; } ) ) ) ) ) ; checkInteractions . add ( this . createInteractionPredicate ( ) . and ( InteractionPredicates . senderIs ( source . requesterId ) ) . and ( InteractionPredicates . transactionLabelIs ( TaskTransaction . CREATE_TASK_LABEL ) ) . and ( interaction -> this . participants . contains ( interaction . receiverId ) ) . and ( InteractionPredicates . messageLabelIs ( "QuestionToAnswerMessage" ) ) ) ; } final var createTransaction = new TaskTransaction ( ) ; createTransaction . label = TaskTransaction . CREATE_TASK_LABEL ; createTransaction . actioneerId = source . requesterId ; final var checkTask = this . createTaskPredicate ( ) . and ( TaskPredicates . similarTo ( source ) ) . and ( TaskPredicates . transactionSizeIs ( 1 ) ) . and ( TaskPredicates . transactionAt ( 0 , this . createTaskTransactionPredicate ( ) . and ( TaskTransactionPredicates . similarTo ( createTransaction ) ) . and ( TaskTransactionPredicates . messagesSizeIs ( maxUsers ) ) . and ( TaskTransactionPredicates . containsMessages ( checkMessages ) ) ) ) ; final Future < ? > future = this . waitUntilTaskCreated ( source , vertx , testContext , checkTask ) . compose ( ignored -> this . waitUntilCallbacks ( vertx , testContext , checkMessages ) ) . compose ( ignored -> this . waitUntilIncentiveServerHasTaskTypeStatus ( vertx , testContext , checkIncentiveTypeStatus ) ) . 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 ( 5 ) ; this . assertSuccessfulCompleted ( testContext ) ; } ) ) ) ; }
Check that a task is created.
Check that a task is created .
// Undefined user