diff --git a/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/ConfigurationManager.java b/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/ConfigurationManager.java index 858528f8..e83eeb5f 100644 --- a/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/ConfigurationManager.java +++ b/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/ConfigurationManager.java @@ -70,7 +70,7 @@ public ConfigurationManager() { */ public synchronized T loadConfig(final Class configClass, String yamlConfigFile) { - log.info("Loading configuration for [" + configClass + "] from: " + yamlConfigFile + " ..."); + log.info("Loading configuration for [{}] from: {} ...", configClass, yamlConfigFile); try (final FileInputStream fileInputStream = new FileInputStream(yamlConfigFile)) { @@ -78,7 +78,7 @@ public synchronized T loadConfig(final Class configClass, String yamlConf final Yaml yaml = new Yaml(new Constructor(configClass, options)); final T requestedConfig = yaml.load(fileInputStream); - log.info("Loaded and set configuration for [" + configClass + "] successfully!"); + log.info("Loaded and set configuration for [{}] successfully!", configClass); return requestedConfig; } catch (IOException e) { @@ -104,7 +104,7 @@ public synchronized T loadConfig(final Class configClass, String yamlConf */ public synchronized void saveConfig(Class configClass, T config, String yamlConfigFile) { - log.info("Saving configuration for [" + configClass + "] to: " + yamlConfigFile + " ..."); + log.info("Saving configuration for [{}] to: {} ...", configClass, yamlConfigFile); try (final FileOutputStream fileOutputStream = new FileOutputStream(yamlConfigFile); final PrintWriter writer = @@ -119,7 +119,7 @@ public synchronized void saveConfig(Class configClass, T config, String y final StringBuilder sb = new StringBuilder(YAML_HEADER); sb.append(yaml.dumpAs(config, Tag.MAP, DumperOptions.FlowStyle.BLOCK)); - log.debug("YAML file content:\n" + sb); + log.debug("YAML file content:\n{}", sb); writer.print(sb); } catch (IOException e) { diff --git a/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/emailalerts/EmailAlertsType.java b/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/emailalerts/EmailAlertsType.java index 6575171d..4c733ac0 100644 --- a/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/emailalerts/EmailAlertsType.java +++ b/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/emailalerts/EmailAlertsType.java @@ -24,12 +24,16 @@ package com.gazbert.bxbot.datastore.yaml.emailalerts; import com.gazbert.bxbot.domain.emailalerts.EmailAlertsConfig; +import lombok.Getter; +import lombok.Setter; /** * Wraps Email Alerts config for dumping to and loading from YAML. * * @author gazbert */ +@Setter +@Getter public class EmailAlertsType { private EmailAlertsConfig emailAlerts; @@ -38,22 +42,4 @@ public class EmailAlertsType { public EmailAlertsType() { // No extra init needed. } - - /** - * Returns the email alerts config. - * - * @return the email alerts config. - */ - public EmailAlertsConfig getEmailAlerts() { - return emailAlerts; - } - - /** - * Sets the email alerts config. - * - * @param emailAlerts the email alerts config. - */ - public void setEmailAlerts(EmailAlertsConfig emailAlerts) { - this.emailAlerts = emailAlerts; - } } diff --git a/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/engine/EngineType.java b/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/engine/EngineType.java index fc89ad03..8afe9955 100644 --- a/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/engine/EngineType.java +++ b/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/engine/EngineType.java @@ -24,12 +24,16 @@ package com.gazbert.bxbot.datastore.yaml.engine; import com.gazbert.bxbot.domain.engine.EngineConfig; +import lombok.Getter; +import lombok.Setter; /** * Wraps Engine config for dumping to and loading from YAML. * * @author gazbert */ +@Setter +@Getter public class EngineType { private EngineConfig engine; @@ -38,22 +42,4 @@ public class EngineType { public EngineType() { // No extra init needed. } - - /** - * Returns the engine config. - * - * @return the engine config. - */ - public EngineConfig getEngine() { - return engine; - } - - /** - * Sets the engine config. - * - * @param engine the engine config. - */ - public void setEngine(EngineConfig engine) { - this.engine = engine; - } } diff --git a/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/exchange/ExchangeType.java b/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/exchange/ExchangeType.java index 3aa3cf02..1dfe30bf 100644 --- a/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/exchange/ExchangeType.java +++ b/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/exchange/ExchangeType.java @@ -24,12 +24,16 @@ package com.gazbert.bxbot.datastore.yaml.exchange; import com.gazbert.bxbot.domain.exchange.ExchangeConfig; +import lombok.Getter; +import lombok.Setter; /** * Wraps Exchange config for dumping to and loading from YAML. * * @author gazbert */ +@Setter +@Getter public class ExchangeType { private ExchangeConfig exchange; @@ -38,22 +42,4 @@ public class ExchangeType { public ExchangeType() { // No extra init needed. } - - /** - * Returns the exchange config. - * - * @return the exchange config. - */ - public ExchangeConfig getExchange() { - return exchange; - } - - /** - * Sets the exchange config. - * - * @param exchange the exchange config. - */ - public void setExchange(ExchangeConfig exchange) { - this.exchange = exchange; - } } diff --git a/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/market/MarketsType.java b/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/market/MarketsType.java index 8f752f5d..57977a6d 100644 --- a/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/market/MarketsType.java +++ b/bxbot-yaml-datastore/src/main/java/com/gazbert/bxbot/datastore/yaml/market/MarketsType.java @@ -26,12 +26,14 @@ import com.gazbert.bxbot.domain.market.MarketConfig; import java.util.ArrayList; import java.util.List; +import lombok.Setter; /** * Wraps a list of Market configs for dumping to and loading from YAML. * * @author gazbert */ +@Setter public class MarketsType { private List markets; @@ -52,13 +54,4 @@ public List getMarkets() { } return markets; } - - /** - * Sets the markets config. - * - * @param markets the markets' config. - */ - public void setMarkets(List markets) { - this.markets = markets; - } } diff --git a/bxbot-yaml-datastore/src/test/java/com/gazbert/bxbot/datastore/yaml/emailalerts/TestEmailAlertsConfigurationManagement.java b/bxbot-yaml-datastore/src/test/java/com/gazbert/bxbot/datastore/yaml/emailalerts/TestEmailAlertsConfigurationManagement.java index 046f1913..d563f433 100644 --- a/bxbot-yaml-datastore/src/test/java/com/gazbert/bxbot/datastore/yaml/emailalerts/TestEmailAlertsConfigurationManagement.java +++ b/bxbot-yaml-datastore/src/test/java/com/gazbert/bxbot/datastore/yaml/emailalerts/TestEmailAlertsConfigurationManagement.java @@ -107,20 +107,7 @@ void testLoadingInvalidYamlConfigFileThrowsException() { @Test void testSavingConfigToXmlIsSuccessful() throws Exception { - final SmtpConfig smtpConfig = new SmtpConfig(); - smtpConfig.setAccountUsername(ACCOUNT_USERNAME); - smtpConfig.setAccountPassword(ACCOUNT_PASSWORD); - smtpConfig.setHost(HOST); - smtpConfig.setTlsPort(TLS_PORT); - smtpConfig.setFromAddress(FROM_ADDRESS); - smtpConfig.setToAddress(TO_ADDRESS); - - final EmailAlertsConfig emailAlertsConfig = new EmailAlertsConfig(); - emailAlertsConfig.setEnabled(true); - emailAlertsConfig.setSmtpConfig(smtpConfig); - - final EmailAlertsType emailAlertsType = new EmailAlertsType(); - emailAlertsType.setEmailAlerts(emailAlertsConfig); + final EmailAlertsType emailAlertsType = getAlertsType(); final ConfigurationManager configurationManager = new ConfigurationManager(); @@ -149,6 +136,22 @@ void testSavingConfigToXmlIsSuccessful() throws Exception { @Test void testSavingConfigToInvalidYamlFileIsHandled() { + final EmailAlertsType emailAlertsType = getAlertsType(); + + final ConfigurationManager configurationManager = new ConfigurationManager(); + + assertThrows( + IllegalStateException.class, + () -> + configurationManager.saveConfig( + EmailAlertsType.class, emailAlertsType, INVALID_YAML_CONFIG_TO_SAVE_FILENAME)); + } + + // -------------------------------------------------------------------------- + // Canned data + // -------------------------------------------------------------------------- + + private static EmailAlertsType getAlertsType() { final SmtpConfig smtpConfig = new SmtpConfig(); smtpConfig.setAccountUsername(ACCOUNT_USERNAME); smtpConfig.setAccountPassword(ACCOUNT_PASSWORD); @@ -163,13 +166,6 @@ void testSavingConfigToInvalidYamlFileIsHandled() { final EmailAlertsType emailAlertsType = new EmailAlertsType(); emailAlertsType.setEmailAlerts(emailAlertsConfig); - - final ConfigurationManager configurationManager = new ConfigurationManager(); - - assertThrows( - IllegalStateException.class, - () -> - configurationManager.saveConfig( - EmailAlertsType.class, emailAlertsType, INVALID_YAML_CONFIG_TO_SAVE_FILENAME)); + return emailAlertsType; } } diff --git a/bxbot-yaml-datastore/src/test/java/com/gazbert/bxbot/datastore/yaml/exchange/TestExchangeConfigurationManagement.java b/bxbot-yaml-datastore/src/test/java/com/gazbert/bxbot/datastore/yaml/exchange/TestExchangeConfigurationManagement.java index fb8ca550..fc88126c 100644 --- a/bxbot-yaml-datastore/src/test/java/com/gazbert/bxbot/datastore/yaml/exchange/TestExchangeConfigurationManagement.java +++ b/bxbot-yaml-datastore/src/test/java/com/gazbert/bxbot/datastore/yaml/exchange/TestExchangeConfigurationManagement.java @@ -157,16 +157,7 @@ void testSavingConfigToYamlIsSuccessful() throws Exception { networkConfig.setNonFatalErrorCodes(NON_FATAL_ERROR_CODES); networkConfig.setNonFatalErrorMessages(NON_FATAL_ERROR_MESSAGES); - final Map otherConfig = new HashMap<>(); - otherConfig.put(BUY_FEE_CONFIG_ITEM_KEY, BUY_FEE_CONFIG_ITEM_VALUE); - otherConfig.put(SELL_FEE_CONFIG_ITEM_KEY, SELL_FEE_CONFIG_ITEM_VALUE); - - final ExchangeConfig exchangeConfig = new ExchangeConfig(); - exchangeConfig.setName(EXCHANGE_NAME); - exchangeConfig.setAdapter(EXCHANGE_ADAPTER); - exchangeConfig.setAuthenticationConfig(authenticationConfig); - exchangeConfig.setNetworkConfig(networkConfig); - exchangeConfig.setOtherConfig(otherConfig); + final ExchangeConfig exchangeConfig = getExchangeConfig(authenticationConfig, networkConfig); final ExchangeType exchangeType = new ExchangeType(); exchangeType.setExchange(exchangeConfig); @@ -227,16 +218,7 @@ void testSavingConfigToInvalidYamlFileIsHandled() { networkConfig.setNonFatalErrorCodes(NON_FATAL_ERROR_CODES); networkConfig.setNonFatalErrorMessages(NON_FATAL_ERROR_MESSAGES); - final Map otherConfig = new HashMap<>(); - otherConfig.put(BUY_FEE_CONFIG_ITEM_KEY, BUY_FEE_CONFIG_ITEM_VALUE); - otherConfig.put(SELL_FEE_CONFIG_ITEM_KEY, SELL_FEE_CONFIG_ITEM_VALUE); - - final ExchangeConfig exchangeConfig = new ExchangeConfig(); - exchangeConfig.setName(EXCHANGE_NAME); - exchangeConfig.setAdapter(EXCHANGE_ADAPTER); - exchangeConfig.setAuthenticationConfig(authenticationConfig); - exchangeConfig.setNetworkConfig(networkConfig); - exchangeConfig.setOtherConfig(otherConfig); + final ExchangeConfig exchangeConfig = getExchangeConfig(authenticationConfig, networkConfig); final ExchangeType exchangeType = new ExchangeType(); exchangeType.setExchange(exchangeConfig); @@ -249,4 +231,23 @@ void testSavingConfigToInvalidYamlFileIsHandled() { configurationManager.saveConfig( ExchangeType.class, exchangeType, INVALID_YAML_CONFIG_TO_SAVE_FILENAME)); } + + // -------------------------------------------------------------------------- + // Canned data + // -------------------------------------------------------------------------- + + private static ExchangeConfig getExchangeConfig( + Map authenticationConfig, NetworkConfig networkConfig) { + final Map otherConfig = new HashMap<>(); + otherConfig.put(BUY_FEE_CONFIG_ITEM_KEY, BUY_FEE_CONFIG_ITEM_VALUE); + otherConfig.put(SELL_FEE_CONFIG_ITEM_KEY, SELL_FEE_CONFIG_ITEM_VALUE); + + final ExchangeConfig exchangeConfig = new ExchangeConfig(); + exchangeConfig.setName(EXCHANGE_NAME); + exchangeConfig.setAdapter(EXCHANGE_ADAPTER); + exchangeConfig.setAuthenticationConfig(authenticationConfig); + exchangeConfig.setNetworkConfig(networkConfig); + exchangeConfig.setOtherConfig(otherConfig); + return exchangeConfig; + } } diff --git a/bxbot-yaml-datastore/src/test/java/com/gazbert/bxbot/datastore/yaml/market/TestMarketConfigurationManagement.java b/bxbot-yaml-datastore/src/test/java/com/gazbert/bxbot/datastore/yaml/market/TestMarketConfigurationManagement.java index 189c9f93..757b9148 100644 --- a/bxbot-yaml-datastore/src/test/java/com/gazbert/bxbot/datastore/yaml/market/TestMarketConfigurationManagement.java +++ b/bxbot-yaml-datastore/src/test/java/com/gazbert/bxbot/datastore/yaml/market/TestMarketConfigurationManagement.java @@ -23,7 +23,7 @@ package com.gazbert.bxbot.datastore.yaml.market; -import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; diff --git a/bxbot-yaml-datastore/src/test/java/com/gazbert/bxbot/datastore/yaml/strategy/TestStrategyConfigurationManagement.java b/bxbot-yaml-datastore/src/test/java/com/gazbert/bxbot/datastore/yaml/strategy/TestStrategyConfigurationManagement.java index ab5015bb..ab328453 100644 --- a/bxbot-yaml-datastore/src/test/java/com/gazbert/bxbot/datastore/yaml/strategy/TestStrategyConfigurationManagement.java +++ b/bxbot-yaml-datastore/src/test/java/com/gazbert/bxbot/datastore/yaml/strategy/TestStrategyConfigurationManagement.java @@ -23,7 +23,7 @@ package com.gazbert.bxbot.datastore.yaml.strategy; -import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -160,16 +160,7 @@ void testLoadingInvalidYamlConfigFileThrowsException() { @Test void testSavingConfigToYamlIsSuccessful() throws Exception { // Strat 1 - final StrategyConfig strategy1 = new StrategyConfig(); - strategy1.setId(STRAT_ID_1); - strategy1.setName(STRAT_NAME_1); - strategy1.setDescription(STRAT_DESCRIPTION_1); - strategy1.setClassName(STRAT_CLASSNAME_1); - - final Map strat1ConfigItems = new HashMap<>(); - strat1ConfigItems.put(BUY_PRICE_CONFIG_ITEM_KEY, BUY_PRICE_CONFIG_ITEM_VALUE); - strat1ConfigItems.put(AMOUNT_TO_BUY_CONFIG_ITEM_KEY, AMOUNT_TO_BUY_CONFIG_ITEM_VALUE); - strategy1.setConfigItems(strat1ConfigItems); + final StrategyConfig strategy1 = getStrategyConfig(); // Strat 2 final StrategyConfig strategy2 = new StrategyConfig(); @@ -247,6 +238,20 @@ void testSavingConfigToYamlIsSuccessful() throws Exception { Files.delete(FileSystems.getDefault().getPath(YAML_CONFIG_TO_SAVE_FILENAME)); } + private static StrategyConfig getStrategyConfig() { + final StrategyConfig strategy1 = new StrategyConfig(); + strategy1.setId(STRAT_ID_1); + strategy1.setName(STRAT_NAME_1); + strategy1.setDescription(STRAT_DESCRIPTION_1); + strategy1.setClassName(STRAT_CLASSNAME_1); + + final Map strat1ConfigItems = new HashMap<>(); + strat1ConfigItems.put(BUY_PRICE_CONFIG_ITEM_KEY, BUY_PRICE_CONFIG_ITEM_VALUE); + strat1ConfigItems.put(AMOUNT_TO_BUY_CONFIG_ITEM_KEY, AMOUNT_TO_BUY_CONFIG_ITEM_VALUE); + strategy1.setConfigItems(strat1ConfigItems); + return strategy1; + } + @Test void testSavingConfigToInvalidYamlFileIsHandled() { // Strat 1