protocols/src/test/java/eu/internetofus/common/protocols/Ask4HelpV2ProtocolWithAllFiltersITC.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(8)
  public void shouldCreateTask(final Vertx vertx, final VertxTestContext testContext) {
    this.assertLastSuccessfulTestWas(7, testContext);
    final var source = this.createTaskForProtocol();
    final var checkMessages = new ArrayList<Predicate<Message>>();
    final var maxUsers = source.attributes.getInteger("maxUsers");
    final var whoToAskUsers = this.expectedState.getJsonArray("whoToAskUsers");
    for (var i = 0; i < maxUsers; i++) {
      final var receiverId = whoToAskUsers.getJsonObject(i).getString("userId");
      checkMessages.add(this.createMessagePredicateForQuestionToAnswerMessageBy(receiverId));
    }
    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.waitUntilUserTaskState(source.requesterId, vertx, testContext, userTaskState -> {
          if (userTaskState.attributes != null) {
            return this.assertExpectedTaskStateAttribute(userTaskState, "whoToAskUsers", true)
                && this.assertExpectedTaskStateAttribute(userTaskState, "closenessUsers", false)
                && this.assertExpectedTaskStateAttribute(userTaskState, "socialClosenessUsers", false)
                && this.assertExpectedTaskStateAttribute(userTaskState, "beliefsAndValuesUsers", false)
                && this.assertExpectedTaskStateAttribute(userTaskState, "domainInterestUsers", false)
                && this.assertExpectedTaskStateAttribute(userTaskState, "unaskedUserIds", true);
          } else {
            return false;
          }
        }));
    future.onComplete(testContext.succeeding(ignored -> this.assertSuccessfulCompleted(testContext)));
  }
@ Test @ Order ( 8 ) public void shouldCreateTask ( final Vertx vertx , final VertxTestContext testContext ) { this . assertLastSuccessfulTestWas ( 7 , testContext ) ; final var source = this . createTaskForProtocol ( ) ; final var checkMessages = new ArrayList < Predicate < Message > > ( ) ; final var maxUsers = source . attributes . getInteger ( "maxUsers" ) ; final var whoToAskUsers = this . expectedState . getJsonArray ( "whoToAskUsers" ) ; for ( var i = 0 ; i < maxUsers ; i ++ ) { final var receiverId = whoToAskUsers . getJsonObject ( i ) . getString ( "userId" ) ; checkMessages . add ( this . createMessagePredicateForQuestionToAnswerMessageBy ( receiverId ) ) ; } 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 . waitUntilUserTaskState ( source . requesterId , vertx , testContext , userTaskState -> { if ( userTaskState . attributes != null ) { return this . assertExpectedTaskStateAttribute ( userTaskState , "whoToAskUsers" , true ) && this . assertExpectedTaskStateAttribute ( userTaskState , "closenessUsers" , false ) && this . assertExpectedTaskStateAttribute ( userTaskState , "socialClosenessUsers" , false ) && this . assertExpectedTaskStateAttribute ( userTaskState , "beliefsAndValuesUsers" , false ) && this . assertExpectedTaskStateAttribute ( userTaskState , "domainInterestUsers" , false ) && this . assertExpectedTaskStateAttribute ( userTaskState , "unaskedUserIds" , true ) ; } else { return false ; } } ) ) ; future . onComplete ( testContext . succeeding ( ignored -> this . assertSuccessfulCompleted ( testContext ) ) ) ; }
Check that a task is created.
Check that a task is created .