vertx/src/test/java/eu/internetofus/common/vertx/RepositoryIT.java
/**
   * Should upsert document.
   *
   * @param vertx       event bus to use.
   * @param testContext context for the test.
   */
Should upsert document.
@param vertx       event bus to use.
@param testContext context for the test.
Should upsert document . @param vertx event bus to use . @param testContext context for the test .
@Test
  public void shouldUsertDocument(final Vertx vertx, final VertxTestContext testContext) {
    final var repository = new Repository(vertx, pool, "schemaVersion");
    final var query = new JsonObject().put("identifier", UUID.randomUUID().toString());
    final var newDoc = new JsonObject().put("index", 100).putNull("key1").put("key3", true);
    testContext.assertComplete(repository.upsertOneDocument(TEST_COLLECTION, query, newDoc, true).compose(id -> {
      newDoc.put("_id", id);
      return pool.find(TEST_COLLECTION, new JsonObject().put("_id", id));
    }).onSuccess(value -> testContext.verify(() -> {
      assertThat(value).isNotEmpty().hasSize(1);
      final var element = value.get(0);
      newDoc.mergeIn(query);
      newDoc.put(Repository.SCHEMA_VERSION, "schemaVersion");
      newDoc.remove("key1");
      assertThat(element).isEqualTo(newDoc);
      testContext.completeNow();
    })));
  }
@ Test public void shouldUsertDocument ( final Vertx vertx , final VertxTestContext testContext ) { final var repository = new Repository ( vertx , pool , "schemaVersion" ) ; final var query = new JsonObject ( ) . put ( "identifier" , UUID . randomUUID ( ) . toString ( ) ) ; final var newDoc = new JsonObject ( ) . put ( "index" , 100 ) . putNull ( "key1" ) . put ( "key3" , true ) ; testContext . assertComplete ( repository . upsertOneDocument ( TEST_COLLECTION , query , newDoc , true ) . compose ( id -> { newDoc . put ( "_id" , id ) ; return pool . find ( TEST_COLLECTION , new JsonObject ( ) . put ( "_id" , id ) ) ; } ) . onSuccess ( value -> testContext . verify ( ( ) -> { assertThat ( value ) . isNotEmpty ( ) . hasSize ( 1 ) ; final var element = value . get ( 0 ) ; newDoc . mergeIn ( query ) ; newDoc . put ( Repository . SCHEMA_VERSION , "schemaVersion" ) ; newDoc . remove ( "key1" ) ; assertThat ( element ) . isEqualTo ( newDoc ) ; testContext . completeNow ( ) ; } ) ) ) ; }
Should upsert document.
Should upsert document .