@Test public void when_config_file_loaded_and_server_configuration_validator_returns_NO_validator_error_message_shutdown_service_is_NOT_called() { serviceToTest.pathToConfigFile = "./src/test/resources/config/pds-config-example1.json"; serviceToTest.postConstruct(); verify(shutdownService,never()).shutdownApplication(); }
@PostConstruct protected void postConstruct() { Path p = Paths.get(pathToConfigFile); File file = p.toFile(); if (file.exists()) { try { String json = FileUtils.readFileToString(file, Charset.forName("UTF-8")); PDSServerConfiguration loadedConfiguration = PDSServerConfiguration.fromJSON(json); String message = serverConfigurationValidator.createValidationErrorMessage(loadedConfiguration); if (message == null) { configuration = loadedConfiguration; } else { LOG.error("configuration file '{}' not valid - reason: {}", file.getAbsolutePath(), message); } } catch (PDSJSONConverterException | IOException e) { LOG.error("no configuration available, because cannot read config file", e); } } else { LOG.error("No config file found at {} !", file.getAbsolutePath()); } if (configuration == null) { LOG.error("PDS configuration failure\n*****************************\nCONFIG ERROR CANNOT START PDS\n*****************************\nNo configuration available (see former logs for reason), so cannot start PDS server - trigger shutdown to ensure application no longer alive"); shutdownService.shutdownApplication(); } }
PDSServerConfigurationService { @PostConstruct protected void postConstruct() { Path p = Paths.get(pathToConfigFile); File file = p.toFile(); if (file.exists()) { try { String json = FileUtils.readFileToString(file, Charset.forName("UTF-8")); PDSServerConfiguration loadedConfiguration = PDSServerConfiguration.fromJSON(json); String message = serverConfigurationValidator.createValidationErrorMessage(loadedConfiguration); if (message == null) { configuration = loadedConfiguration; } else { LOG.error("configuration file '{}' not valid - reason: {}", file.getAbsolutePath(), message); } } catch (PDSJSONConverterException | IOException e) { LOG.error("no configuration available, because cannot read config file", e); } } else { LOG.error("No config file found at {} !", file.getAbsolutePath()); } if (configuration == null) { LOG.error("PDS configuration failure\n*****************************\nCONFIG ERROR CANNOT START PDS\n*****************************\nNo configuration available (see former logs for reason), so cannot start PDS server - trigger shutdown to ensure application no longer alive"); shutdownService.shutdownApplication(); } } }
PDSServerConfigurationService { @PostConstruct protected void postConstruct() { Path p = Paths.get(pathToConfigFile); File file = p.toFile(); if (file.exists()) { try { String json = FileUtils.readFileToString(file, Charset.forName("UTF-8")); PDSServerConfiguration loadedConfiguration = PDSServerConfiguration.fromJSON(json); String message = serverConfigurationValidator.createValidationErrorMessage(loadedConfiguration); if (message == null) { configuration = loadedConfiguration; } else { LOG.error("configuration file '{}' not valid - reason: {}", file.getAbsolutePath(), message); } } catch (PDSJSONConverterException | IOException e) { LOG.error("no configuration available, because cannot read config file", e); } } else { LOG.error("No config file found at {} !", file.getAbsolutePath()); } if (configuration == null) { LOG.error("PDS configuration failure\n*****************************\nCONFIG ERROR CANNOT START PDS\n*****************************\nNo configuration available (see former logs for reason), so cannot start PDS server - trigger shutdown to ensure application no longer alive"); shutdownService.shutdownApplication(); } }  }
PDSServerConfigurationService { @PostConstruct protected void postConstruct() { Path p = Paths.get(pathToConfigFile); File file = p.toFile(); if (file.exists()) { try { String json = FileUtils.readFileToString(file, Charset.forName("UTF-8")); PDSServerConfiguration loadedConfiguration = PDSServerConfiguration.fromJSON(json); String message = serverConfigurationValidator.createValidationErrorMessage(loadedConfiguration); if (message == null) { configuration = loadedConfiguration; } else { LOG.error("configuration file '{}' not valid - reason: {}", file.getAbsolutePath(), message); } } catch (PDSJSONConverterException | IOException e) { LOG.error("no configuration available, because cannot read config file", e); } } else { LOG.error("No config file found at {} !", file.getAbsolutePath()); } if (configuration == null) { LOG.error("PDS configuration failure\n*****************************\nCONFIG ERROR CANNOT START PDS\n*****************************\nNo configuration available (see former logs for reason), so cannot start PDS server - trigger shutdown to ensure application no longer alive"); shutdownService.shutdownApplication(); } }  PDSServerConfiguration getServerConfiguration(); PDSProductSetup getProductSetupOrNull(String productId); String getServerId(); }
PDSServerConfigurationService { @PostConstruct protected void postConstruct() { Path p = Paths.get(pathToConfigFile); File file = p.toFile(); if (file.exists()) { try { String json = FileUtils.readFileToString(file, Charset.forName("UTF-8")); PDSServerConfiguration loadedConfiguration = PDSServerConfiguration.fromJSON(json); String message = serverConfigurationValidator.createValidationErrorMessage(loadedConfiguration); if (message == null) { configuration = loadedConfiguration; } else { LOG.error("configuration file '{}' not valid - reason: {}", file.getAbsolutePath(), message); } } catch (PDSJSONConverterException | IOException e) { LOG.error("no configuration available, because cannot read config file", e); } } else { LOG.error("No config file found at {} !", file.getAbsolutePath()); } if (configuration == null) { LOG.error("PDS configuration failure\n*****************************\nCONFIG ERROR CANNOT START PDS\n*****************************\nNo configuration available (see former logs for reason), so cannot start PDS server - trigger shutdown to ensure application no longer alive"); shutdownService.shutdownApplication(); } }  PDSServerConfiguration getServerConfiguration(); PDSProductSetup getProductSetupOrNull(String productId); String getServerId();  }