tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [1/3] incubator-tamaya-sandbox git commit: TAMAYA-300 Added tests.
Date Sun, 01 Oct 2017 12:24:51 GMT
Repository: incubator-tamaya-sandbox
Updated Branches:
  refs/heads/master e60d9ddb9 -> b11f31742


TAMAYA-300 Added tests.


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/9d8fe86d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/9d8fe86d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/9d8fe86d

Branch: refs/heads/master
Commit: 9d8fe86d5bafc608d5a153876aaf632af7510c00
Parents: e60d9dd
Author: Anatole Tresch <anatole@apache.org>
Authored: Sun Oct 1 10:19:55 2017 +0200
Committer: Anatole Tresch <anatole@apache.org>
Committed: Sun Oct 1 10:19:55 2017 +0200

----------------------------------------------------------------------
 osgi/updater/pom.xml                            | 46 +--------
 .../tamaya/osgi/updater/AbstractOSGITest.java   | 99 ++++++++++++++++++++
 .../tamaya/osgi/updater/ActivatorTest.java      | 44 +++++++++
 3 files changed, 145 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/9d8fe86d/osgi/updater/pom.xml
----------------------------------------------------------------------
diff --git a/osgi/updater/pom.xml b/osgi/updater/pom.xml
index a1df83b..fed3f46 100644
--- a/osgi/updater/pom.xml
+++ b/osgi/updater/pom.xml
@@ -93,51 +93,9 @@
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         </dependency>
-
-        <!-- OSGI Testbed -->
-        <dependency>
-            <groupId>org.ops4j.pax.exam</groupId>
-            <artifactId>pax-exam-container-forked</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.ops4j.pax.exam</groupId>
-            <artifactId>pax-exam-junit4</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.ops4j.pax.exam</groupId>
-            <artifactId>pax-exam-link-mvn</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.ops4j.pax.url</groupId>
-            <artifactId>pax-url-aether</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.framework</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>ch.qos.logback</groupId>
-            <artifactId>logback-core</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>ch.qos.logback</groupId>
-            <artifactId>logback-classic</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.ops4j.pax.exam</groupId>
-            <artifactId>pax-exam</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.ops4j.pax.exam</groupId>
-            <artifactId>pax-exam-junit4</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.ops4j.pax.url</groupId>
-            <artifactId>pax-url-wrap</artifactId>
-        </dependency>
         <dependency>
-            <groupId>org.ops4j.pax.url</groupId>
-            <artifactId>pax-url-reference</artifactId>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
         </dependency>
 
     </dependencies>

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/9d8fe86d/osgi/updater/src/test/java/org/apache/tamaya/osgi/updater/AbstractOSGITest.java
----------------------------------------------------------------------
diff --git a/osgi/updater/src/test/java/org/apache/tamaya/osgi/updater/AbstractOSGITest.java
b/osgi/updater/src/test/java/org/apache/tamaya/osgi/updater/AbstractOSGITest.java
new file mode 100644
index 0000000..adca9f3
--- /dev/null
+++ b/osgi/updater/src/test/java/org/apache/tamaya/osgi/updater/AbstractOSGITest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.updater;
+
+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/9d8fe86d/osgi/updater/src/test/java/org/apache/tamaya/osgi/updater/ActivatorTest.java
----------------------------------------------------------------------
diff --git a/osgi/updater/src/test/java/org/apache/tamaya/osgi/updater/ActivatorTest.java
b/osgi/updater/src/test/java/org/apache/tamaya/osgi/updater/ActivatorTest.java
new file mode 100644
index 0000000..5e1f614
--- /dev/null
+++ b/osgi/updater/src/test/java/org/apache/tamaya/osgi/updater/ActivatorTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.updater;
+
+import org.apache.tamaya.events.ConfigEventManager;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import static junit.framework.TestCase.assertEquals;
+
+/**
+ * Created by atsti on 30.09.2017.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class ActivatorTest extends AbstractOSGITest{
+
+    @Test
+    public void startStop() throws Exception {
+        int size = ConfigEventManager.getListeners().size();
+        Activator activator = new Activator();
+        activator.start(super.bundleContext);
+        assertEquals(ConfigEventManager.getListeners().size(), size+1);
+        activator.stop(super.bundleContext);
+        assertEquals(ConfigEventManager.getListeners().size(), size);
+    }
+
+}
\ No newline at end of file


Mime
View raw message