vertx/src/test/java/eu/internetofus/common/vertx/RepositoryTest.java
/**
   * Should not migrate document because update failed.
   *
   * @param pool        mocked MongoDB client.
   * @param vertx       event bus to use.
   * @param testContext test context.
   */
Should not migrate document because update failed.
@param pool        mocked MongoDB client.
@param vertx       event bus to use.
@param testContext test context.
Should not migrate document because update failed . @param pool mocked MongoDB client . @param vertx event bus to use . @param testContext test context .
@Test
  public void shouldNotMigrateOneDocumentBecauseUpdateFailed(@Mock final MongoClient pool, final Vertx vertx,
      final VertxTestContext testContext) {
    final var repository = new Repository(vertx, pool, "version");
    final var collection = "collectionName";
    doReturn(Future.succeededFuture(new JsonObject())).when(pool).findOne(eq(collection), any(), any());
    doReturn(Future.failedFuture("Cannot update")).when(pool).updateCollectionWithOptions(eq(collection),
        any(JsonObject.class), any(JsonObject.class), any(UpdateOptions.class));
    final var consumerId = UUID.randomUUID().toString();
    final var consumer = vertx.eventBus().localConsumer(consumerId);
    consumer.handler(msg -> {
      consumer.unregister();
      testContext.verify(() -> {
        assertThat(msg.body()).isInstanceOf(String.class);
        testContext.completeNow();
      });
    });
    repository.migrateOneDocument(consumerId, collection, DummyModel.class, new JsonObject(), 10l);
  }
@ Test public void shouldNotMigrateOneDocumentBecauseUpdateFailed ( @ Mock final MongoClient pool , final Vertx vertx , final VertxTestContext testContext ) { final var repository = new Repository ( vertx , pool , "version" ) ; final var collection = "collectionName" ; doReturn ( Future . succeededFuture ( new JsonObject ( ) ) ) . when ( pool ) . findOne ( eq ( collection ) , any ( ) , any ( ) ) ; doReturn ( Future . failedFuture ( "Cannot update" ) ) . when ( pool ) . updateCollectionWithOptions ( eq ( collection ) , any ( JsonObject . class ) , any ( JsonObject . class ) , any ( UpdateOptions . class ) ) ; final var consumerId = UUID . randomUUID ( ) . toString ( ) ; final var consumer = vertx . eventBus ( ) . localConsumer ( consumerId ) ; consumer . handler ( msg -> { consumer . unregister ( ) ; testContext . verify ( ( ) -> { assertThat ( msg . body ( ) ) . isInstanceOf ( String . class ) ; testContext . completeNow ( ) ; } ) ; } ) ; repository . migrateOneDocument ( consumerId , collection , DummyModel . class , new JsonObject ( ) , 10l ) ; }
Should not migrate document because update failed.
Should not migrate document because update failed .