vertx/src/test/java/eu/internetofus/common/vertx/AbstractMainTest.java
/**
   * Check configuration properties are preferred to the defined on the
   * configuration files.
   *
   * @param testContext test context over the event bus.
   * @param tmpDir      temporal directory.
   *
   * @throws Throwable if can not create the temporal files.
   */
Check configuration properties are preferred to the defined on the
configuration files.

@param testContext test context over the event bus.
@param tmpDir      temporal directory.

@throws Throwable if can not create the temporal files.
Check configuration properties are preferred to the defined on the configuration files . @param testContext test context over the event bus . @param tmpDir temporal directory . @throws Throwable if can not create the temporal files .
@Test
  public void shouldConfigureAndUsePropertiesBeforeFiles(final VertxTestContext testContext, @TempDir final File tmpDir)
      throws Throwable {
    final var etc = new File(tmpDir, "etc");
    etc.mkdirs();
    final var api = new JsonObject().put("host", "HOST").put("port", 80);
    final var apiFile = new File(etc, "api.json");
    apiFile.createNewFile();
    Files.writeString(apiFile.toPath(), new JsonObject().put("api", api).encodePrettily());
    final var persistence = new StringBuilder();
    persistence.append("persistence:\n");
    persistence.append("  host: phost\n");
    persistence.append("  port: 27\n");
    persistence.append("  db_name: \"DB_NAME\"\n");
    persistence.append("  username: USER_NAME\n");
    persistence.append("  password: \"PASSWORD\"\n");
    final var persistenceFile = new File(etc, "persistence.yml");
    persistenceFile.createNewFile();
    Files.writeString(persistenceFile.toPath(), persistence.toString());
    testContext
        .assertComplete(this.main.startWith("-" + AbstractMain.CONF_DIR_OPTION + etc.getAbsolutePath(),
            "-" + AbstractMain.PROPERTY_OPTION + "api.port=8081",
            "-" + AbstractMain.PROPERTY_OPTION + " persistence.db_name=\"database name\"",
            "-" + AbstractMain.PROPERTY_OPTION, "persistence.password=PASSW0RD", "-" + AbstractMain.VERSION_OPTION))
        .onComplete(handler -> {
          final var retriever = ConfigRetriever.create(Vertx.vertx(), this.main.retrieveOptions);
          retriever.getConfig(testContext.succeeding(conf -> testContext.verify(() -> {
            assertThat(conf.getJsonObject("api")).isNotNull();
            assertThat(conf.getJsonObject("api").getString("host")).isEqualTo("HOST");
            assertThat(conf.getJsonObject("api").getInteger("port")).isEqualTo(8081);
            assertThat(conf.getJsonObject("persistence")).isNotNull();
            assertThat(conf.getJsonObject("persistence").getString("host")).isEqualTo("phost");
            assertThat(conf.getJsonObject("persistence").getInteger("port")).isEqualTo(27);
            assertThat(conf.getJsonObject("persistence").getString("db_name")).isEqualTo("database name");
            assertThat(conf.getJsonObject("persistence").getString("username")).isEqualTo("USER_NAME");
            assertThat(conf.getJsonObject("persistence").getString("password")).isEqualTo("PASSW0RD");
            testContext.completeNow();
          })));
        });
  }
@ Test public void shouldConfigureAndUsePropertiesBeforeFiles ( final VertxTestContext testContext , @ TempDir final File tmpDir ) throws Throwable { final var etc = new File ( tmpDir , "etc" ) ; etc . mkdirs ( ) ; final var api = new JsonObject ( ) . put ( "host" , "HOST" ) . put ( "port" , 80 ) ; final var apiFile = new File ( etc , "api.json" ) ; apiFile . createNewFile ( ) ; Files . writeString ( apiFile . toPath ( ) , new JsonObject ( ) . put ( "api" , api ) . encodePrettily ( ) ) ; final var persistence = new StringBuilder ( ) ; persistence . append ( "persistence:\n" ) ; persistence . append ( "  host: phost\n" ) ; persistence . append ( "  port: 27\n" ) ; persistence . append ( "  db_name: \"DB_NAME\"\n" ) ; persistence . append ( "  username: USER_NAME\n" ) ; persistence . append ( "  password: \"PASSWORD\"\n" ) ; final var persistenceFile = new File ( etc , "persistence.yml" ) ; persistenceFile . createNewFile ( ) ; Files . writeString ( persistenceFile . toPath ( ) , persistence . toString ( ) ) ; testContext . assertComplete ( this . main . startWith ( "-" + AbstractMain . CONF_DIR_OPTION + etc . getAbsolutePath ( ) , "-" + AbstractMain . PROPERTY_OPTION + "api.port=8081" , "-" + AbstractMain . PROPERTY_OPTION + " persistence.db_name=\"database name\"" , "-" + AbstractMain . PROPERTY_OPTION , "persistence.password=PASSW0RD" , "-" + AbstractMain . VERSION_OPTION ) ) . onComplete ( handler -> { final var retriever = ConfigRetriever . create ( Vertx . vertx ( ) , this . main . retrieveOptions ) ; retriever . getConfig ( testContext . succeeding ( conf -> testContext . verify ( ( ) -> { assertThat ( conf . getJsonObject ( "api" ) ) . isNotNull ( ) ; assertThat ( conf . getJsonObject ( "api" ) . getString ( "host" ) ) . isEqualTo ( "HOST" ) ; assertThat ( conf . getJsonObject ( "api" ) . getInteger ( "port" ) ) . isEqualTo ( 8081 ) ; assertThat ( conf . getJsonObject ( "persistence" ) ) . isNotNull ( ) ; assertThat ( conf . getJsonObject ( "persistence" ) . getString ( "host" ) ) . isEqualTo ( "phost" ) ; assertThat ( conf . getJsonObject ( "persistence" ) . getInteger ( "port" ) ) . isEqualTo ( 27 ) ; assertThat ( conf . getJsonObject ( "persistence" ) . getString ( "db_name" ) ) . isEqualTo ( "database name" ) ; assertThat ( conf . getJsonObject ( "persistence" ) . getString ( "username" ) ) . isEqualTo ( "USER_NAME" ) ; assertThat ( conf . getJsonObject ( "persistence" ) . getString ( "password" ) ) . isEqualTo ( "PASSW0RD" ) ; testContext . completeNow ( ) ; } ) ) ) ; } ) ; }
Check configuration properties are preferred to the defined on the
 configuration files.
Check configuration properties are preferred to the defined on the configuration files .