vertx/src/test/java/eu/internetofus/common/vertx/RepositoryIT.java
/**
   * Should migrate collection.
   *
   * @param vertx       event bus to use.
   * @param testContext context for the test.
   */
Should migrate collection.
@param vertx       event bus to use.
@param testContext context for the test.
Should migrate collection . @param vertx event bus to use . @param testContext context for the test .
@Test
  public void shouldMigrateCollection(final Vertx vertx, final VertxTestContext testContext) {
    final var collection = "_" + UUID.randomUUID().toString().replaceAll("-", "");
    pool.createCollection(collection, testContext.succeeding(createdCollections -> {
      this.createAndInsertDummyComplexModelsWithExtraFieldsTo(collection, 1000, testContext, () -> {
        final var repository = new Repository(vertx, pool, "2");
        final var options = new FindOptions();
        options.setLimit(10000);
        options.getSort().put("index", 1);
        repository.migrateCollection(collection, DummyModel.class, "2")
            .onComplete(testContext.succeeding(migrated -> pool.findWithOptions(collection, new JsonObject(), options,
                testContext.succeeding(values -> testContext.verify(() -> {
                  assertThat(values).isNotEmpty().hasSize(1000);
                  final var expected = new JsonObject().put(Repository.SCHEMA_VERSION, "2");
                  for (var i = 0; i < 1000; i++) {
                    final var value = values.get(i);
                    expected.put("index", i + 1).put("_id", value.getString("_id"));
                    assertThat(value).isEqualTo(expected);
                  }
                  testContext.completeNow();
                })))));
      });
    }));
  }
@ Test public void shouldMigrateCollection ( final Vertx vertx , final VertxTestContext testContext ) { final var collection = "_" + UUID . randomUUID ( ) . toString ( ) . replaceAll ( "-" , "" ) ; pool . createCollection ( collection , testContext . succeeding ( createdCollections -> { this . createAndInsertDummyComplexModelsWithExtraFieldsTo ( collection , 1000 , testContext , ( ) -> { final var repository = new Repository ( vertx , pool , "2" ) ; final var options = new FindOptions ( ) ; options . setLimit ( 10000 ) ; options . getSort ( ) . put ( "index" , 1 ) ; repository . migrateCollection ( collection , DummyModel . class , "2" ) . onComplete ( testContext . succeeding ( migrated -> pool . findWithOptions ( collection , new JsonObject ( ) , options , testContext . succeeding ( values -> testContext . verify ( ( ) -> { assertThat ( values ) . isNotEmpty ( ) . hasSize ( 1000 ) ; final var expected = new JsonObject ( ) . put ( Repository . SCHEMA_VERSION , "2" ) ; for ( var i = 0 ; i < 1000 ; i ++ ) { final var value = values . get ( i ) ; expected . put ( "index" , i + 1 ) . put ( "_id" , value . getString ( "_id" ) ) ; assertThat ( value ) . isEqualTo ( expected ) ; } testContext . completeNow ( ) ; } ) ) ) ) ) ; } ) ; } ) ) ; }
Should migrate collection.
Should migrate collection .