protocols/src/test/java/eu/internetofus/common/protocols/Ask4HelpV1_2ProtocolITC.java
/**
   * Check that pick the best answer.
   *
   * @param vertx       event bus to use.
   * @param testContext context to do the test.
   */
Check that pick the best answer.
@param vertx       event bus to use.
@param testContext context to do the test.
Check that pick the best answer . @param vertx event bus to use . @param testContext context to do the test .
@Test
  @Order(12)
  public void shouldBestAnswer(final Vertx vertx, final VertxTestContext testContext) {
    this.assertLastSuccessfulTestWas(6, testContext);
    this.lastSuccessfulTest = 11;
    final var transaction = new TaskTransaction();
    transaction.actioneerId = this.task.requesterId;
    transaction.taskId = this.task.id;
    transaction.label = "bestAnswerTransaction";
    transaction.attributes = new JsonObject().put("transactionId", this.task.transactions.get(3).id).put("reason",
        "Reason msg");
    final var checkMessages = new ArrayList<Predicate<Message>>();
    final var checkMessage = this.createMessagePredicate().and(MessagePredicates.labelIs("AnsweredPickedMessage"))
        .and(MessagePredicates.receiverIs(this.task.transactions.get(3).actioneerId))
        .and(MessagePredicates.attributesSimilarTo(
            new JsonObject().put("taskId", this.task.id).put("transactionId", this.task.transactions.get(3).id)));
    checkMessages.add(checkMessage);
    final var checkTask = this.createTaskPredicate().and(TaskPredicates.isClosed())
        .and(TaskPredicates.lastTransactionIs(this.createTaskTransactionPredicate()
            .and(TaskTransactionPredicates.similarTo(transaction)).and(TaskTransactionPredicates.messagesSizeIs(1))
            .and(TaskTransactionPredicates.messageAt(0, checkMessage))));
    final var checkStatus = new ArrayList<Predicate<TaskTransactionStatusBody>>();
    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.transactions.get(3).actioneerId))
        .and(TaskTransactionStatusBodyPredicates.labelIs("AnsweredPickedMessage"))
        .and(TaskTransactionStatusBodyPredicates.countIs(1)));
    final var future = WeNetTaskManager.createProxy(vertx).doTaskTransaction(transaction)
        .compose(ignored -> this.waitUntilTask(vertx, testContext, checkTask))
        .compose(ignored -> this.waitUntilCallbacks(vertx, testContext, checkMessages))
        .compose(ignored -> this.waitUntilIncentiveServerHasTaskTransactionStatus(vertx, testContext, checkStatus))
        .compose(ignored -> this.waitUntil(vertx, testContext,
            () -> WeNetSocialContextBuilderSimulator.createProxy(vertx)
                .getSocialPreferencesSelectedAnswerForUserOnTask(transaction.actioneerId, this.task.id, 2),
            any -> true));
    future.onComplete(testContext.succeeding(ignored -> this.assertSuccessfulCompleted(testContext)));
  }
@ Test @ Order ( 12 ) public void shouldBestAnswer ( final Vertx vertx , final VertxTestContext testContext ) { this . assertLastSuccessfulTestWas ( 6 , testContext ) ; this . lastSuccessfulTest = 11 ; final var transaction = new TaskTransaction ( ) ; transaction . actioneerId = this . task . requesterId ; transaction . taskId = this . task . id ; transaction . label = "bestAnswerTransaction" ; transaction . attributes = new JsonObject ( ) . put ( "transactionId" , this . task . transactions . get ( 3 ) . id ) . put ( "reason" , "Reason msg" ) ; final var checkMessages = new ArrayList < Predicate < Message > > ( ) ; final var checkMessage = this . createMessagePredicate ( ) . and ( MessagePredicates . labelIs ( "AnsweredPickedMessage" ) ) . and ( MessagePredicates . receiverIs ( this . task . transactions . get ( 3 ) . actioneerId ) ) . and ( MessagePredicates . attributesSimilarTo ( new JsonObject ( ) . put ( "taskId" , this . task . id ) . put ( "transactionId" , this . task . transactions . get ( 3 ) . id ) ) ) ; checkMessages . add ( checkMessage ) ; final var checkTask = this . createTaskPredicate ( ) . and ( TaskPredicates . isClosed ( ) ) . and ( TaskPredicates . lastTransactionIs ( this . createTaskTransactionPredicate ( ) . and ( TaskTransactionPredicates . similarTo ( transaction ) ) . and ( TaskTransactionPredicates . messagesSizeIs ( 1 ) ) . and ( TaskTransactionPredicates . messageAt ( 0 , checkMessage ) ) ) ) ; final var checkStatus = new ArrayList < Predicate < TaskTransactionStatusBody > > ( ) ; 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 . transactions . get ( 3 ) . actioneerId ) ) . and ( TaskTransactionStatusBodyPredicates . labelIs ( "AnsweredPickedMessage" ) ) . and ( TaskTransactionStatusBodyPredicates . countIs ( 1 ) ) ) ; final var future = WeNetTaskManager . createProxy ( vertx ) . doTaskTransaction ( transaction ) . compose ( ignored -> this . waitUntilTask ( vertx , testContext , checkTask ) ) . compose ( ignored -> this . waitUntilCallbacks ( vertx , testContext , checkMessages ) ) . compose ( ignored -> this . waitUntilIncentiveServerHasTaskTransactionStatus ( vertx , testContext , checkStatus ) ) . compose ( ignored -> this . waitUntil ( vertx , testContext , ( ) -> WeNetSocialContextBuilderSimulator . createProxy ( vertx ) . getSocialPreferencesSelectedAnswerForUserOnTask ( transaction . actioneerId , this . task . id , 2 ) , any -> true ) ) ; future . onComplete ( testContext . succeeding ( ignored -> this . assertSuccessfulCompleted ( testContext ) ) ) ; }
Check that pick the best answer.
Check that pick the best answer .