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/30 21:33:02 UTC
incubator-tamaya-sandbox git commit: TAMAYA-300 Added tests and fixes.
Repository: incubator-tamaya-sandbox
Updated Branches:
refs/heads/master 0cb95ed1c -> 55b1f20ed
TAMAYA-300 Added tests and fixes.
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/55b1f20e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/55b1f20e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/55b1f20e
Branch: refs/heads/master
Commit: 55b1f20eda32fa6adc166e09227e28541a5f9785
Parents: 0cb95ed
Author: Anatole Tresch <an...@apache.org>
Authored: Sat Sep 30 22:27:16 2017 +0200
Committer: Anatole Tresch <an...@apache.org>
Committed: Sat Sep 30 22:27:16 2017 +0200
----------------------------------------------------------------------
.../java/org/apache/tamaya/osgi/Activator.java | 28 +--
.../org/apache/tamaya/osgi/ConfigHistory.java | 2 +-
.../tamaya/osgi/commands/BackupCommands.java | 10 +-
.../tamaya/osgi/commands/ConfigCommands.java | 32 +--
.../tamaya/osgi/commands/HistoryCommands.java | 8 +-
.../org/apache/tamaya/osgi/ActivatorTest.java | 43 ++++
.../osgi/commands/BackupCommandsTest.java | 105 ++++++++++
.../osgi/commands/ConfigCommandsTest.java | 206 +++++++++++++++++++
.../osgi/commands/HistoryCommandsTest.java | 82 ++++++++
9 files changed, 471 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/55b1f20e/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java
index a1522a1..d3a138f 100644
--- a/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java
@@ -53,39 +53,19 @@ public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
ServiceReference<ConfigurationAdmin> cmRef = context.getServiceReference(ConfigurationAdmin.class);
ConfigurationAdmin cm = context.getService(cmRef);
- Configuration configuration = cm.getConfiguration("tamaya-osgi", null);
- Dictionary<String, Object> props = null;
- if (configuration != null
- && configuration.getProperties() != null) {
- props = configuration.getProperties();
- } else {
- props = new Hashtable<>();
- }
- String ranking = context.getProperty(Constants.SERVICE_RANKING);
- if (ranking == null) {
- ranking = System.getProperty(Constants.SERVICE_RANKING);
- }
- if (ranking == null) {
- ranking = DEFAULT_RANKING.toString();
- LOG.fine("Using default ranking for Tamaya OSGI Config plugin: " + DEFAULT_RANKING);
- } else {
- ranking = Integer.valueOf(ranking).toString();
- LOG.fine("Using custom ranking for Tamaya OSGI Config plugin: " + ranking);
- }
- props.put(Constants.SERVICE_RANKING, DEFAULT_RANKING);
+ Configuration configuration = cm.getConfiguration(TamayaConfigPlugin.COMPONENTID, null);
this.plugin = new TamayaConfigPlugin(context);
- LOG.info("Registering Tamaya OSGI Config plugin with ranking: " + ranking);
+ Dictionary<String, Object> props = new Hashtable<>();
+ props.put(Constants.SERVICE_RANKING, DEFAULT_RANKING);
+ LOG.info("Registering Tamaya OSGI Config plugin as service...");
registration = context.registerService(
TamayaConfigPlugin.class,
this.plugin, props);
- LOG.info("Registered Tamaya OSGI Config plugin.");
- configuration.update(props);
}
@Override
public void stop(BundleContext context) throws Exception {
if (registration != null) {
- context.removeBundleListener(this.plugin);
registration.unregister();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/55b1f20e/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java
index 8e1b822..513c54c 100644
--- a/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java
@@ -151,7 +151,7 @@ public final class ConfigHistory implements Serializable{
*/
public static void clearHistory(String pid){
synchronized (history){
- if(pid==null || pid.isEmpty()) {
+ if("*".equals(pid)) {
history.clear();
}else{
history.removeAll(history(pid));
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/55b1f20e/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/BackupCommands.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/BackupCommands.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/BackupCommands.java
index d49f1cd..6487fe1 100644
--- a/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/BackupCommands.java
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/BackupCommands.java
@@ -48,10 +48,12 @@ public final class BackupCommands {
Backups.set(pid, props);
return "Backup created, PID = " + pid + '\n' +
printProps(props);
+ }else{
+ return "Creating backup failed. Backup already existing, PID = " + pid;
}
}
}
- return "No Config found, PID = " + pid;
+ return "Creating backup failed. No Config found, PID = " + pid;
}
public static String deleteBackup(String pid) throws IOException {
@@ -83,12 +85,12 @@ public final class BackupCommands {
}else {
try{
if(plugin.restoreBackup(pid)){
- return pid + " -> restored.\n";
+ return "Backup restored for PID: "+pid+"\n";
}else{
- return pid + " -> no backup found.\n";
+ return "Backup restore failed for PID "+pid+": no backup found.\n";
}
}catch(Exception e){
- return pid + " -> failed: " + e + '\n';
+ return "Backup restore failed for PID "+pid+", error: " + e + '\n';
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/55b1f20e/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/ConfigCommands.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/ConfigCommands.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/ConfigCommands.java
index 23ba263..ec24308 100644
--- a/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/ConfigCommands.java
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/ConfigCommands.java
@@ -55,7 +55,11 @@ public final class ConfigCommands {
if(filter!=null){
config = config.with(ConfigurationFunctions.section(filter, false));
}
- return config.query(ConfigurationFunctions.textInfo());
+ return "Tamaya Configuration\n" +
+ "--------------------\n" +
+ "Section: "+section +"\n" +
+ (filter!=null?"Filter: "+filter + "\n":"") +
+ config.query(ConfigurationFunctions.textInfo());
}
public static String readTamayaConfig4PID(String pid, String filter) {
@@ -93,8 +97,8 @@ public final class ConfigCommands {
return "No Config present for PID: " + pid;
}
StringBuilder b = new StringBuilder();
- b.append("OSGI Configuration for PID: " + pid);
- b.append("------------------------------------------------");
+ b.append("OSGI Configuration for PID: " + pid + '\n');
+ b.append("-----------------------------------------------------\n");
TreeMap<String,String> result = new TreeMap<>();
Enumeration<String> keys = config.keys();
while(keys.hasMoreElements()){
@@ -124,14 +128,14 @@ public final class ConfigCommands {
if(propertysource!=null){
PropertySource ps = config.getContext().getPropertySource(propertysource);
if(ps==null){
- return "ERR: No such propertysource: " + propertysource;
+ return "ERR: No such Property Source: " + propertysource;
}else {
PropertyValue val = ps.get(key);
if(val==null){
- return "ERR: PropertySource: " + propertysource + " - undefined key: " + key;
+ return "ERR: Property Source: " + propertysource + " - undefined key: " + key;
}else {
if(extended) {
- return StringUtil.format("PropertySource", 25) + StringUtil.format("Value", 25) + '\n' +
+ return StringUtil.format("Property Source", 25) + StringUtil.format("Value", 25) + '\n' +
StringUtil.format(propertysource, 25) + StringUtil.format(val.getValue(), 55);
}else{
return val.getValue();
@@ -141,7 +145,7 @@ public final class ConfigCommands {
}else{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
- pw.println(StringUtil.format("PropertySource", 25) + StringUtil.format("Value", 25));
+ pw.println(StringUtil.format("Property Source", 25) + StringUtil.format("Value", 25));
for(PropertySource ps:config.getContext().getPropertySources()){
PropertyValue val = ps.get(key);
if(val!=null){
@@ -162,10 +166,12 @@ public final class ConfigCommands {
if(propertysource!=null){
PropertySource ps = config.getContext().getPropertySource(propertysource);
if(ps==null){
- return "No such propertysource: " + propertysource;
+ return "No such Property Source: " + propertysource;
}else {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
+ pw.println("Property Source");
+ pw.println("---------------");
pw.println(StringUtil.format("ID:", 20) + ps.getName());
pw.println(StringUtil.format("Ordinal:", 20) + ps.getOrdinal());
pw.println(StringUtil.format("Class:", 20) + ps.getClass().getName());
@@ -201,13 +207,15 @@ public final class ConfigCommands {
Configuration config = ConfigurationProvider.getConfiguration();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
- pw.print(StringUtil.format("ID", 20));
+ pw.println("Property Sources");
+ pw.println("----------------");
+ pw.print(StringUtil.format("ID", 30));
pw.print(StringUtil.format("Ordinal", 20));
pw.print(StringUtil.format("Class", 40));
pw.println(StringUtil.format("Property Count", 5));
pw.println(StringUtil.printRepeat("-", 80));
for(PropertySource ps:config.getContext().getPropertySources()){
- pw.print(StringUtil.format(ps.getName(), 20));
+ pw.print(StringUtil.format(ps.getName(), 30));
pw.print(StringUtil.format(String.valueOf(ps.getOrdinal()), 20));
pw.print(StringUtil.format(ps.getClass().getName(), 40));
pw.println(StringUtil.format(String.valueOf(ps.getProperties().size()), 5));
@@ -219,7 +227,7 @@ public final class ConfigCommands {
public static String setDefaultEnabled(TamayaConfigPlugin configPlugin, boolean enabled) throws IOException {
configPlugin.setTamayaEnabledByDefault(enabled);
- return "tamaya.enabled="+enabled;
+ return "tamaya.default-enabled="+enabled;
}
public static String getDefaultEnabled(TamayaConfigPlugin configPlugin) {
@@ -228,7 +236,7 @@ public final class ConfigCommands {
public static String setAutoUpdateEnabled(TamayaConfigPlugin configPlugin, boolean enabled) {
configPlugin.setAutoUpdateEnabled(enabled);
- return "tamaya.autoUpdate="+enabled;
+ return "tamaya.auto-update="+enabled;
}
public static String getAutoUpdateEnabled(TamayaConfigPlugin configPlugin) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/55b1f20e/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java
index 6429e8d..6b282f5 100644
--- a/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java
@@ -41,7 +41,7 @@ public final class HistoryCommands{
public static String clearHistory(String pid) throws IOException {
int size = ConfigHistory.history(pid).size();
ConfigHistory.clearHistory(pid);
- return "Deleted entries: " + size;
+ return "Deleted history for PID: " + pid;
}
public static String getHistory(String pid, String... events) throws IOException {
@@ -66,13 +66,13 @@ public final class HistoryCommands{
return sw.toString();
}
- public static int getMaxHistorySize(){
- return ConfigHistory.getMaxHistory();
+ public static String getMaxHistorySize(){
+ return String.valueOf(ConfigHistory.getMaxHistory());
}
public static String setMaxHistorySize(int maxSize){
ConfigHistory.setMaxHistory(maxSize);
- return "history.maxSize="+maxSize;
+ return "tamaya.max-history-size="+maxSize;
}
private static List<ConfigHistory> filterTypes(List<ConfigHistory> history, String... eventTypes) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/55b1f20e/osgi/common/src/test/java/org/apache/tamaya/osgi/ActivatorTest.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/ActivatorTest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/ActivatorTest.java
new file mode 100644
index 0000000..35a402b
--- /dev/null
+++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/ActivatorTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.osgi;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+
+/**
+ * Created by atsti on 29.09.2017.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class ActivatorTest extends AbstractOSGITest{
+
+ @Test
+ public void startStop() throws Exception {
+ Activator activator = new Activator();
+ activator.start(super.bundleContext);
+ verify(bundleContext).registerService(eq(TamayaConfigPlugin.class), anyObject(), anyObject());
+ activator.stop(super.bundleContext);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/55b1f20e/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/BackupCommandsTest.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/BackupCommandsTest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/BackupCommandsTest.java
new file mode 100644
index 0000000..c7a5f62
--- /dev/null
+++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/BackupCommandsTest.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.osgi.commands;
+
+import org.apache.tamaya.osgi.AbstractOSGITest;
+import org.apache.tamaya.osgi.Backups;
+import org.apache.tamaya.osgi.TamayaConfigPlugin;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import java.util.Hashtable;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by atsti on 30.09.2017.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class BackupCommandsTest extends AbstractOSGITest {
+ @Test
+ public void createBackup() throws Exception {
+ String result = BackupCommands.createBackup(cm, "createBackup", false);
+ assertNotNull(result);
+ assertTrue(result.contains("createBackup"));
+ assertTrue(result.contains("Backup created"));
+ assertTrue(Backups.contains("createBackup"));
+ // A backup with the given name already exists, so it fails
+ result = BackupCommands.createBackup(cm, "createBackup", false);
+ assertNotNull(result);
+ assertTrue(result.contains("createBackup"));
+ assertTrue(result.contains("Creating backup failed"));
+ assertTrue(result.contains("already existing"));
+ assertTrue(Backups.contains("createBackup"));
+ // any existing backups gets overridden
+ result = BackupCommands.createBackup(cm, "createBackup", true);
+ assertNotNull(result);
+ assertTrue(result.contains("createBackup"));
+ assertTrue(result.contains("Backup created"));
+ assertTrue(Backups.contains("createBackup"));
+ }
+
+ @Test
+ public void deleteBackup() throws Exception {
+ BackupCommands.createBackup(cm, "deleteBackup", false);
+ assertTrue(Backups.contains("deleteBackup"));
+ String result = BackupCommands.deleteBackup("deleteBackup");
+ assertNotNull(result);
+ assertTrue(result.contains("deleteBackup"));
+ assertTrue(result.contains("Backup deleted"));
+ assertFalse(Backups.contains("deleteBackup"));
+ }
+
+ @Test
+ public void restoreBackup() throws Exception {
+ BackupCommands.createBackup(cm, "restoreBackup", false);
+ assertTrue(Backups.contains("restoreBackup"));
+ String result = BackupCommands.restoreBackup(tamayaConfigPlugin, "restoreBackup");
+ assertNotNull(result);
+ assertTrue(result.contains("restoreBackup"));
+ assertTrue(result.contains("Backup restored"));
+ BackupCommands.deleteBackup("restoreBackup");
+ assertFalse(Backups.contains("restoreBackup"));
+ result = BackupCommands.restoreBackup(tamayaConfigPlugin, "restoreBackup");
+ assertTrue(result.contains("Backup restore failed"));
+ assertTrue(result.contains("no backup found"));
+ }
+
+ @Test
+ public void listBackup() throws Exception {
+ BackupCommands.createBackup(cm, "listBackup", false);
+ String result = BackupCommands.listBackup("listBackup");
+ result.concat("listBackup");
+ result.contains("pid");
+ }
+
+ @Test
+ public void printProps() throws Exception {
+ Hashtable<String,Object> props = new Hashtable<>();
+ props.put("k1", "v1");
+ props.put("k2", "v2");
+ String result = BackupCommands.printProps(props);
+ assertTrue(result.contains("k1"));
+ assertTrue(result.contains("k2"));
+ assertTrue(result.contains("v1"));
+ assertTrue(result.contains("v2"));
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/55b1f20e/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/ConfigCommandsTest.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/ConfigCommandsTest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/ConfigCommandsTest.java
new file mode 100644
index 0000000..3d180e7
--- /dev/null
+++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/ConfigCommandsTest.java
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.osgi.commands;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.osgi.AbstractOSGITest;
+import org.apache.tamaya.osgi.OperationMode;
+import org.apache.tamaya.osgi.TamayaConfigPlugin;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by atsti on 30.09.2017.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class ConfigCommandsTest extends AbstractOSGITest{
+ @Test
+ public void getInfo() throws Exception {
+ String result = ConfigCommands.getInfo(tamayaConfigPlugin);
+ assertNotNull(result);
+ System.out.println(result);
+ assertTrue(result.contains("Property Sources"));
+ assertTrue(result.contains("Property Converter"));
+ assertTrue(result.contains("Property Filter"));
+ assertTrue(result.contains("ConfigurationContext"));
+ assertTrue(result.contains("Configuration"));
+ }
+
+ @Test
+ public void readTamayaConfig() throws Exception {
+ String result = ConfigCommands.readTamayaConfig("java", null);
+ assertNotNull(result);
+ System.out.println(result);
+ assertTrue(result.contains(".version"));
+ assertTrue(result.contains("Section"));
+ assertTrue(result.contains("java"));
+ result = ConfigCommands.readTamayaConfig("java", "version");
+ assertNotNull(result);
+ assertFalse(result.contains(".version"));
+ assertTrue(result.contains("Section"));
+ assertTrue(result.contains("java"));
+ assertTrue(result.contains("Filter"));
+ assertTrue(result.contains("version"));
+ assertFalse(result.contains("java.vendor"));
+ System.out.println("readTamayaConfig: " + result);
+ }
+
+ @Test
+ public void readTamayaConfig4PID() throws Exception {
+ String result = ConfigCommands.readTamayaConfig4PID("test", null);
+ assertNotNull(result);
+ System.out.println(result);
+ assertTrue(result.contains("Configuration"));
+ assertTrue(result.contains("test"));
+ }
+
+ @Test
+ public void applyTamayaConfiguration() throws Exception {
+ String result = ConfigCommands.applyTamayaConfiguration(tamayaConfigPlugin, "applyTamayaConfiguration", OperationMode.OVERRIDE.toString(), true);
+ assertNotNull(result);
+ System.out.println(result);
+ assertTrue(result.contains("OSGI Configuration for PID"));
+ assertTrue(result.contains("applyTamayaConfiguration"));
+ assertTrue(result.contains("OVERRIDE"));
+ assertTrue(result.contains("Applied"));
+ assertTrue(result.contains("false"));
+ }
+
+ @Test
+ public void readOSGIConfiguration() throws Exception {
+ String result = ConfigCommands.readOSGIConfiguration(tamayaConfigPlugin, "readOSGIConfiguration", "java");
+ assertNotNull(result);
+ System.out.println(result);
+ assertTrue(result.contains("OSGI Configuration for PID"));
+ assertTrue(result.contains("readOSGIConfiguration"));
+ assertTrue(result.contains("java.home"));
+ }
+
+ @Test
+ public void getDefaultOpPolicy() throws Exception {
+ OperationMode mode = tamayaConfigPlugin.getDefaultOperationMode();
+ String result = ConfigCommands.getDefaultOpPolicy(tamayaConfigPlugin);
+ assertNotNull(result);
+ assertTrue(result.contains(mode.toString()));
+ }
+
+ @Test
+ public void setDefaultOpPolicy() throws Exception {
+ String result = ConfigCommands.setDefaultOpPolicy(tamayaConfigPlugin, OperationMode.EXTEND.toString());
+ assertNotNull(result);
+ assertTrue(result.contains("EXTEND"));
+ assertEquals(tamayaConfigPlugin.getDefaultOperationMode(), OperationMode.EXTEND);
+ result = ConfigCommands.setDefaultOpPolicy(tamayaConfigPlugin, OperationMode.UPDATE_ONLY.toString());
+ assertNotNull(result);
+ assertTrue(result.contains("UPDATE_ONLY"));
+ assertEquals(tamayaConfigPlugin.getDefaultOperationMode(), OperationMode.UPDATE_ONLY);
+ }
+
+ @Test
+ public void getProperty() throws Exception {
+ String result = ConfigCommands.getProperty("system-properties", "java.version", false);
+ assertNotNull(result);
+ System.out.println(result);
+ assertEquals(result, System.getProperty("java.version"));
+ result = ConfigCommands.getProperty("system-properties", "java.version", true);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void getPropertySource() throws Exception {
+ String result = ConfigCommands.getPropertySource("system-properties");
+ assertNotNull(result);
+ System.out.println(result);
+ assertTrue(result.contains("Property Source"));
+ assertTrue(result.contains("ID"));
+ assertTrue(result.contains("system-properties"));
+ assertTrue(result.contains("Ordinal"));
+ assertTrue(result.contains("java.version"));
+ }
+
+ @Test
+ public void getPropertySourceOverview() throws Exception {
+ String result = ConfigCommands.getPropertySourceOverview();
+ assertNotNull(result);
+ System.out.println(result);
+ assertTrue(result.contains("Ordinal"));
+ assertTrue(result.contains("Class"));
+ assertTrue(result.contains("Ordinal"));
+ assertTrue(result.contains("ID"));
+ assertTrue(result.contains("Ordinal"));
+ assertTrue(result.contains("system-properties"));
+ assertTrue(result.contains("environment-properties"));
+ assertTrue(result.contains("CLI"));
+ }
+
+ @Test
+ public void setDefaultEnabled() throws Exception {
+ String result = ConfigCommands.setDefaultEnabled(tamayaConfigPlugin, true);
+ assertNotNull(result);
+ System.out.println(result);
+ assertTrue(result.contains("tamaya.default-enabled=true"));
+ assertTrue(tamayaConfigPlugin.isTamayaEnabledByDefault());
+ result = ConfigCommands.setDefaultEnabled(tamayaConfigPlugin, false);
+ assertNotNull(result);
+ assertTrue(result.contains("tamaya.default-enabled=false"));
+ assertFalse(tamayaConfigPlugin.isTamayaEnabledByDefault());
+ }
+
+ @Test
+ public void getDefaultEnabled() throws Exception {
+ tamayaConfigPlugin.setTamayaEnabledByDefault(true);
+ String result = ConfigCommands.getDefaultEnabled(tamayaConfigPlugin);
+ System.out.println(result);
+ tamayaConfigPlugin.setTamayaEnabledByDefault(false);
+ result = ConfigCommands.getDefaultEnabled(tamayaConfigPlugin);
+ assertNotNull(result);
+ assertTrue(result.equals("false"));
+ }
+
+ @Test
+ public void setAutoUpdateEnabled() throws Exception {
+ String result = ConfigCommands.setAutoUpdateEnabled(tamayaConfigPlugin, true);
+ assertNotNull(result);
+ System.out.println(result);
+ assertTrue(result.contains("true"));
+ assertTrue(result.contains("auto-update"));
+ assertTrue(tamayaConfigPlugin.isAutoUpdateEnabled());
+ result = ConfigCommands.setAutoUpdateEnabled(tamayaConfigPlugin, false);
+ assertNotNull(result);
+ assertTrue(result.contains("false"));
+ assertTrue(result.contains("auto-update"));
+ assertFalse(tamayaConfigPlugin.isAutoUpdateEnabled());
+ }
+
+ @Test
+ public void getAutoUpdateEnabled() throws Exception {
+ tamayaConfigPlugin.setAutoUpdateEnabled(true);
+ String result = ConfigCommands.getAutoUpdateEnabled(tamayaConfigPlugin);
+ System.out.println(result);
+ assertTrue(result.contains("true"));
+ tamayaConfigPlugin.setAutoUpdateEnabled(false);
+ result = ConfigCommands.getAutoUpdateEnabled(tamayaConfigPlugin);
+ assertNotNull(result);
+ assertTrue(result.contains("false"));
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/55b1f20e/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/HistoryCommandsTest.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/HistoryCommandsTest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/HistoryCommandsTest.java
new file mode 100644
index 0000000..b8f63f2
--- /dev/null
+++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/HistoryCommandsTest.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.osgi.commands;
+
+import org.apache.tamaya.osgi.ConfigHistory;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by atsti on 30.09.2017.
+ */
+public class HistoryCommandsTest {
+ @Test
+ public void clearHistory() throws Exception {
+ ConfigHistory.configured("clearHistory1", "test");
+ ConfigHistory.configured("clearHistory2", "test");
+ assertTrue(ConfigHistory.history("clearHistory1").size()==1);
+ assertTrue(ConfigHistory.history("clearHistory2").size()==1);
+ assertTrue(ConfigHistory.history("clearHistory3").size()==0);
+ String result = HistoryCommands.clearHistory("clearHistory1");
+ assertTrue(result.contains("PID"));
+ assertTrue(result.contains("clearHistory1"));
+ assertTrue(ConfigHistory.history("clearHistory1").size()==0);
+ assertTrue(ConfigHistory.history("clearHistory2").size()==1);
+ assertTrue(ConfigHistory.history("clearHistory3").size()==0);
+ ConfigHistory.configured("clearHistory1", "test");
+ result = HistoryCommands.clearHistory("*");
+ assertTrue(result.contains("PID"));
+ assertTrue(result.contains("*"));
+ assertTrue(ConfigHistory.history("clearHistory1").size()==0);
+ assertTrue(ConfigHistory.history("clearHistory2").size()==0);
+ assertTrue(ConfigHistory.history("clearHistory3").size()==0);
+
+ }
+
+ @Test
+ public void getHistory() throws Exception {
+ ConfigHistory.configured("getHistory", "test");
+ ConfigHistory.configuring("getHistory", "test");
+ ConfigHistory.propertySet("getHistory", "k1", "v1", null);
+ ConfigHistory.propertySet("getHistory", "k2", null, "v2");
+ String result = HistoryCommands.getHistory("getHistory");
+ assertNotNull(result);
+ assertTrue(result.contains("k1"));
+ assertTrue(result.contains("v1"));
+ assertTrue(result.contains("test"));
+ result = HistoryCommands.getHistory("getHistory", ConfigHistory.TaskType.BEGIN.toString());
+ assertNotNull(result);
+ assertTrue(result.contains("getHistory"));
+ assertTrue(result.contains("test"));
+ assertFalse(result.contains("k1"));
+ assertFalse(result.contains("v2"));
+ }
+
+ @Test
+ public void getSetMaxHistorySize() throws Exception {
+ String result = HistoryCommands.getMaxHistorySize();
+ assertEquals(result, String.valueOf(ConfigHistory.getMaxHistory()));
+ result = HistoryCommands.setMaxHistorySize(111);
+ assertEquals(result, "tamaya.max-history-size=111");
+ result = HistoryCommands.getMaxHistorySize();
+ assertEquals(result, "111");
+ }
+
+}
\ No newline at end of file