protocols/src/test/java/eu/internetofus/common/protocols/Ask4HelpV1_2ProtocolITC.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>>();
    for (final var user : this.users) {
      if (!user.id.equals(source.requesterId)) {
        checkMessages.add(this.createMessagePredicate().and(MessagePredicates.labelIs("QuestionToAnswerMessage"))
            .and(MessagePredicates.receiverIs(user.id))
            .and(MessagePredicates.attributesSimilarTo(
                new JsonObject().put("question", source.goal.name).put("userId", source.requesterId)))
            .and(MessagePredicates.attributesAre(target -> {
              return this.task.id.equals(target.getString("taskId"));
            })));
        checkIncentiveTransactionStatus.add(this.createIncentiveServerTaskTransactionStatusPredicate()
            .and(TaskTransactionStatusBodyPredicates.labelIs("QuestionToAnswerMessage"))
            .and(TaskTransactionStatusBodyPredicates.userIs(user.id))
            .and(TaskTransactionStatusBodyPredicates.countIs(1)));
      } else {
        checkIncentiveTypeStatus.add(this.createIncentiveServerTaskTypeStatusPredicate()
            .and(TaskTypeStatusBodyPredicates.userIs(user.id)).and(TaskTypeStatusBodyPredicates.countIs(1)));
      }
    }
    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(this.users.size() - 1))
                .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));
    future.onComplete(testContext.succeeding(ignored -> 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 > > ( ) ; for ( final var user : this . users ) { if ( ! user . id . equals ( source . requesterId ) ) { checkMessages . add ( this . createMessagePredicate ( ) . and ( MessagePredicates . labelIs ( "QuestionToAnswerMessage" ) ) . and ( MessagePredicates . receiverIs ( user . id ) ) . and ( MessagePredicates . attributesSimilarTo ( new JsonObject ( ) . put ( "question" , source . goal . name ) . put ( "userId" , source . requesterId ) ) ) . and ( MessagePredicates . attributesAre ( target -> { return this . task . id . equals ( target . getString ( "taskId" ) ) ; } ) ) ) ; checkIncentiveTransactionStatus . add ( this . createIncentiveServerTaskTransactionStatusPredicate ( ) . and ( TaskTransactionStatusBodyPredicates . labelIs ( "QuestionToAnswerMessage" ) ) . and ( TaskTransactionStatusBodyPredicates . userIs ( user . id ) ) . and ( TaskTransactionStatusBodyPredicates . countIs ( 1 ) ) ) ; } else { checkIncentiveTypeStatus . add ( this . createIncentiveServerTaskTypeStatusPredicate ( ) . and ( TaskTypeStatusBodyPredicates . userIs ( user . id ) ) . and ( TaskTypeStatusBodyPredicates . countIs ( 1 ) ) ) ; } } 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 ( this . users . size ( ) - 1 ) ) . 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 ) ) ; future . onComplete ( testContext . succeeding ( ignored -> this . assertSuccessfulCompleted ( testContext ) ) ) ; }
Check that a task is created.
Check that a task is created .