Repository: incubator-tamaya-extensions Updated Branches: refs/heads/master 6d91a934a -> 864f02006
TAMAYA-316: Fix minor errors in tests. Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/864f0200 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/864f0200 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/864f0200 Branch: refs/heads/master Commit: 864f02006bbd733d1076f70b1411860cd6ff8966 Parents: 6d91a93 Author: Phil Ottlinger <[email protected]> Authored: Wed Nov 1 22:02:29 2017 +0100 Committer: Phil Ottlinger <[email protected]> Committed: Wed Nov 1 22:02:29 2017 +0100 ---------------------------------------------------------------------- .../tamaya/osgi/commands/BackupCommands.java | 4 +- .../tamaya/osgi/commands/HistoryCommands.java | 3 -- .../apache/tamaya/osgi/AbstractOSGITest.java | 6 +-- .../org/apache/tamaya/osgi/BackupsTest.java | 1 - .../apache/tamaya/osgi/ConfigHistoryTest.java | 53 +++++++++++--------- .../tamaya/osgi/TamayaConfigPluginTest.java | 35 ++++++------- .../osgi/commands/BackupCommandsTest.java | 2 +- 7 files changed, 50 insertions(+), 54 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/864f0200/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/BackupCommands.java ---------------------------------------------------------------------- diff --git a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/BackupCommands.java b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/BackupCommands.java index d8734f7..03338cd 100644 --- a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/BackupCommands.java +++ b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/BackupCommands.java @@ -47,11 +47,11 @@ public final class BackupCommands { if(service.createBackup(pid)){ return "Backup created, PID = " + pid + '\n' + printProps(props); }else{ - return "Creating backup failed. Backup already existing, PID = " + pid; + return "Creating of backup failed. Backup already existing, PID = " + pid; } } } - return "Creating backup failed. No Config found, PID = " + pid; + return "Creating of backup failed. No Config found, PID = " + pid; } public static String deleteBackup(TamayaConfigService service, String pid) throws IOException { http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/864f0200/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java ---------------------------------------------------------------------- diff --git a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java index 7323dbd..6aafe92 100644 --- a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java +++ b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java @@ -38,7 +38,6 @@ public final class HistoryCommands{ private HistoryCommands(){} public static String clearHistory(TamayaConfigService service, String pid) throws IOException { - int size = service.getHistory(pid).size(); if(pid!=null){ service.clearHistory(pid); return "Deleted Config Change History for PID: " + pid; @@ -46,7 +45,6 @@ public final class HistoryCommands{ service.clearHistory(); return "Deleted complete Config Change History."; } - } public static String getHistory(TamayaConfigService service, String pid, String... events) throws IOException { @@ -97,5 +95,4 @@ public final class HistoryCommands{ return result; } - } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/864f0200/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/AbstractOSGITest.java ---------------------------------------------------------------------- diff --git a/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/AbstractOSGITest.java b/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/AbstractOSGITest.java index 20f6fea..41ad2e6 100644 --- a/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/AbstractOSGITest.java +++ b/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/AbstractOSGITest.java @@ -21,7 +21,6 @@ package org.apache.tamaya.osgi; import org.apache.tamaya.osgi.commands.TamayaConfigService; import org.junit.Before; import org.mockito.Mock; -import org.mockito.stubbing.Answer; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -76,7 +75,8 @@ public abstract class AbstractOSGITest { doReturn(tamayaConfigPlugin).when(bundleContext).getService(tamayaRef); } - protected Configuration initConfigurationMock(final String pid)throws Exception{ + @SuppressWarnings("unchecked") + protected Configuration initConfigurationMock(final String pid)throws Exception{ Configuration config = mock(Configuration.class); doAnswer(invocation -> { Hashtable<String,Object> props = properties.get(pid); @@ -89,7 +89,7 @@ public abstract class AbstractOSGITest { if(props==null){ props = new Hashtable<>(); properties.put(pid, props); - for(Map.Entry en:System.getProperties().entrySet()){ + for(Map.Entry<Object,Object> en:System.getProperties().entrySet()){ props.put(en.getKey().toString(), en.getValue()); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/864f0200/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/BackupsTest.java ---------------------------------------------------------------------- diff --git a/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/BackupsTest.java b/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/BackupsTest.java index 9039332..623c3ff 100644 --- a/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/BackupsTest.java +++ b/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/BackupsTest.java @@ -32,7 +32,6 @@ import static org.junit.Assert.*; */ public class BackupsTest { - private Dictionary<String,Object> createConfig(String pid){ Hashtable<String,Object> config = new Hashtable<>(); config.put("test.id", pid); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/864f0200/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/ConfigHistoryTest.java ---------------------------------------------------------------------- diff --git a/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/ConfigHistoryTest.java b/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/ConfigHistoryTest.java index a829f7b..f688da9 100644 --- a/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/ConfigHistoryTest.java +++ b/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/ConfigHistoryTest.java @@ -35,35 +35,35 @@ public class ConfigHistoryTest { public void configuring() throws Exception { ConfigHistory en = ConfigHistory.configuring("configuring", "configuring_test"); assertNotNull(en); - assertEquals(en.getPid(), "configuring"); - assertEquals(en.getType(), ConfigHistory.TaskType.BEGIN); - assertEquals(en.getValue(), "configuring_test"); + assertEquals("configuring", en.getPid()); + assertEquals(ConfigHistory.TaskType.BEGIN, en.getType()); + assertEquals("configuring_test", en.getValue()); } @Test public void configured() throws Exception { ConfigHistory en = ConfigHistory.configured("configured", "configured_test"); assertNotNull(en); - assertEquals(en.getPid(), "configured"); - assertEquals(en.getType(), ConfigHistory.TaskType.END); - assertEquals(en.getValue(), "configured_test"); + assertEquals("configured", en.getPid()); + assertEquals(ConfigHistory.TaskType.END, en.getType()); + assertEquals("configured_test", en.getValue()); } @Test public void propertySet() throws Exception { ConfigHistory en = ConfigHistory.propertySet("propertySet", "propertySet.key", "new", "prev"); assertNotNull(en); - assertEquals(en.getPid(), "propertySet"); - assertEquals(en.getType(), ConfigHistory.TaskType.PROPERTY); - assertEquals(en.getKey(), "propertySet.key"); - assertEquals(en.getPreviousValue(), "prev"); - assertEquals(en.getValue(),"new"); + assertEquals("propertySet", en.getPid()); + assertEquals(ConfigHistory.TaskType.PROPERTY, en.getType()); + assertEquals("propertySet.key", en.getKey()); + assertEquals("prev", en.getPreviousValue()); + assertEquals("new", en.getValue()); } @Test public void setGetMaxHistory() throws Exception { ConfigHistory.setMaxHistory(1000); - assertEquals(ConfigHistory.getMaxHistory(),1000); + assertEquals(1000, ConfigHistory.getMaxHistory()); } @Test @@ -88,13 +88,13 @@ public class ConfigHistoryTest { } List<ConfigHistory> hist = ConfigHistory.getHistory("history1"); assertNotNull(hist); - assertTrue(hist.size()==102); + assertEquals(102, hist.size()); hist = ConfigHistory.getHistory("history2"); assertNotNull(hist); - assertTrue(hist.size()==100); + assertEquals(100, hist.size()); hist = ConfigHistory.getHistory(null); assertNotNull(hist); - assertTrue(hist.size()>=202); + assertTrue(hist.size()>202); } @Test @@ -107,27 +107,30 @@ public class ConfigHistoryTest { } List<ConfigHistory> hist = ConfigHistory.getHistory("history3"); assertNotNull(hist); - assertTrue(hist.size()==100); - assertEquals(ConfigHistory.getHistory("history4").size(), 100); + assertEquals(100, hist.size()); + assertEquals(100, ConfigHistory.getHistory("history4").size()); ConfigHistory.clearHistory("history3"); - assertEquals(ConfigHistory.getHistory("history3").size(), 0); - assertEquals(ConfigHistory.getHistory("history4").size(), 100); + assertEquals(0, ConfigHistory.getHistory("history3").size()); + assertEquals(100, ConfigHistory.getHistory("history4").size()); ConfigHistory.clearHistory(null); - assertEquals(ConfigHistory.getHistory().size(), 0); - assertEquals(ConfigHistory.getHistory("history4").size(), 0); + assertTrue(ConfigHistory.getHistory().isEmpty()); + assertTrue(ConfigHistory.getHistory("history4").isEmpty()); } @Test public void setPreviousValue() throws Exception { + // TODO } @Test public void getValue() throws Exception { + // TODO } @Test public void getKey() throws Exception { + // TODO } @Test @@ -135,14 +138,14 @@ public class ConfigHistoryTest { for(int i=0;i<10;i++){ ConfigHistory.propertySet("save", "getHistory"+i, "prev"+i, "new"+i); } - assertEquals(ConfigHistory.getHistory("save").size(), 10); + assertEquals(10, ConfigHistory.getHistory("save").size()); Dictionary<String,Object> config = new Hashtable<>(); ConfigHistory.save(config); - assertEquals(ConfigHistory.getHistory("save").size(), 10); + assertEquals(10, ConfigHistory.getHistory("save").size()); ConfigHistory.clearHistory(); - assertEquals(ConfigHistory.getHistory("save").size(), 0); + assertTrue(ConfigHistory.getHistory("save").isEmpty()); ConfigHistory.restore(config); - assertEquals(ConfigHistory.getHistory("save").size(), 10); + assertEquals(10, ConfigHistory.getHistory("save").size()); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/864f0200/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java ---------------------------------------------------------------------- diff --git a/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java b/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java index d597557..65e8499 100644 --- a/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java +++ b/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java @@ -40,7 +40,6 @@ public class TamayaConfigPluginTest extends AbstractOSGITest{ @Test public void testOperationMode() throws Exception { - Policy om = tamayaConfigPlugin.getDefaultPolicy(); tamayaConfigPlugin.setDefaultPolicy(Policy.EXTEND); assertEquals(Policy.EXTEND, tamayaConfigPlugin.getDefaultPolicy()); tamayaConfigPlugin.setDefaultPolicy(Policy.OVERRIDE); @@ -73,8 +72,6 @@ public class TamayaConfigPluginTest extends AbstractOSGITest{ @Test public void testSetGetConfigValue() throws Exception { - Dictionary<String,Object> config = new Hashtable<>(); - String val = (String)((TamayaConfigPlugin)tamayaConfigPlugin).getConfigValue("foo"); ((TamayaConfigPlugin)tamayaConfigPlugin).setConfigValue("bar", "foo"); assertEquals(((TamayaConfigPlugin)tamayaConfigPlugin).getConfigValue("bar"), "foo"); } @@ -84,21 +81,21 @@ public class TamayaConfigPluginTest extends AbstractOSGITest{ org.apache.tamaya.Configuration config = ((TamayaConfigPlugin)tamayaConfigPlugin).getTamayaConfiguration("java."); assertNotNull(config); assertNull(config.get("jlkjllj")); - assertEquals(config.get("home"),System.getProperty("java.home")); + assertEquals(System.getProperty("java.home"), config.get("home")); } @Test public void getUpdateConfig() throws Exception { Dictionary<String, Object> config = tamayaConfigPlugin.updateConfig(TamayaConfigPlugin.COMPONENTID); assertNotNull(config); - assertEquals(config.get("java.home"), System.getProperty("java.home")); + assertEquals(System.getProperty("java.home"), config.get("java.home")); } @Test public void getUpdateConfig_DryRun() throws Exception { Dictionary<String, Object> config = tamayaConfigPlugin.updateConfig(TamayaConfigPlugin.COMPONENTID, true); assertNotNull(config); - assertEquals(config.get("java.home"), System.getProperty("java.home")); + assertEquals(System.getProperty("java.home"), config.get("java.home")); } @Test @@ -112,7 +109,7 @@ public class TamayaConfigPluginTest extends AbstractOSGITest{ public void getPluginConfig() throws Exception { Dictionary<String, Object> config = ((TamayaConfigPlugin)tamayaConfigPlugin).getPluginConfig(); assertNotNull(config); - assertEquals(config, super.getProperties(TamayaConfigPlugin.COMPONENTID)); + assertEquals(super.getProperties(TamayaConfigPlugin.COMPONENTID), config); } @Test @@ -124,12 +121,12 @@ public class TamayaConfigPluginTest extends AbstractOSGITest{ TamayaConfigPlugin plugin = new TamayaConfigPlugin(bundleContext); om = plugin.getDefaultPolicy(); assertNotNull(om); - assertEquals(om, Policy.UPDATE_ONLY); + assertEquals(Policy.UPDATE_ONLY, om); pluginConfig.put(Policy.class.getSimpleName(), Policy.OVERRIDE.toString()); plugin = new TamayaConfigPlugin(bundleContext); om = plugin.getDefaultPolicy(); assertNotNull(om); - assertEquals(om, Policy.OVERRIDE); + assertEquals(Policy.OVERRIDE, om); } @Test @@ -142,12 +139,12 @@ public class TamayaConfigPluginTest extends AbstractOSGITest{ assertFalse(config.getProperties().isEmpty()); assertTrue(config.getProperties().size() > 4); // Override should add additional values - assertEquals(config.getProperties().get("my.testProperty1"), "success1"); - assertEquals(config.getProperties().get("my.testProperty2"), "success2"); - assertEquals(config.getProperties().get("my.testProperty3"), "success3"); - assertEquals(config.getProperties().get("my.testProperty4"), "success4"); + assertEquals("success1", config.getProperties().get("my.testProperty1")); + assertEquals("success2", config.getProperties().get("my.testProperty2")); + assertEquals("success3", config.getProperties().get("my.testProperty3")); + assertEquals("success4", config.getProperties().get("my.testProperty4")); // Extend should also update any existing values... - assertEquals(config.getProperties().get("java.version"), "Java2000"); + assertEquals("Java2000", config.getProperties().get("java.version")); tamayaConfigPlugin.restoreBackup("tamaya"); } @@ -165,12 +162,12 @@ public class TamayaConfigPluginTest extends AbstractOSGITest{ assertFalse(config.getProperties().isEmpty()); assertTrue(config.getProperties().size() > 4); // Override should add additional values - assertEquals(config.getProperties().get("my.testProperty1"), "success1"); - assertEquals(config.getProperties().get("my.testProperty2"), "success2"); - assertEquals(config.getProperties().get("my.testProperty3"), "success3"); - assertEquals(config.getProperties().get("my.testProperty4"), "success4"); + assertEquals("success1", config.getProperties().get("my.testProperty1")); + assertEquals("success2", config.getProperties().get("my.testProperty2")); + assertEquals("success3", config.getProperties().get("my.testProperty3")); + assertEquals("success4", config.getProperties().get("my.testProperty4")); // Extend should also update any existing values... - assertEquals(config.getProperties().get("java.version"), "Java2000"); + assertEquals("Java2000", config.getProperties().get("java.version")); tamayaConfigPlugin.restoreBackup("tamaya"); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/864f0200/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/BackupCommandsTest.java ---------------------------------------------------------------------- diff --git a/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/BackupCommandsTest.java b/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/BackupCommandsTest.java index 20d2a78..f42db0b 100644 --- a/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/BackupCommandsTest.java +++ b/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/BackupCommandsTest.java @@ -43,7 +43,7 @@ public class BackupCommandsTest extends AbstractOSGITest { result = BackupCommands.createBackup(tamayaConfigPlugin, cm, "createBackup", false); assertNotNull(result); assertTrue(result.contains("createBackup")); - assertTrue(result.contains("Creating backup failed")); + assertTrue(result.contains("Creating of backup failed")); assertTrue(result.contains("already existing")); assertTrue(tamayaConfigPlugin.containsBackup("createBackup")); // any existing backups gets overridden
