You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2017/09/29 19:53:51 UTC
incubator-tamaya-sandbox git commit: TAMAYA-300 Fixed tests and
plugin configuration method.
Repository: incubator-tamaya-sandbox
Updated Branches:
refs/heads/master 28d81b959 -> 0cb95ed1c
TAMAYA-300 Fixed tests and plugin configuration method.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/0cb95ed1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/0cb95ed1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/0cb95ed1
Branch: refs/heads/master
Commit: 0cb95ed1c152ad1e5d726b24df9b56e5ffcf0292
Parents: 28d81b9
Author: Anatole Tresch <an...@apache.org>
Authored: Fri Sep 29 21:53:41 2017 +0200
Committer: Anatole Tresch <an...@apache.org>
Committed: Fri Sep 29 21:53:41 2017 +0200
----------------------------------------------------------------------
.../org/apache/tamaya/osgi/ConfigChanger.java | 27 +++++-----
.../apache/tamaya/osgi/TamayaConfigPlugin.java | 2 +-
.../apache/tamaya/osgi/AbstractOSGITest.java | 14 ++++-
.../tamaya/osgi/TamayaConfigPluginTest.java | 54 +++++++++++++++-----
4 files changed, 66 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/0cb95ed1/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java
index 71fe18b..3c5826a 100644
--- a/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java
@@ -140,7 +140,6 @@ final class ConfigChanger {
public void modifyConfiguration(String pid, org.apache.tamaya.Configuration config, Dictionary<String, Object> dictionary, OperationMode opMode) {
LOG.info(() -> "Updating configuration for PID: " + pid + "...");
dictionary.put("tamaya.modified.at", new Date().toString());
- ConfigHistory.propertySet(pid, "tamaya.modified.at", dictionary.get("tamaya.modified.at"), null);
Map<String, Object> dictionaryMap = new HashMap<>();
Enumeration<String> keys = dictionary.keys();
@@ -155,19 +154,19 @@ final class ConfigChanger {
if(configuredValue.equals(dictEntry.getValue())){
continue;
}
- }
- switch (opMode) {
- case EXTEND:
- break;
- case OVERRIDE:
- LOG.info(() -> "Setting key " + dictEntry.getKey() + " to " + configuredValue);
- ConfigHistory.propertySet(pid,dictEntry.getKey(), configuredValue, dictEntry.getValue());
- dictionary.put(dictEntry.getKey(), configuredValue);
- break;
- case UPDATE_ONLY:
- LOG.info(() -> "Setting key " + dictEntry.getKey() + " to " + configuredValue);
- ConfigHistory.propertySet(pid,dictEntry.getKey(), configuredValue, dictEntry.getValue());
- dictionary.put(dictEntry.getKey(), configuredValue);
+ switch (opMode) {
+ case EXTEND:
+ break;
+ case OVERRIDE:
+ LOG.info(() -> "Setting key " + dictEntry.getKey() + " to " + configuredValue);
+ ConfigHistory.propertySet(pid,dictEntry.getKey(), configuredValue, dictEntry.getValue());
+ dictionary.put(dictEntry.getKey(), configuredValue);
+ break;
+ case UPDATE_ONLY:
+ LOG.info(() -> "Setting key " + dictEntry.getKey() + " to " + configuredValue);
+ ConfigHistory.propertySet(pid,dictEntry.getKey(), configuredValue, dictEntry.getValue());
+ dictionary.put(dictEntry.getKey(), configuredValue);
+ }
}
}
for (Map.Entry<String, String> configEntry : config.getProperties().entrySet()) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/0cb95ed1/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java
index 0d947fc..d0bf7e3 100644
--- a/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java
@@ -226,7 +226,7 @@ public class TamayaConfigPlugin implements BundleListener, ServiceListener{
}
private void initDefaultOpMode(Dictionary<String,Object> props) {
- String opVal = (String)props.get(OperationMode.class.getName());
+ String opVal = (String)props.get(OperationMode.class.getSimpleName());
if(opVal!=null){
try{
defaultOpMode = OperationMode.valueOf(opVal);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/0cb95ed1/osgi/common/src/test/java/org/apache/tamaya/osgi/AbstractOSGITest.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/AbstractOSGITest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/AbstractOSGITest.java
index ac3de0e..3794afa 100644
--- a/osgi/common/src/test/java/org/apache/tamaya/osgi/AbstractOSGITest.java
+++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/AbstractOSGITest.java
@@ -55,11 +55,18 @@ public abstract class AbstractOSGITest {
protected TamayaConfigPlugin tamayaConfigPlugin;
+ protected Dictionary<String,Object> getProperties(String pid){
+ return this.properties.get(pid);
+ }
+
@Before
public void setup()throws Exception{
- when(cm.getConfiguration(any())).then(invocation -> {
+ doAnswer(invocation -> {
+ return initConfigurationMock((String)invocation.getArguments()[0]);
+ }).when(cm).getConfiguration(any());
+ doAnswer(invocation -> {
return initConfigurationMock((String)invocation.getArguments()[0]);
- });
+ }).when(cm).getConfiguration(any(), any());
doReturn(new Bundle[0]).when(bundleContext).getBundles();
doReturn(cmRef).when(bundleContext).getServiceReference(ConfigurationAdmin.class);
doReturn(cm).when(bundleContext).getService(cmRef);
@@ -81,6 +88,9 @@ public abstract class AbstractOSGITest {
if(props==null){
props = new Hashtable<>();
properties.put(pid, props);
+ for(Map.Entry en:System.getProperties().entrySet()){
+ props.put(en.getKey().toString(), en.getValue());
+ }
}
return new Hashtable<>(props);
}).when(config).getProperties();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/0cb95ed1/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java
index accc0f0..712ed3b 100644
--- a/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java
+++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java
@@ -18,27 +18,14 @@
*/
package org.apache.tamaya.osgi;
-import javafx.beans.binding.Bindings;
-import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import javax.inject.Inject;
-
-import java.util.Collections;
import java.util.Dictionary;
import java.util.Hashtable;
import static org.junit.Assert.*;
-import static org.mockito.Mockito.doReturn;
/**
* Created by atsticks on 10.12.16.
@@ -100,10 +87,49 @@ public class TamayaConfigPluginTest extends AbstractOSGITest{
assertEquals(config.get("home"),System.getProperty("java.home"));
}
+ @Test
public void getUpdateConfig() throws Exception {
- Dictionary<String, Object> config = tamayaConfigPlugin.updateConfig("getUpdateConfig");
+ Dictionary<String, Object> config = tamayaConfigPlugin.updateConfig(TamayaConfigPlugin.COMPONENTID);
+ assertNotNull(config);
+ assertEquals(config.get("java.home"), System.getProperty("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"));
+ }
+
+ @Test
+ public void getUpdateConfig_Explicit_DryRun() throws Exception {
+ Dictionary<String, Object> config = tamayaConfigPlugin.updateConfig(TamayaConfigPlugin.COMPONENTID, OperationMode.EXTEND, true, true);
assertNotNull(config);
assertEquals(config.get("java.home"), System.getProperty("java.home"));
}
+ @Test
+ public void getPluginConfig() throws Exception {
+ Dictionary<String, Object> config = tamayaConfigPlugin.getPluginConfig();
+ assertNotNull(config);
+ assertEquals(config, super.getProperties(TamayaConfigPlugin.COMPONENTID));
+ }
+
+ @Test
+ public void getDefaultOperationMode() throws Exception {
+ OperationMode om = tamayaConfigPlugin.getDefaultOperationMode();
+ assertNotNull(om);
+ Dictionary<String,Object> pluginConfig = super.getProperties(TamayaConfigPlugin.COMPONENTID);
+ pluginConfig.put(OperationMode.class.getSimpleName(), OperationMode.UPDATE_ONLY.toString());
+ TamayaConfigPlugin plugin = new TamayaConfigPlugin(bundleContext);
+ om = plugin.getDefaultOperationMode();
+ assertNotNull(om);
+ assertEquals(om, OperationMode.UPDATE_ONLY);
+ pluginConfig.put(OperationMode.class.getSimpleName(), OperationMode.OVERRIDE.toString());
+ plugin = new TamayaConfigPlugin(bundleContext);
+ om = plugin.getDefaultOperationMode();
+ assertNotNull(om);
+ assertEquals(om, OperationMode.OVERRIDE);
+ }
+
}
\ No newline at end of file