protocols/src/test/java/eu/internetofus/common/protocols/AbstractAsk4HelpV2_2ProtocolRandomUsersITC.java
/**
   * Check that pick best answer.
   *
   * @param vertx       event bus to use.
   * @param testContext context to do the test.
   */
Check that pick best answer.
@param vertx       event bus to use.
@param testContext context to do the test.
Check that pick best answer . @param vertx event bus to use . @param testContext context to do the test .
@Test
  @Order(11)
  public void shouldBestAnswerTransaction(final Vertx vertx, final VertxTestContext testContext) {
    this.assertLastSuccessfulTestWas(6, testContext);
    this.lastSuccessfulTest = 10;
    final var bestAnswerTransaction = new TaskTransaction();
    bestAnswerTransaction.taskId = this.task.id;
    bestAnswerTransaction.actioneerId = this.task.requesterId;
    bestAnswerTransaction.label = "bestAnswerTransaction";
    final var selectedTransaction = this.task.transactions.get(2);
    bestAnswerTransaction.attributes = new JsonObject().put("transactionId", selectedTransaction.id)
        .put("reason", "I love it").put("helpful", "extremelyHelpful");
    final var checkMessages = new ArrayList<Predicate<Message>>();
    final var checkMessage = this.createMessagePredicate().and(MessagePredicates.labelIs("AnsweredPickedMessage"))
        .and(MessagePredicates.receiverIs(selectedTransaction.actioneerId))
        .and(MessagePredicates.attributesSimilarTo(new JsonObject().put("taskId", this.task.id)
            .put("question", this.task.goal.name).put("transactionId", selectedTransaction.id)));
    checkMessages.add(checkMessage);
    final var checkTask = this.createTaskPredicate().and(TaskPredicates.lastTransactionIs(this
        .createTaskTransactionPredicate().and(TaskTransactionPredicates.similarTo(bestAnswerTransaction))
        .and(TaskTransactionPredicates.messagesSizeIs(1)).and(TaskTransactionPredicates.messageAt(0, checkMessage))))
        .and(TaskPredicates.isClosed());
    final var checkStatus = new ArrayList<Predicate<TaskTransactionStatusBody>>();
    checkStatus.add(this.createIncentiveServerTaskTransactionStatusPredicate()
        .and(TaskTransactionStatusBodyPredicates.userIs(bestAnswerTransaction.actioneerId))
        .and(TaskTransactionStatusBodyPredicates.labelIs(bestAnswerTransaction.label))
        .and(TaskTransactionStatusBodyPredicates.countIs(1)));
    checkStatus.add(this.createIncentiveServerTaskTransactionStatusPredicate()
        .and(TaskTransactionStatusBodyPredicates.userIs(selectedTransaction.actioneerId))
        .and(TaskTransactionStatusBodyPredicates.labelIs("AnsweredPickedMessage"))
        .and(TaskTransactionStatusBodyPredicates.countIs(1)));
    final var checkSocialNotification = new ArrayList<Predicate<UserMessage>>();
    checkSocialNotification
        .add(this.createSocialNotificationPredicate().and(UserMessagePredicates.senderId(this.task.requesterId))
            .and(UserMessagePredicates.transactionId(String.valueOf(this.task.transactions.size())))
            .and(UserMessagePredicates.message(checkMessage)));
    final var checkInteractions = new ArrayList<Predicate<Interaction>>();
    checkInteractions
        .add(this.createInteractionPredicate().and(InteractionPredicates.senderIs(bestAnswerTransaction.actioneerId))
            .and(InteractionPredicates.transactionLabelIs(bestAnswerTransaction.label))
            .and(InteractionPredicates.transactionAttributesAre(bestAnswerTransaction.attributes))
            .and(InteractionPredicates.receiverIs(selectedTransaction.actioneerId))
            .and(InteractionPredicates.messageLabelIs("AnsweredPickedMessage"))
            .and(InteractionPredicates.messageAttributesSimilarTo(new JsonObject().put("taskId", this.task.id)
                .put("question", this.task.goal.name).put("transactionId", selectedTransaction.id))));
    final Future<?> future = WeNetTaskManager.createProxy(vertx).doTaskTransaction(bestAnswerTransaction)
        .compose(ignored -> this.waitUntilTask(vertx, testContext, checkTask))
        .compose(ignored -> this.waitUntilCallbacks(vertx, testContext, checkMessages))
        .compose(ignored -> this.waitUntilIncentiveServerHasTaskTransactionStatus(vertx, testContext, checkStatus))
        .compose(ignored -> this.waitUntilSocialNotification(vertx, testContext, checkSocialNotification))
        .compose(ignored -> this.waitUntilInteractions(vertx, testContext, checkInteractions));
    future.onComplete(testContext.succeeding(ignored -> this.assertSuccessfulCompleted(testContext)));
  }
@ Test @ Order ( 11 ) public void shouldBestAnswerTransaction ( final Vertx vertx , final VertxTestContext testContext ) { this . assertLastSuccessfulTestWas ( 6 , testContext ) ; this . lastSuccessfulTest = 10 ; final var bestAnswerTransaction = new TaskTransaction ( ) ; bestAnswerTransaction . taskId = this . task . id ; bestAnswerTransaction . actioneerId = this . task . requesterId ; bestAnswerTransaction . label = "bestAnswerTransaction" ; final var selectedTransaction = this . task . transactions . get ( 2 ) ; bestAnswerTransaction . attributes = new JsonObject ( ) . put ( "transactionId" , selectedTransaction . id ) . put ( "reason" , "I love it" ) . put ( "helpful" , "extremelyHelpful" ) ; final var checkMessages = new ArrayList < Predicate < Message > > ( ) ; final var checkMessage = this . createMessagePredicate ( ) . and ( MessagePredicates . labelIs ( "AnsweredPickedMessage" ) ) . and ( MessagePredicates . receiverIs ( selectedTransaction . actioneerId ) ) . and ( MessagePredicates . attributesSimilarTo ( new JsonObject ( ) . put ( "taskId" , this . task . id ) . put ( "question" , this . task . goal . name ) . put ( "transactionId" , selectedTransaction . id ) ) ) ; checkMessages . add ( checkMessage ) ; final var checkTask = this . createTaskPredicate ( ) . and ( TaskPredicates . lastTransactionIs ( this . createTaskTransactionPredicate ( ) . and ( TaskTransactionPredicates . similarTo ( bestAnswerTransaction ) ) . and ( TaskTransactionPredicates . messagesSizeIs ( 1 ) ) . and ( TaskTransactionPredicates . messageAt ( 0 , checkMessage ) ) ) ) . and ( TaskPredicates . isClosed ( ) ) ; final var checkStatus = new ArrayList < Predicate < TaskTransactionStatusBody > > ( ) ; checkStatus . add ( this . createIncentiveServerTaskTransactionStatusPredicate ( ) . and ( TaskTransactionStatusBodyPredicates . userIs ( bestAnswerTransaction . actioneerId ) ) . and ( TaskTransactionStatusBodyPredicates . labelIs ( bestAnswerTransaction . label ) ) . and ( TaskTransactionStatusBodyPredicates . countIs ( 1 ) ) ) ; checkStatus . add ( this . createIncentiveServerTaskTransactionStatusPredicate ( ) . and ( TaskTransactionStatusBodyPredicates . userIs ( selectedTransaction . actioneerId ) ) . and ( TaskTransactionStatusBodyPredicates . labelIs ( "AnsweredPickedMessage" ) ) . and ( TaskTransactionStatusBodyPredicates . countIs ( 1 ) ) ) ; final var checkSocialNotification = new ArrayList < Predicate < UserMessage > > ( ) ; checkSocialNotification . add ( this . createSocialNotificationPredicate ( ) . and ( UserMessagePredicates . senderId ( this . task . requesterId ) ) . and ( UserMessagePredicates . transactionId ( String . valueOf ( this . task . transactions . size ( ) ) ) ) . and ( UserMessagePredicates . message ( checkMessage ) ) ) ; final var checkInteractions = new ArrayList < Predicate < Interaction > > ( ) ; checkInteractions . add ( this . createInteractionPredicate ( ) . and ( InteractionPredicates . senderIs ( bestAnswerTransaction . actioneerId ) ) . and ( InteractionPredicates . transactionLabelIs ( bestAnswerTransaction . label ) ) . and ( InteractionPredicates . transactionAttributesAre ( bestAnswerTransaction . attributes ) ) . and ( InteractionPredicates . receiverIs ( selectedTransaction . actioneerId ) ) . and ( InteractionPredicates . messageLabelIs ( "AnsweredPickedMessage" ) ) . and ( InteractionPredicates . messageAttributesSimilarTo ( new JsonObject ( ) . put ( "taskId" , this . task . id ) . put ( "question" , this . task . goal . name ) . put ( "transactionId" , selectedTransaction . id ) ) ) ) ; final Future < ? > future = WeNetTaskManager . createProxy ( vertx ) . doTaskTransaction ( bestAnswerTransaction ) . compose ( ignored -> this . waitUntilTask ( vertx , testContext , checkTask ) ) . compose ( ignored -> this . waitUntilCallbacks ( vertx , testContext , checkMessages ) ) . compose ( ignored -> this . waitUntilIncentiveServerHasTaskTransactionStatus ( vertx , testContext , checkStatus ) ) . compose ( ignored -> this . waitUntilSocialNotification ( vertx , testContext , checkSocialNotification ) ) . compose ( ignored -> this . waitUntilInteractions ( vertx , testContext , checkInteractions ) ) ; future . onComplete ( testContext . succeeding ( ignored -> this . assertSuccessfulCompleted ( testContext ) ) ) ; }
Check that pick best answer.
Check that pick best answer .