http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/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 deleted file mode 100644 index a2c273b..0000000 --- a/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/ConfigCommandsTest.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * 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.Policy; -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", Policy.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 { - Policy mode = tamayaConfigPlugin.getDefaultPolicy(); - String result = ConfigCommands.getDefaultOpPolicy(tamayaConfigPlugin); - assertNotNull(result); - assertTrue(result.contains(mode.toString())); - } - - @Test - public void setDefaultOpPolicy() throws Exception { - String result = ConfigCommands.setDefaultOpPolicy(tamayaConfigPlugin, Policy.EXTEND.toString()); - assertNotNull(result); - assertTrue(result.contains("EXTEND")); - assertEquals(tamayaConfigPlugin.getDefaultPolicy(), Policy.EXTEND); - result = ConfigCommands.setDefaultOpPolicy(tamayaConfigPlugin, Policy.UPDATE_ONLY.toString()); - assertNotNull(result); - assertTrue(result.contains("UPDATE_ONLY")); - assertEquals(tamayaConfigPlugin.getDefaultPolicy(), Policy.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(TamayaConfigService.TAMAYA_ENABLED_PROP+"=true")); - assertTrue(tamayaConfigPlugin.isTamayaEnabledByDefault()); - result = ConfigCommands.setDefaultEnabled(tamayaConfigPlugin, false); - assertNotNull(result); - assertTrue(result.contains(TamayaConfigService.TAMAYA_ENABLED_PROP+"=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(TamayaConfigService.TAMAYA_AUTO_UPDATE_ENABLED_PROP)); - assertTrue(tamayaConfigPlugin.isAutoUpdateEnabled()); - result = ConfigCommands.setAutoUpdateEnabled(tamayaConfigPlugin, false); - assertNotNull(result); - assertTrue(result.contains("false")); - assertTrue(result.contains(TamayaConfigService.TAMAYA_AUTO_UPDATE_ENABLED_PROP)); - 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/eeab5ce0/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 deleted file mode 100644 index ad32857..0000000 --- a/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/HistoryCommandsTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.ConfigHistory; -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 HistoryCommandsTest extends AbstractOSGITest { - - @Test - public void clearHistory() throws Exception { - ConfigHistory.configured("clearHistory1", "test"); - ConfigHistory.configured("clearHistory2", "test"); - assertTrue(ConfigHistory.getHistory("clearHistory1").size()==1); - assertTrue(ConfigHistory.getHistory("clearHistory2").size()==1); - assertTrue(ConfigHistory.getHistory("clearHistory3").size()==0); - String result = HistoryCommands.clearHistory(tamayaConfigPlugin, "clearHistory1"); - assertTrue(result.contains("PID")); - assertTrue(result.contains("clearHistory1")); - assertTrue(ConfigHistory.getHistory("clearHistory1").size()==0); - assertTrue(ConfigHistory.getHistory("clearHistory2").size()==1); - assertTrue(ConfigHistory.getHistory("clearHistory3").size()==0); - ConfigHistory.configured("clearHistory1", "test"); - result = HistoryCommands.clearHistory(tamayaConfigPlugin, "*"); - assertTrue(result.contains("PID")); - assertTrue(result.contains("*")); - assertTrue(ConfigHistory.getHistory("clearHistory1").size()==0); - assertTrue(ConfigHistory.getHistory("clearHistory2").size()==0); - assertTrue(ConfigHistory.getHistory("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(tamayaConfigPlugin, "getHistory"); - assertNotNull(result); - assertTrue(result.contains("k1")); - assertTrue(result.contains("v1")); - assertTrue(result.contains("test")); - result = HistoryCommands.getHistory(tamayaConfigPlugin, "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(tamayaConfigPlugin); - assertEquals(result, String.valueOf(tamayaConfigPlugin.getMaxHistorySize())); - result = HistoryCommands.setMaxHistorySize(tamayaConfigPlugin, 111); - assertEquals(result, "tamaya-max-getHistory-size=111"); - result = HistoryCommands.getMaxHistorySize(tamayaConfigPlugin); - assertEquals(result, "111"); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/common/src/test/resources/META-INF/javaconfiguration.properties ---------------------------------------------------------------------- diff --git a/osgi/common/src/test/resources/META-INF/javaconfiguration.properties b/osgi/common/src/test/resources/META-INF/javaconfiguration.properties deleted file mode 100644 index d0b0cb8..0000000 --- a/osgi/common/src/test/resources/META-INF/javaconfiguration.properties +++ /dev/null @@ -1,22 +0,0 @@ -# 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. -# -[tamaya]my.testProperty1=success1 -[tamaya]my.testProperty2=success2 -[tamaya]my.testProperty3=success3 -[tamaya]my.testProperty4=success4 -[tamaya]java.version=Java2000 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/common/src/test/resources/org.ops4j.pax.logging.cfg ---------------------------------------------------------------------- diff --git a/osgi/common/src/test/resources/org.ops4j.pax.logging.cfg b/osgi/common/src/test/resources/org.ops4j.pax.logging.cfg deleted file mode 100644 index 6683438..0000000 --- a/osgi/common/src/test/resources/org.ops4j.pax.logging.cfg +++ /dev/null @@ -1,48 +0,0 @@ -# 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. -# -#updated by pax-exam -#Sun Nov 27 20:55:11 CET 2016 -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.sift.appender.append=true -log4j.appender.out.maxFileSize=1MB -log4j.appender.audit.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n -log4j.appender.sift.appender.file=${karaf.data}/log/$\\{bundle.name\\}.log -log4j.appender.sift.appender.layout=org.apache.log4j.PatternLayout -log4j.appender.out.append=true -log4j.appender.sift.appender=org.apache.log4j.FileAppender -log4j.appender.out.layout=org.apache.log4j.PatternLayout -log4j.appender.out=org.apache.log4j.RollingFileAppender -log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n -log4j.throwableRenderer=org.apache.log4j.OsgiThrowableRenderer -log4j.appender.out.file=${karaf.data}/log/karaf.log -log4j.appender.sift=org.apache.log4j.sift.MDCSiftingAppender -log4j.appender.audit.append=true -log4j.appender.audit.maxBackupIndex=10 -log4j.appender.audit.layout=org.apache.log4j.PatternLayout -log4j.appender.sift.key=bundle.name -log4j.appender.audit.maxFileSize=1MB -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.additivity.org.apache.karaf.jaas.modules.audit=false -log4j.logger.org.apache.karaf.jaas.modules.audit=INFO, audit -log4j.appender.audit.file=${karaf.data}/security/audit.log -log4j.appender.sift.default=karaf -log4j.appender.sift.appender.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %m%n -log4j.appender.out.maxBackupIndex=10 -log4j.appender.audit=org.apache.log4j.RollingFileAppender -log4j.rootLogger=WARN, out, stdout, osgi\:* -log4j.appender.out.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/gogo-shell/bnd.bnd ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/bnd.bnd b/osgi/gogo-shell/bnd.bnd deleted file mode 100644 index 67e951a..0000000 --- a/osgi/gogo-shell/bnd.bnd +++ /dev/null @@ -1,34 +0,0 @@ --buildpath: \ - osgi.annotation; version=6.0.0,\ - osgi.core; version=6.0,\ - osgi.cmpn; version=6.0 - --testpath: \ - ${junit} - -javac.source: 1.8 -javac.target: 1.8 - -Bundle-Activator: org.apache.tamaya.gogo.shell.Activator -Bundle-Version: ${version}.${tstamp} -Bundle-Name: Apache Tamaya - Felix Shell Commands -Bundle-SymbolicName: org.apache.tamaya.osgi.gogo.shell -Bundle-Description: Apacha Tamaya Configuration - Gogo Shell Extensions -Bundle-Category: Implementation -Bundle-Copyright: (C) Apache Foundation -Bundle-License: Apache Licence version 2 -Bundle-Vendor: Apache Software Foundation -Bundle-ContactAddress: [email protected] -Bundle-DocURL: http://tamaya.apache.org -Export-Package: \ - org.apache.tamaya.gogo.shell -Import-Package: \ - org.osgi.service.cm,\ - org.osgi.framework,\ - org.apache.tamaya,\ - org.apache.tamaya.spi,\ - org.apache.tamaya.functions,\ - org.apache.tamaya.spisupport,\ - org.apache.tamaya.osgi,\ - org.apache.tamaya.osgi.commands,\ - org.apache.felix.service.command http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/gogo-shell/pom.xml ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/pom.xml b/osgi/gogo-shell/pom.xml deleted file mode 100644 index ba9fa64..0000000 --- a/osgi/gogo-shell/pom.xml +++ /dev/null @@ -1,71 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - - <!-- - - 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. - --> - - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-osgi-all</artifactId> - <version>0.4-incubating-SNAPSHOT</version> - </parent> - - <artifactId>tamaya-osgi-gogo-shell</artifactId> - <packaging>jar</packaging> - <name>Apache Tamaya :: OSGI :: Gogo :: Shell</name> - <description>Tamaya Gogo Shell Commands</description> - - <dependencies> - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-osgi</artifactId> - <version>${project.parent.version}</version> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.gogo.runtime</artifactId> - <version>1.0.8</version> - </dependency> - - <!-- Testing --> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>java-hamcrest</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - </dependency> - </dependencies> - -</project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/Activator.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/Activator.java b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/Activator.java deleted file mode 100644 index f7a2aa9..0000000 --- a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/Activator.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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.gogo.shell; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -import java.util.Dictionary; -import java.util.Hashtable; -import java.util.logging.Logger; - -/** - * Activator that registers the Tamaya commands for the Felix Gogo console used - * in Apache Felix and Equinox. - */ -public class Activator implements BundleActivator { - - private static final Logger LOG = Logger.getLogger(Activator.class.getName()); - - private ServiceRegistration<HistoryCommands> histReg; - private ServiceRegistration<ConfigCommands> configReg; - private ServiceRegistration<BackupCommands> backupReg; - private ServiceRegistration<SettingsCommands> settingsReg; - - @Override - public void start(BundleContext context) throws Exception { - LOG.finest("Registering Tamaya commands..."); - Dictionary<String, Object> props = new Hashtable<>(); - props.put("osgi.command.scope", "tamaya"); - props.put("osgi.command.function", - new String[] {"tm_config", "tm_property", - "tm_propertysource","tm_propertysources"}); - configReg = context.registerService( - ConfigCommands.class, - new ConfigCommands(context), props); - props.put("osgi.command.function", - new String[] {"tm_history","tm_history_delete","tm_history_delete_all", - "tm_history_maxsize", "tm_history_maxsize_set"}); - histReg = context.registerService( - HistoryCommands.class, - new HistoryCommands(context), props); - props.put("osgi.command.function", - new String[] {"tm_backup_create","tm_backup_delete", - "tm_backup","tm_backup_restore"}); - backupReg = context.registerService( - BackupCommands.class, - new BackupCommands(context), props); - props.put("osgi.command.function", - new String[] {"tm_enable","tm_enabled", "tm_policy", - "tm_policy_set","tm_info", "tm_propagate_updates", - "tm_propagate_updates_set"}); - settingsReg = context.registerService( - SettingsCommands.class, - new SettingsCommands(context), props); - LOG.info("Registered Tamaya commands."); - } - - @Override - public void stop(BundleContext context) throws Exception { - LOG.info("Unregistering Tamaya commands."); - if (histReg != null) { - histReg.unregister(); - } - if (configReg != null) { - configReg.unregister(); - } - if (backupReg != null) { - backupReg.unregister(); - } - if (settingsReg != null) { - settingsReg.unregister(); - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java deleted file mode 100644 index 67c7b66..0000000 --- a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.gogo.shell; - -import org.apache.felix.service.command.Descriptor; -import org.apache.felix.service.command.Parameter; -import org.apache.tamaya.osgi.commands.TamayaConfigService; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.cm.ConfigurationAdmin; - -import java.io.IOException; -import java.util.Objects; - -public class BackupCommands { - - private BundleContext context; - - public BackupCommands(BundleContext context){ - this.context = Objects.requireNonNull(context); - } - - private <T> T getService(Class<T> type){ - ServiceReference<T> cmRef = context.getServiceReference(type); - return context.getService(cmRef); - } - - - @Descriptor("Creates an OSGI ConfigAdmin configuration backup for a PID.") - public void tm_backup_create(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--pid"}) - @Descriptor("The PID (requred)") String pid, - @Parameter(absentValue = Parameter.UNSPECIFIED, names={"-f", "--force"}) - @Descriptor("If set any existing backup will be overriden, default is false.") Boolean force) throws IOException { - System.out.println(org.apache.tamaya.osgi.commands.BackupCommands.createBackup( - getService(TamayaConfigService.class), - getService(ConfigurationAdmin.class), pid, force)); - } - - @Descriptor("Deletes an OSGI ConfigAdmin configuration backup for a PID.") - public void tm_backup_delete(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--pid"}) - @Descriptor("The target PID") String pid) throws IOException { - System.out.println(org.apache.tamaya.osgi.commands.BackupCommands.deleteBackup( - getService(TamayaConfigService.class), - pid)); - } - - @Descriptor("Restores an OSGI ConfigAdmin configuration backup for a PID and disabled Tamaya for the given PID.") - public void tm_backup_restore(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--pid"}) - @Descriptor("The target PID") String pid) throws IOException { - System.out.println(org.apache.tamaya.osgi.commands.BackupCommands.restoreBackup( - getService(TamayaConfigService.class), pid)); - } - - @Descriptor("Shows the contents of the OSGI ConfigAdmin configuration backup for a PID.") - public void tm_backup_get(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--pid"}) - @Descriptor("The PID (requred)") String pid) throws IOException { - System.out.println(org.apache.tamaya.osgi.commands.BackupCommands.listBackup( - getService(TamayaConfigService.class), - Objects.requireNonNull(pid))); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java deleted file mode 100644 index 8926ede..0000000 --- a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.gogo.shell; - -import org.apache.felix.service.command.Descriptor; -import org.apache.felix.service.command.Parameter; -import org.apache.tamaya.osgi.Policy; -import org.apache.tamaya.osgi.commands.TamayaConfigService; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; - -import java.io.IOException; -import java.util.Objects; - -public class ConfigCommands { - - private BundleContext context; - - private <T> T getService(Class<T> type){ - ServiceReference<T> cmRef = context.getServiceReference(type); - return context.getService(cmRef); - } - - public ConfigCommands(BundleContext context){ - this.context = Objects.requireNonNull(context); - } - - @Descriptor("Shows the current Tamaya configuration.") - public void tm_config(@Parameter(absentValue = "", names={"-s", "--section"}) - @Descriptor("The section start expression to filter.") String section, - @Parameter(absentValue = "", names={"-p", "--pid"}) - @Descriptor("The pid to filter (required).") String pid) throws IOException { - if(pid.isEmpty()){ - System.out.println(org.apache.tamaya.osgi.commands.ConfigCommands.readTamayaConfig(section, null)); - }else { - System.out.println(org.apache.tamaya.osgi.commands.ConfigCommands.readTamayaConfig4PID(pid, section)); - } - } - - public void tm_apply_config(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--pid"}) - @Descriptor("The target OSGI component PID.") - String pid, - @Parameter(absentValue = "OVERRIDE", names={"-m", "--opmode"}) - @Descriptor("Explicitly set (override) the operation mode to use, one of: EXTEND, OVERRIDE, UPDATE_ONLY") - Policy policy, - @Parameter(absentValue = "false", names={"-d", "--dryrun"}) - @Descriptor("If set to true no OSGI configuration gets changed.") - boolean dryRun){ - System.out.println(org.apache.tamaya.osgi.commands.ConfigCommands.applyTamayaConfiguration( - getService(TamayaConfigService.class), pid, policy.toString(), dryRun)); - } - - @Descriptor("Gets the detailed property values.") - public void tm_property(@Parameter(absentValue = "", names={"-ps", "--propertysource"}) - @Descriptor("The property source name")String propertysource, - @Parameter(absentValue = Parameter.UNSPECIFIED, names={"-k", "--key"}) - @Descriptor("The property key")String key, - @Parameter(absentValue = "false", names={"-e", "--extended"}) - @Descriptor("Show extended info, default=false")Boolean extended) throws IOException { - System.out.println(org.apache.tamaya.osgi.commands.ConfigCommands.getProperty(propertysource, key, extended.booleanValue())); - } - - @Descriptor("Get details of a property source.") - public void tm_propertysource(@Parameter(absentValue = "", names={"-ps", "--propertysource"}) - @Descriptor("The property source name, empty returns a list of possible values")String propertysource) throws IOException { - System.out.println(org.apache.tamaya.osgi.commands.ConfigCommands.getPropertySource(propertysource)); - } - - @Descriptor("Show details of all registered property sources.") - public void tm_propertysources() throws IOException { - System.out.println(org.apache.tamaya.osgi.commands.ConfigCommands.getPropertySourceOverview()); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java deleted file mode 100644 index 906f471..0000000 --- a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.gogo.shell; - -import org.apache.felix.service.command.Descriptor; -import org.apache.felix.service.command.Parameter; -import org.apache.tamaya.osgi.commands.TamayaConfigService; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; - -import java.io.IOException; -import java.util.Objects; - -public class HistoryCommands { - - private BundleContext context; - - private <T> T getService(Class<T> type){ - ServiceReference<T> cmRef = context.getServiceReference(type); - return context.getService(cmRef); - } - - public HistoryCommands(BundleContext context){ - this.context = Objects.requireNonNull(context); - } - - @Descriptor("Deletes the getHistory of configuration changes.") - public void tm_history_delete(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--pid"}) - @Descriptor("The PID.") String pid) throws IOException { - System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.clearHistory( - getService(TamayaConfigService.class), - pid)); - } - - @Descriptor("Deletes the full getHistory of configuration changes.") - public void tm_history_delete_all() throws IOException { - System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.clearHistory( - getService(TamayaConfigService.class), - null)); - } - - @Descriptor("Read the getHistory of configuration changes.") - public void tm_history_get(@Parameter(absentValue = "", names={"-p", "--pid"}) - @Descriptor("The PID.")String pid, - @Parameter(absentValue = "", names={"-t", "--eventtypes"}) - @Descriptor("The comma separated Event types to filter, valid types are " + - "PROPERTY,BEGIN,END")String eventTypes) throws IOException { - if(eventTypes.isEmpty()){ - System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.getHistory( - getService(TamayaConfigService.class), - pid, null)); - }else { - System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.getHistory( - getService(TamayaConfigService.class), - pid, eventTypes.split(","))); - } - } - - @Descriptor("Get the maximum configuration change getHistory size.") - public void tm_history_maxsize() throws IOException { - System.out.println(String.valueOf(org.apache.tamaya.osgi.commands.HistoryCommands.getMaxHistorySize( - getService(TamayaConfigService.class)))); - } - - @Descriptor("Sets the maximum configuration change getHistory size.") - public void tm_history_maxsize_set(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-s", "--size"}) - @Descriptor("The maximum size of getHistory entries stored.")int maxSize) throws IOException { - System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.setMaxHistorySize( - getService(TamayaConfigService.class), - maxSize)); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java deleted file mode 100644 index cf79f0a..0000000 --- a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.gogo.shell; - -import org.apache.felix.service.command.Descriptor; -import org.apache.felix.service.command.Parameter; -import org.apache.tamaya.osgi.Policy; -import org.apache.tamaya.osgi.commands.ConfigCommands; -import org.apache.tamaya.osgi.commands.TamayaConfigService; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; - -import java.io.IOException; -import java.util.Objects; - -public class SettingsCommands { - - private BundleContext context; - - public SettingsCommands(BundleContext context){ - this.context = Objects.requireNonNull(context); - } - - private <T> T getService(Class<T> type){ - ServiceReference<T> cmRef = context.getServiceReference(type); - return context.getService(cmRef); - } - - @Descriptor("Allows to disable/enable Tamaya configuration by default.") - public void tm_enable(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-e", "--enable"}) - @Descriptor("if true Tamaya is enabled by default (default=false)") boolean enabled) throws IOException { - System.out.println(ConfigCommands.setDefaultEnabled(getService(TamayaConfigService.class), enabled)); - } - - @Descriptor("Access if Tamaya is currently enabled by default to change OSGI configuration.") - public void tm_enabled(){ - System.out.println(ConfigCommands.getDefaultEnabled(getService(TamayaConfigService.class))); - } - - @Descriptor("Get the default Tamaya configuration policy.") - public void tm_policy() throws IOException { - System.out.println(ConfigCommands.getDefaultOpPolicy(getService(TamayaConfigService.class))); - } - - @Descriptor("Set the default Tamaya configuration policy.") - public void tm_policy_set(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--policy"}) - @Descriptor("The policy to apply (required), one of: EXTEND, OVERRIDE, UPDATE_ONLY") Policy policy) throws IOException { - System.out.println(ConfigCommands.setDefaultOpPolicy(getService(TamayaConfigService.class), policy.toString())); - } - - @Descriptor("Get info about the current Tamaya configuration settings.") - public void tm_info() throws IOException { - System.out.println(ConfigCommands.getInfo(getService(TamayaConfigService.class))); - } - - @Descriptor("Flag if Tamaya is automatically triggering OSGI config updates, when according " + - "Tamaya configuration changes.") - public void tm_propagate_updates() throws IOException { - System.out.println(getService(TamayaConfigService.class).isAutoUpdateEnabled()); - } - - @Descriptor("Configure if Tamaya is automatically triggering OSGI config updates, when according " + - "Tamaya configuration changes.") - public void tm_propagate_updates_set(boolean enabled) throws IOException { - System.out.println(ConfigCommands.setAutoUpdateEnabled(getService(TamayaConfigService.class), enabled)); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/AbstractOSGITest.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/AbstractOSGITest.java b/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/AbstractOSGITest.java deleted file mode 100644 index 918ff97..0000000 --- a/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/AbstractOSGITest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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.gogo.shell; - -import org.apache.tamaya.osgi.TamayaConfigPlugin; -import org.apache.tamaya.osgi.commands.TamayaConfigService; -import org.junit.Before; -import org.mockito.Mock; -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 java.util.Dictionary; -import java.util.Hashtable; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.*; - -/** - * Created by atsticks on 27.09.17. - */ -public abstract class AbstractOSGITest { - - private Map<String,Hashtable<String, Object>> properties = new ConcurrentHashMap<>(); - - @Mock - protected BundleContext bundleContext; - - @Mock - protected ConfigurationAdmin cm; - - @Mock - private ServiceReference<ConfigurationAdmin> cmRef; - @Mock - private ServiceReference<TamayaConfigService> tamayaRef; - - protected TamayaConfigService tamayaConfigPlugin; - - protected Dictionary<String,Object> getProperties(String pid){ - return this.properties.get(pid); - } - - @Before - public void setup()throws Exception{ - 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); - doReturn(tamayaRef).when(bundleContext).getServiceReference(TamayaConfigService.class); - tamayaConfigPlugin = new TamayaConfigPlugin(bundleContext); - doReturn(tamayaConfigPlugin).when(bundleContext).getService(tamayaRef); - } - - protected Configuration initConfigurationMock(final String pid)throws Exception{ - Configuration config = mock(Configuration.class); - doAnswer(invocation -> { - Hashtable<String,Object> props = properties.get(pid); - props.clear(); - props.putAll((Map<? extends String, ?>) invocation.getArguments()[0]); - return null; - }).when(config).update(any(Dictionary.class)); - doAnswer(invocation -> { - Hashtable<String,Object> props = properties.get(pid); - 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(); - return config; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/ActivatorTest.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/ActivatorTest.java b/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/ActivatorTest.java deleted file mode 100644 index 03608c3..0000000 --- a/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/ActivatorTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.gogo.shell; - -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 30.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(BackupCommands.class), anyObject(), anyObject()); - verify(bundleContext).registerService(eq(ConfigCommands.class), anyObject(), anyObject()); - verify(bundleContext).registerService(eq(HistoryCommands.class), anyObject(), anyObject()); - verify(bundleContext).registerService(eq(SettingsCommands.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/eeab5ce0/osgi/injection/bnd.bnd ---------------------------------------------------------------------- diff --git a/osgi/injection/bnd.bnd b/osgi/injection/bnd.bnd deleted file mode 100644 index 69e9637..0000000 --- a/osgi/injection/bnd.bnd +++ /dev/null @@ -1,34 +0,0 @@ --buildpath: \ - osgi.annotation; version=6.0.0,\ - osgi.core; version=6.0,\ - osgi.cmpn; version=6.0 - --testpath: \ - ${junit} - -javac.source: 1.8 -javac.target: 1.8 - -Bundle-Activator: org.apache.tamaya.osgi.injection.Activator -Bundle-Version: ${version}.${tstamp} -Bundle-Name: Apache Tamaya - OSGI Configuration Injection -Bundle-SymbolicName: org.apache.tamaya.osgi.injection -Bundle-Description: Apacha Tamaya Configuration - OSGI Service Configuration Injection -Bundle-Category: Implementation -Bundle-Copyright: (C) Apache Foundation -Bundle-License: Apache Licence version 2 -Bundle-Vendor: Apache Software Foundation -Bundle-ContactAddress: [email protected] -Bundle-DocURL: http://tamaya.apache.org -Import-Package: \ - org.osgi.service.cm,\ - org.osgi.framework,\ - org.osgi.util.tracker,\ - org.apache.tamaya,\ - org.apache.tamaya.spi,\ - org.apache.tamaya.functions,\ - org.apache.tamaya.spisupport,\ - org.apache.tamaya.osgi,\ - org.apache.tamaya.inject.api,\ - org.apache.tamaya.inject.spi,\ - org.apache.tamaya.inject http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/injection/pom.xml ---------------------------------------------------------------------- diff --git a/osgi/injection/pom.xml b/osgi/injection/pom.xml deleted file mode 100644 index 692e98f..0000000 --- a/osgi/injection/pom.xml +++ /dev/null @@ -1,72 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - - <!-- - - 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. - --> - - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-osgi-all</artifactId> - <version>0.4-incubating-SNAPSHOT</version> - </parent> - - <artifactId>tamaya-osgi-injection</artifactId> - <packaging>jar</packaging> - <name>Apache Tamaya :: OSGI :: Config Injection</name> - <description>Tamaya OSGI Configuration Injector</description> - - <dependencies> - - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-injection</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-osgi</artifactId> - <version>${project.parent.version}</version> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> - </dependency> - - <!-- Testing --> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>java-hamcrest</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - </dependency> - </dependencies> - -</project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/Activator.java ---------------------------------------------------------------------- diff --git a/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/Activator.java b/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/Activator.java deleted file mode 100644 index d11d223..0000000 --- a/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/Activator.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.injection; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -import java.util.Dictionary; -import java.util.Hashtable; -import java.util.logging.Logger; - -/** - * Activator that registers the Tamaya commands for the Felix Gogo console used - * in Apache Felix and Equinox. - */ -public class Activator implements BundleActivator { - - private static final Logger LOG = Logger.getLogger(Activator.class.getName()); - - private TamayaOSGIInjector injector; - private ServiceRegistration<TamayaOSGIInjector> injectorReg; - - @Override - public void start(BundleContext context) throws Exception { - LOG.finest("Registering Tamaya OSGI Config injector..."); - injector = new TamayaOSGIInjector(context); - Dictionary<String, Object> props = new Hashtable<>(); - injectorReg = context.registerService( - TamayaOSGIInjector.class, - injector, props); - injector.start(); - LOG.finest("Registered Tamaya OSGI Config injector."); - } - - @Override - public void stop(BundleContext context) throws Exception { - LOG.finest("Unregistering Tamaya Config injector..."); - if (injectorReg != null) { - injector.stop(); - injectorReg.unregister(); - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java ---------------------------------------------------------------------- diff --git a/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java b/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java deleted file mode 100644 index 529468e..0000000 --- a/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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.injection; - -import org.apache.tamaya.spi.PropertyValue; -import org.apache.tamaya.spisupport.BasePropertySource; -import org.osgi.service.cm.Configuration; -import org.osgi.service.cm.ConfigurationAdmin; - -import java.io.IOException; -import java.util.*; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * This is a Tamaya PropertySource, which internally wraps the OSGI ConfigAdmin service, preconfigured - * for a PID and (optionally) location. - */ -public class OSGIConfigAdminPropertySource extends BasePropertySource{ - - private static final Logger LOG = Logger.getLogger(OSGIConfigAdminPropertySource.class.getName()); - private ConfigurationAdmin configurationAdmin; - private String pid; - private String location; - - public OSGIConfigAdminPropertySource(ConfigurationAdmin configurationAdmin, String pid){ - this.configurationAdmin = Objects.requireNonNull(configurationAdmin); - this.pid = Objects.requireNonNull(pid); - } - - public OSGIConfigAdminPropertySource(ConfigurationAdmin configurationAdmin, String pid, String location){ - this.configurationAdmin = Objects.requireNonNull(configurationAdmin); - this.pid = Objects.requireNonNull(pid); - this.location = location; - } - - /** - * Get the configured OSGI service PID. - * @return the pid, nnever null. - */ - public String getPid() { - return pid; - } - - /** - * Get the configured OSGI config location, may be null. - * @return the location, or null. - */ - public String getLocation() { - return location; - } - - @Override - public PropertyValue get(String key) { - try { - Configuration osgiConfig = configurationAdmin.getConfiguration(pid, location); - Dictionary<String,Object> props = osgiConfig.getProperties(); - if(props!=null){ - Object value = props.get(key); - if(value!=null) { - return PropertyValue.of(key, String.valueOf(value), "OSGI ConfigAdmin: " + pid); - } - } - } catch (IOException e) { - LOG.log(Level.FINEST, e, () -> "No config for PID: " + pid); - } - return null; - } - - @Override - public Map<String, PropertyValue> getProperties() { - try { - Configuration osgiConfig = configurationAdmin.getConfiguration(pid); - Dictionary<String,Object> props = osgiConfig.getProperties(); - if(props!=null){ - Map<String, PropertyValue> result = new HashMap<>(); - Enumeration<String> keys = props.keys(); - while(keys.hasMoreElements()){ - String key = keys.nextElement(); - Object value = props.get(key); - result.put(key, PropertyValue.of(key, String.valueOf(value), "OSGI ConfigAdmin: " + pid)); - } - return result; - } - } catch (IOException e) { - LOG.log(Level.FINEST, e, () -> "No config for PID: " + pid); - } - return Collections.emptyMap(); - } -} - - http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjector.java ---------------------------------------------------------------------- diff --git a/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjector.java b/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjector.java deleted file mode 100644 index 887939b..0000000 --- a/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjector.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.injection; - -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.inject.ConfigurationInjection; -import org.osgi.service.cm.ConfigurationAdmin; - -import java.util.Objects; -import java.util.function.Supplier; - -/** - * Created by atsti on 03.10.2017. - */ -final class OSGIConfigurationInjector{ - - private ConfigurationAdmin cm; - private Configuration tamayaOSGIConfiguration; - private String pid; - private String location; - - - public OSGIConfigurationInjector(ConfigurationAdmin cm, String pid){ - this(cm, pid, null); - } - - public OSGIConfigurationInjector(ConfigurationAdmin cm, String pid, String location){ - this.cm = Objects.requireNonNull(cm); - tamayaOSGIConfiguration = ConfigurationProvider.createConfiguration( - ConfigurationProvider.getConfigurationContextBuilder() - .addDefaultPropertyConverters() - .addDefaultPropertyFilters() - .addPropertySources(new OSGIConfigAdminPropertySource(cm, pid, location)) - .build()); - } - - public <T> T configure(T instance){ - return ConfigurationInjection.getConfigurationInjector() - .configure(instance, tamayaOSGIConfiguration); - } - - public <T> Supplier<T> getConfiguredSupplier(java.util.function.Supplier<T> supplier){ - return ConfigurationInjection.getConfigurationInjector() - .getConfiguredSupplier(supplier, tamayaOSGIConfiguration); - } - - /** - * Creates a template implementing the annotated methods based on current configuration data. - * - * @param <T> the type of the template. - * @param templateType the type of the template to be created. - * @return the configured template. - */ - public <T> T createTemplate(Class<T> templateType){ - return ConfigurationInjection.getConfigurationInjector() - .createTemplate(templateType, tamayaOSGIConfiguration); - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/TamayaOSGIInjector.java ---------------------------------------------------------------------- diff --git a/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/TamayaOSGIInjector.java b/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/TamayaOSGIInjector.java deleted file mode 100644 index 19fd795..0000000 --- a/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/TamayaOSGIInjector.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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.injection; - -import org.apache.tamaya.osgi.TamayaConfigPlugin; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Constants; -import org.osgi.framework.ServiceReference; -import org.osgi.service.cm.ConfigurationAdmin; -import org.osgi.util.tracker.ServiceTracker; - -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Logger; - -/** - * Class that monitors services and configures them if they have {@code Tamaya-Config = true} in the - * service settings. - */ -public class TamayaOSGIInjector { - - public static final String TAMAYA_INJECTION_ENABLED_MANIFEST = "Tamaya-Config-Inject"; - public static final String TAMAYA_INJECTION_ENABLED_PROP = "tamaya-config-inject"; - private static final Logger log = Logger.getLogger(TamayaConfigPlugin.class.getName()); - private BundleContext context; - private ConfigurationAdmin cm; - private ServiceTracker<Object, Object> tracker; - private static final Map<String, OSGIConfigurationInjector> INJECTORS = new ConcurrentHashMap<>(); - - public TamayaOSGIInjector(BundleContext context) { - this.context = Objects.requireNonNull(context); - } - - public void start(){ - tracker = new ServiceTracker<Object, Object>(context, Object.class.getName(), null) { - @Override - public Object addingService(ServiceReference reference) { - log.info("Checking service for configuration: " + reference); - Object service = super.addingService(reference); - if(isInjectionEnabled(reference)) { - String pid = (String)reference.getProperty(Constants.SERVICE_PID); - if(pid==null){ - pid = reference.getBundle().getSymbolicName(); - } - OSGIConfigurationInjector injector = getInjector(pid, reference.getBundle().getLocation()); - injector.configure(service); - } - return service; - } - - @Override - public void modifiedService(ServiceReference<Object> reference, Object service) { - super.modifiedService(reference, service); - if(isInjectionEnabled(reference)) { - String pid = (String)reference.getProperty(Constants.SERVICE_PID); - if(pid==null){ - pid = reference.getBundle().getSymbolicName(); - } - OSGIConfigurationInjector injector = getInjector(pid, reference.getBundle().getLocation()); - injector.configure(service); - } - } - }; - tracker.open(true); - } - - public void stop(){ - if(tracker!=null){ - tracker.close(); - tracker = null; - } - } - - private OSGIConfigurationInjector getInjector(String pid, String location){ - String key = location==null?pid.trim():pid.trim()+"::"+location.trim(); - OSGIConfigurationInjector injector = INJECTORS.get(key); - if(injector==null){ - injector = new OSGIConfigurationInjector(cm, pid, location); - INJECTORS.put(key, injector); - } - return injector; - } - - public static boolean isInjectionEnabled(ServiceReference reference){ - String enabledVal = (String)reference.getProperty(TAMAYA_INJECTION_ENABLED_PROP); - if(enabledVal!=null){ - return Boolean.parseBoolean(enabledVal); - } - enabledVal = reference.getBundle().getHeaders().get(TAMAYA_INJECTION_ENABLED_MANIFEST); - if(enabledVal!=null){ - return Boolean.parseBoolean(enabledVal); - } - return false; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/AbstractOSGITest.java ---------------------------------------------------------------------- diff --git a/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/AbstractOSGITest.java b/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/AbstractOSGITest.java deleted file mode 100644 index e3f73c3..0000000 --- a/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/AbstractOSGITest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.injection; - -import org.apache.tamaya.osgi.TamayaConfigPlugin; -import org.junit.Before; -import org.mockito.Mock; -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 java.util.Dictionary; -import java.util.Hashtable; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.*; - -/** - * Created by atsticks on 27.09.17. - */ -public abstract class AbstractOSGITest { - - private Map<String,Hashtable<String, Object>> properties = new ConcurrentHashMap<>(); - - @Mock - protected BundleContext bundleContext; - - @Mock - protected ConfigurationAdmin cm; - - @Mock - private ServiceReference<ConfigurationAdmin> cmRef; - @Mock - private ServiceReference<TamayaConfigPlugin> tamayaRef; - - protected TamayaConfigPlugin tamayaConfigPlugin; - - protected Dictionary<String,Object> getProperties(String pid){ - return this.properties.get(pid); - } - - @Before - public void setup()throws Exception{ - 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); - doReturn(tamayaRef).when(bundleContext).getServiceReference(TamayaConfigPlugin.class); - tamayaConfigPlugin = new TamayaConfigPlugin(bundleContext); - doReturn(tamayaConfigPlugin).when(bundleContext).getService(tamayaRef); - } - - protected Configuration initConfigurationMock(final String pid)throws Exception{ - Configuration config = mock(Configuration.class); - doAnswer(invocation -> { - Hashtable<String,Object> props = properties.get(pid); - props.clear(); - props.putAll((Map<? extends String, ?>) invocation.getArguments()[0]); - return null; - }).when(config).update(any(Dictionary.class)); - doAnswer(invocation -> { - Hashtable<String,Object> props = properties.get(pid); - 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(); - return config; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/ActivatorTest.java ---------------------------------------------------------------------- diff --git a/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/ActivatorTest.java b/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/ActivatorTest.java deleted file mode 100644 index 9cd587f..0000000 --- a/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/ActivatorTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.injection; - -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 03.10.2017. - */ -@RunWith(MockitoJUnitRunner.class) -public class ActivatorTest extends AbstractOSGITest{ - - @Test - public void startStop() throws Exception { - Activator activator = new Activator(); - activator.start(this.bundleContext); - verify(bundleContext).registerService(eq(TamayaOSGIInjector.class), anyObject(), anyObject()); - activator.stop(this.bundleContext); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySourceTest.java b/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySourceTest.java deleted file mode 100644 index f83ac56..0000000 --- a/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySourceTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.injection; - -import org.apache.tamaya.spi.PropertyValue; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; - -import java.util.Map; - -import static org.junit.Assert.*; - -/** - * Created by atsti on 03.10.2017. - */ -@RunWith(MockitoJUnitRunner.class) -public class OSGIConfigAdminPropertySourceTest extends AbstractOSGITest{ - - OSGIConfigAdminPropertySource propertySource; - - @Before - public void init(){ - propertySource = new OSGIConfigAdminPropertySource(cm, "tamaya"); - } - - @Test - public void get() throws Exception { - PropertyValue val = propertySource.get("java.home"); - assertNotNull(val); - assertEquals(val.getKey(), "java.home"); - assertEquals(val.getValue(), System.getProperty("java.home")); - val = propertySource.get("foo.bar"); - assertNull(val); - } - - @Test - public void getProperties() throws Exception { - Map<String,PropertyValue> props = propertySource.getProperties(); - assertNotNull(props); - PropertyValue val = props.get("java.home"); - assertEquals(val.getKey(), "java.home"); - assertEquals(val.getValue(), System.getProperty("java.home")); - val = props.get("foo.bar"); - assertNull(val); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjectorTest.java ---------------------------------------------------------------------- diff --git a/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjectorTest.java b/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjectorTest.java deleted file mode 100644 index 6735e7a..0000000 --- a/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjectorTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.injection; - -import org.apache.tamaya.inject.api.Config; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; - -import java.util.function.Supplier; - -import static org.junit.Assert.*; - -/** - * Created by atsti on 03.10.2017. - */ -@RunWith(MockitoJUnitRunner.class) -public class OSGIConfigurationInjectorTest extends AbstractOSGITest{ - - - @Test - public void configure() throws Exception { - OSGIConfigurationInjector injector = new OSGIConfigurationInjector(cm, "OSGIConfigurationInjectorTest"); - Example example = new Example(); - Example result = injector.configure(example); - assertNotNull(result); - assertTrue(result==example); - checkExampleConfig(example); - } - - @Test - public void getConfiguredSupplier() throws Exception { - OSGIConfigurationInjector injector = new OSGIConfigurationInjector(cm, "OSGIConfigurationInjectorTest"); - Supplier<Example> supplier = injector.getConfiguredSupplier(Example::new); - assertNotNull(supplier); - Example example = supplier.get(); - checkExampleConfig(example); - } - - @Test - public void createTemplate() throws Exception { - OSGIConfigurationInjector injector = new OSGIConfigurationInjector(cm, "OSGIConfigurationInjectorTest"); - TemplateExample template = injector.createTemplate(TemplateExample.class); - checkExampleConfig(template); - } - - private void checkExampleConfig(Example example) { - assertNotNull(example); - assertEquals(example.javaHome, System.getProperty("java.home")); - assertEquals(example.javaVersion, System.getProperty("java.version")); - assertEquals(example.javaUsed, true); - } - - private void checkExampleConfig(TemplateExample template) { - assertNotNull(template); - assertEquals(template.getJavaHome(), System.getProperty("java.home")); - assertEquals(template.javaVersion(), System.getProperty("java.version")); - assertEquals(template.isJavaUsed(), true); - } - - private static final class Example { - @Config("java.home") - String javaHome; - @Config("java.version") - String javaVersion; - @Config(value = "java.used", defaultValue = "true") - boolean javaUsed; - } - - private interface TemplateExample { - - @Config("java.home") - String getJavaHome(); - - @Config("java.version") - String javaVersion(); - - @Config(value = "java.used", defaultValue = "true") - boolean isJavaUsed(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/eeab5ce0/osgi/karaf-features/pom.xml ---------------------------------------------------------------------- diff --git a/osgi/karaf-features/pom.xml b/osgi/karaf-features/pom.xml deleted file mode 100644 index 8d8c2d4..0000000 --- a/osgi/karaf-features/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - -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. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-osgi-all</artifactId> - <version>0.4-incubating-SNAPSHOT</version> - </parent> - - <artifactId>tamaya-karaf-features</artifactId> - <packaging>feature</packaging> - <name>Apache Tamaya :: OSGI :: Karaf :: Features</name> - <description>Tamaya Karaf Feature Descriptor.</description> - - <build> - <plugins> - <plugin> - <groupId>org.apache.karaf.tooling</groupId> - <artifactId>karaf-maven-plugin</artifactId> - <configuration> - <startLevel>80</startLevel> - <aggregateFeatures>true</aggregateFeatures> - </configuration> - </plugin> - </plugins> - </build> - -</project>
