protocols/src/test/java/eu/internetofus/common/protocols/EatTogetherV2ProtocolITC.java
/**
   * Check that an user can be accepted to be volunteer.
   *
   * @param vertx       event bus to use.
   * @param testContext context to do the test.
   */
Check that an user can be accepted to be volunteer.
@param vertx       event bus to use.
@param testContext context to do the test.
Check that an user can be accepted to be volunteer . @param vertx event bus to use . @param testContext context to do the test .
@Test
  @Order(10)
  public void shouldAcceptVolunteer(final Vertx vertx, final VertxTestContext testContext) {
    this.assertLastSuccessfulTestWas(9, testContext);
    final var taskTransaction = new TaskTransaction();
    taskTransaction.actioneerId = this.task.requesterId;
    taskTransaction.taskId = this.task.id;
    taskTransaction.label = "acceptVolunteer";
    final var volunteerId = this.users.get(2).id;
    taskTransaction.attributes = new JsonObject().put("volunteerId", volunteerId);
    final var attributes = this.task.attributes.copy();
    attributes.getJsonArray("volunteers").remove(volunteerId);
    attributes.put("accepted", new JsonArray().add(volunteerId));
    final var checkMessage = this.createMessagePredicate().and(MessagePredicates.labelIs("TaskSelectionNotification"))
        .and(MessagePredicates.receiverIs(volunteerId)).and(MessagePredicates.attributesAre(new JsonObject()
            .put("communityId", this.community.id).put("taskId", this.task.id).put("outcome", "accepted")));
    final var checkMessages = new ArrayList<Predicate<Message>>();
    checkMessages.add(checkMessage);
    final var checkTask = this.createTaskPredicate()
        .and(TaskPredicates.transactionSizeIs(this.task.transactions.size() + 1))
        .and(TaskPredicates.attributesAre(attributes))
        .and(TaskPredicates.transactionAt(this.task.transactions.size(),
            this.createTaskTransactionPredicate().and(TaskTransactionPredicates.similarTo(taskTransaction))
                .and(TaskTransactionPredicates.messagesSizeIs(1))
                .and(TaskTransactionPredicates.messageAt(0, checkMessage))));
    final var checkStatus = new ArrayList<Predicate<TaskTransactionStatusBody>>();
    checkStatus.add(this.createIncentiveServerTaskTransactionStatusPredicate()
        .and(TaskTransactionStatusBodyPredicates.labelIs(taskTransaction.label))
        .and(TaskTransactionStatusBodyPredicates.userIs(taskTransaction.actioneerId))
        .and(TaskTransactionStatusBodyPredicates.countIs(1)));
    checkStatus.add(this.createIncentiveServerTaskTransactionStatusPredicate()
        .and(TaskTransactionStatusBodyPredicates.labelIs("TaskSelectionNotification"))
        .and(TaskTransactionStatusBodyPredicates.userIs(volunteerId))
        .and(TaskTransactionStatusBodyPredicates.countIs(1)));
    final var future = WeNetTaskManager.createProxy(vertx).doTaskTransaction(taskTransaction)
        .compose(ignored -> this.waitUntilCallbacks(vertx, testContext, checkMessages))
        .compose(ignored -> this.waitUntilTask(vertx, testContext, checkTask))
        .compose(ignored -> this.waitUntilIncentiveServerHasTaskTransactionStatus(vertx, testContext, checkStatus));
    future.onComplete(testContext.succeeding(ignored -> this.assertSuccessfulCompleted(testContext)));
  }
@ Test @ Order ( 10 ) public void shouldAcceptVolunteer ( final Vertx vertx , final VertxTestContext testContext ) { this . assertLastSuccessfulTestWas ( 9 , testContext ) ; final var taskTransaction = new TaskTransaction ( ) ; taskTransaction . actioneerId = this . task . requesterId ; taskTransaction . taskId = this . task . id ; taskTransaction . label = "acceptVolunteer" ; final var volunteerId = this . users . get ( 2 ) . id ; taskTransaction . attributes = new JsonObject ( ) . put ( "volunteerId" , volunteerId ) ; final var attributes = this . task . attributes . copy ( ) ; attributes . getJsonArray ( "volunteers" ) . remove ( volunteerId ) ; attributes . put ( "accepted" , new JsonArray ( ) . add ( volunteerId ) ) ; final var checkMessage = this . createMessagePredicate ( ) . and ( MessagePredicates . labelIs ( "TaskSelectionNotification" ) ) . and ( MessagePredicates . receiverIs ( volunteerId ) ) . and ( MessagePredicates . attributesAre ( new JsonObject ( ) . put ( "communityId" , this . community . id ) . put ( "taskId" , this . task . id ) . put ( "outcome" , "accepted" ) ) ) ; final var checkMessages = new ArrayList < Predicate < Message > > ( ) ; checkMessages . add ( checkMessage ) ; final var checkTask = this . createTaskPredicate ( ) . and ( TaskPredicates . transactionSizeIs ( this . task . transactions . size ( ) + 1 ) ) . and ( TaskPredicates . attributesAre ( attributes ) ) . and ( TaskPredicates . transactionAt ( this . task . transactions . size ( ) , this . createTaskTransactionPredicate ( ) . and ( TaskTransactionPredicates . similarTo ( taskTransaction ) ) . and ( TaskTransactionPredicates . messagesSizeIs ( 1 ) ) . and ( TaskTransactionPredicates . messageAt ( 0 , checkMessage ) ) ) ) ; final var checkStatus = new ArrayList < Predicate < TaskTransactionStatusBody > > ( ) ; checkStatus . add ( this . createIncentiveServerTaskTransactionStatusPredicate ( ) . and ( TaskTransactionStatusBodyPredicates . labelIs ( taskTransaction . label ) ) . and ( TaskTransactionStatusBodyPredicates . userIs ( taskTransaction . actioneerId ) ) . and ( TaskTransactionStatusBodyPredicates . countIs ( 1 ) ) ) ; checkStatus . add ( this . createIncentiveServerTaskTransactionStatusPredicate ( ) . and ( TaskTransactionStatusBodyPredicates . labelIs ( "TaskSelectionNotification" ) ) . and ( TaskTransactionStatusBodyPredicates . userIs ( volunteerId ) ) . and ( TaskTransactionStatusBodyPredicates . countIs ( 1 ) ) ) ; final var future = WeNetTaskManager . createProxy ( vertx ) . doTaskTransaction ( taskTransaction ) . compose ( ignored -> this . waitUntilCallbacks ( vertx , testContext , checkMessages ) ) . compose ( ignored -> this . waitUntilTask ( vertx , testContext , checkTask ) ) . compose ( ignored -> this . waitUntilIncentiveServerHasTaskTransactionStatus ( vertx , testContext , checkStatus ) ) ; future . onComplete ( testContext . succeeding ( ignored -> this . assertSuccessfulCompleted ( testContext ) ) ) ; }
Check that an user can be accepted to be volunteer.
Check that an user can be accepted to be volunteer .