protocols/src/test/java/eu/internetofus/common/protocols/Ask4HelpV1_2ProtocolITC.java
/**
   * Check that can rank the answers.
   *
   * @param vertx       event bus to use.
   * @param testContext context to do the test.
   */
Check that can rank the answers.
@param vertx       event bus to use.
@param testContext context to do the test.
Check that can rank the answers . @param vertx event bus to use . @param testContext context to do the test .
@Test
  @Order(11)
  public void shouldRankAnswers(final Vertx vertx, final VertxTestContext testContext) {
    this.assertLastSuccessfulTestWas(6, testContext);
    this.lastSuccessfulTest = 10;
    final var transaction = new TaskTransaction();
    transaction.actioneerId = this.task.requesterId;
    transaction.taskId = this.task.id;
    transaction.label = "rankAnswers";
    final var ranking = new JsonArray();
    for (final var done : this.task.transactions) {
      if (done.label.equals("answerTransaction")) {
        final var userId = done.actioneerId;
        final var answer = done.attributes.getString("answer", "");
        ranking.add(new JsonObject().put("userId", userId).put("answer", answer));
      }
    }
    final var checkMessages = new ArrayList<Predicate<Message>>();
    final var checkMessage = this.createMessagePredicate().and(MessagePredicates.labelIs("AnswersRanking"))
        .and(MessagePredicates.receiverIs(this.task.requesterId)).and(MessagePredicates
            .attributesSimilarTo(new JsonObject().put("taskId", this.task.id).put("ranking", ranking)));
    checkMessages.add(checkMessage);
    final var checkTask = this.createTaskPredicate().and(TaskPredicates.lastTransactionIs(
        this.createTaskTransactionPredicate().and(TaskTransactionPredicates.similarTo(transaction))));
    final var checkStatus = new ArrayList<Predicate<TaskTransactionStatusBody>>();
    checkStatus.add(this.createIncentiveServerTaskTransactionStatusPredicate()
        .and(TaskTransactionStatusBodyPredicates.labelIs(transaction.label))
        .and(TaskTransactionStatusBodyPredicates.countIs(1))
        .and(TaskTransactionStatusBodyPredicates.userIs(transaction.actioneerId)));
    final var future = WeNetTaskManager.createProxy(vertx).doTaskTransaction(transaction)
        .compose(ignored -> this.waitUntilTask(vertx, testContext, checkTask))
        .compose(ignored -> this.waitUntilIncentiveServerHasTaskTransactionStatus(vertx, testContext, checkStatus))
        .compose(ignored -> this.waitUntilCallbacks(vertx, testContext, checkMessages));
    future.onComplete(testContext.succeeding(ignored -> this.assertSuccessfulCompleted(testContext)));
  }
@ Test @ Order ( 11 ) public void shouldRankAnswers ( final Vertx vertx , final VertxTestContext testContext ) { this . assertLastSuccessfulTestWas ( 6 , testContext ) ; this . lastSuccessfulTest = 10 ; final var transaction = new TaskTransaction ( ) ; transaction . actioneerId = this . task . requesterId ; transaction . taskId = this . task . id ; transaction . label = "rankAnswers" ; final var ranking = new JsonArray ( ) ; for ( final var done : this . task . transactions ) { if ( done . label . equals ( "answerTransaction" ) ) { final var userId = done . actioneerId ; final var answer = done . attributes . getString ( "answer" , "" ) ; ranking . add ( new JsonObject ( ) . put ( "userId" , userId ) . put ( "answer" , answer ) ) ; } } final var checkMessages = new ArrayList < Predicate < Message > > ( ) ; final var checkMessage = this . createMessagePredicate ( ) . and ( MessagePredicates . labelIs ( "AnswersRanking" ) ) . and ( MessagePredicates . receiverIs ( this . task . requesterId ) ) . and ( MessagePredicates . attributesSimilarTo ( new JsonObject ( ) . put ( "taskId" , this . task . id ) . put ( "ranking" , ranking ) ) ) ; checkMessages . add ( checkMessage ) ; final var checkTask = this . createTaskPredicate ( ) . and ( TaskPredicates . lastTransactionIs ( this . createTaskTransactionPredicate ( ) . and ( TaskTransactionPredicates . similarTo ( transaction ) ) ) ) ; final var checkStatus = new ArrayList < Predicate < TaskTransactionStatusBody > > ( ) ; checkStatus . add ( this . createIncentiveServerTaskTransactionStatusPredicate ( ) . and ( TaskTransactionStatusBodyPredicates . labelIs ( transaction . label ) ) . and ( TaskTransactionStatusBodyPredicates . countIs ( 1 ) ) . and ( TaskTransactionStatusBodyPredicates . userIs ( transaction . actioneerId ) ) ) ; final var future = WeNetTaskManager . createProxy ( vertx ) . doTaskTransaction ( transaction ) . compose ( ignored -> this . waitUntilTask ( vertx , testContext , checkTask ) ) . compose ( ignored -> this . waitUntilIncentiveServerHasTaskTransactionStatus ( vertx , testContext , checkStatus ) ) . compose ( ignored -> this . waitUntilCallbacks ( vertx , testContext , checkMessages ) ) ; future . onComplete ( testContext . succeeding ( ignored -> this . assertSuccessfulCompleted ( testContext ) ) ) ; }
Check that can rank the answers.
Check that can rank the answers .