vertx/src/test/java/eu/internetofus/common/vertx/RepositoryIT.java
/**
   * Should update document.
   *
   * @param vertx       event bus to use.
   * @param testContext context for the test.
   */
Should update document.
@param vertx       event bus to use.
@param testContext context for the test.
Should update document . @param vertx event bus to use . @param testContext context for the test .
@Test
  public void shouldUpdateDocument(final Vertx vertx, final VertxTestContext testContext) {
    final var document = new JsonObject().put("key1", "value").put("key2", 2).put("key3", false).put("key4",
        new JsonArray());
    pool.insert(TEST_COLLECTION, document, testContext.succeeding(id -> {
      final var repository = new Repository(vertx, pool, "schemaVersion");
      final var query = new JsonObject().put("_id", id);
      testContext.assertComplete(repository
          .updateOneDocument(TEST_COLLECTION, query,
              new JsonObject().put("index", 100).putNull("key1").put("key3", true))
          .compose(updated -> pool.find(TEST_COLLECTION, query))).onSuccess(value -> testContext.verify(() -> {
            assertThat(value).isNotEmpty().hasSize(1);
            final var element = value.get(0);
            assertThat(element.getInteger("index")).isEqualTo(100);
            assertThat(element.containsKey("key1")).isFalse();
            assertThat(element.getInteger("key2")).isEqualTo(2);
            assertThat(element.getBoolean("key3")).isTrue();
            assertThat(element.getJsonArray("key4")).isEqualTo(new JsonArray());
            testContext.completeNow();
          }));
    }));
  }
@ Test public void shouldUpdateDocument ( final Vertx vertx , final VertxTestContext testContext ) { final var document = new JsonObject ( ) . put ( "key1" , "value" ) . put ( "key2" , 2 ) . put ( "key3" , false ) . put ( "key4" , new JsonArray ( ) ) ; pool . insert ( TEST_COLLECTION , document , testContext . succeeding ( id -> { final var repository = new Repository ( vertx , pool , "schemaVersion" ) ; final var query = new JsonObject ( ) . put ( "_id" , id ) ; testContext . assertComplete ( repository . updateOneDocument ( TEST_COLLECTION , query , new JsonObject ( ) . put ( "index" , 100 ) . putNull ( "key1" ) . put ( "key3" , true ) ) . compose ( updated -> pool . find ( TEST_COLLECTION , query ) ) ) . onSuccess ( value -> testContext . verify ( ( ) -> { assertThat ( value ) . isNotEmpty ( ) . hasSize ( 1 ) ; final var element = value . get ( 0 ) ; assertThat ( element . getInteger ( "index" ) ) . isEqualTo ( 100 ) ; assertThat ( element . containsKey ( "key1" ) ) . isFalse ( ) ; assertThat ( element . getInteger ( "key2" ) ) . isEqualTo ( 2 ) ; assertThat ( element . getBoolean ( "key3" ) ) . isTrue ( ) ; assertThat ( element . getJsonArray ( "key4" ) ) . isEqualTo ( new JsonArray ( ) ) ; testContext . completeNow ( ) ; } ) ) ; } ) ) ; }
Should update document.
Should update document .