You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:19:55 UTC

[sling-org-apache-sling-testing-osgi-mock] annotated tag org.apache.sling.testing.osgi-mock-1.7.0 created (now ed06a9e)

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a change to annotated tag org.apache.sling.testing.osgi-mock-1.7.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git.


      at ed06a9e  (tag)
 tagging 5b4b909ad0afc1b1027f0b5e3f0fadf934c7269b (commit)
      by Stefan Seifert
      on Wed Nov 4 21:34:40 2015 +0000

- Log -----------------------------------------------------------------
org.apache.sling.testing.osgi-mock-1.7.0
-----------------------------------------------------------------------

This annotated tag includes the following new commits:

     new e5ba840  SLING-4042 Donate sling-mock, jcr-mock, osgi-mock implementation
     new e1ee5ad  svn:ignore
     new 8d20817  SLING-4042 move all mock projects to mocks/ subdirectory
     new ad838b2  SLING-4042 add missing package-info files
     new 740687d  SLING-4042 make sure dependency injection is continued even if not all injections succeeded, and report root cause of invocation target exceptions
     new 7e5bc2d  SLING-4042 add README files
     new 21a5152  add/update SCM urls
     new 74be83a  [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-1.0.0
     new d794a37  [maven-release-plugin] prepare for next development iteration
     new 0a80e0c  SLING-4090 Define package versions for Sling Mock, JCR Mock, OSGi Mock
     new 59f74f6  SLING-4142 MockOsgi: Activate/Deactivate method does not support different signatures
     new a822c76  SLING-4162 Introduce "OsgiContext" junit rule for OSGi and OsgiContextImpl
     new b30dd56  SLING-4162 fix javadoc
     new c40b2dd  SLING-4163 OSGi Mock: Reference bind/unbind method picking order
     new abe8b21  fix some javadoc copy&paste errors and formatting
     new 7c2b519  SLING-4166 OSGi Mock: Support for "modified" SCR lifecycle method
     new 4d131cd  SLING-4166 update package version
     new 907c7df  SLING-4165 OSGi Mock: Fail-fast when calling methods requiring SCR metadata and this is not present
     new 5538cda  SLING-4201 MockOsgi.activate()/deactivate()/modified() should fail fast if method is declared but can't be found
     new 50112aa  SLING-4202 OSGi Mock: Fail-fast when mandatory references cannot be injected
     new 70f5447  fix some javadoc errors/warnings
     new d7f336c  [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-1.1.0
     new 5022c27  [maven-release-plugin] prepare for next development iteration
     new b910746  rename package-private class ReflectinServiceUtil to OsgiServiceUtil because it does not any longer use reflection to do it's job (no functional change)
     new 68de5d4  SLING-4435 OSGi Mock: Cache reading of OSGi SCR Metadata files
     new dc9866e  SLING-4439 add support for unregistering services and prepare dynamic service reference handling
     new e3e8bb1  SLING-4439 implement dynamic service registration
     new e6baa2c  SLING-4439 implement dynamic service registration
     new a980473  SLING-4439 implement dynamic service registration
     new e828e3d  SLING-4439 implement dynamic service registration - support string array properties in osgi metadata as well - merge properties from osgi metadata with those specified on activation/registration call - support "old-style" scr component metadata file as well (and test this case)
     new 5afcfc6  [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-1.2.0
     new cea3da7  [maven-release-plugin] prepare for next development iteration
     new c389c24  SLING-4472 MockBundleContent.getProperty should return null
     new 4900b9b  Add missing licence headers and ignores for rat
     new 174e654  SLING-4670 : SCR metadata can't be read if components element is missing
     new c1ab86f  SLING-4698 - Set parent.relativePath to empty for all modules
     new ad91a5b  SLING-4718 Support OSGi component name different from implementation class
     new dd63020  SLING-4719 osgi-mock: Add Mock EventAdmin implementation
     new aede0b4  SLING-4720 Add support for "Long" and "Boolean" property types in SCR metadata
     new bd78f8a  SLING-4725 osgi-mock: Make compatible to OSGi 5/6
     new 9a4208d  SLING-4470 introduce separate "logging-mock" project for default log configuration in mock tests, remove compile-dependency on slf4j-simple
     new 61fec88  update dependencies for release
     new 20100ff  [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-1.3.0
     new 1e80946  [maven-release-plugin] prepare for next development iteration
     new 62541d8  update to next development snapshot unit released artifacts are in maven central
     new c5653dd  SLING-4756 - ServiceListener notifications are not filtered
     new cd84d7c  SLING-4756 - ServiceListener notifications are not filtered
     new 88790a8  SLING-4756 - ServiceListener notifications are not filtered
     new 3704cb2  update to released mock versions
     new 0f222f7  SLING-4769 Osgi Mock: Add support for bundle headers
     new 5644c49  SLING-4756 add support for filtering via felix.framework FilterImpl implementation
     new f4513f8  SLING-4771 Osgi Mock: Allow to set mock bundle symbolic name
     new 9b26d4c  OsgiServiceUtil: clarify exception message when no matching references were found
     new 7da1c22  MockBundleTest - cast once in the @BeforeMethod instead of every test
     new 4d21da0  SLING-4780 - Implement MockBundle.getLastModified
     new 9248ced  SLING-4781 - Implement MockBundle.getEntryPaths
     new ed82c56  SLING-4781 - Implement MockBundle.getEntryPaths
     new 456e603  SLING-4813 - Support CGLIB enhanced classes for Mockito based service mocks
     new 8d9a404  [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-1.4.0
     new 1e43ffc  [maven-release-plugin] prepare for next development iteration
     new 2cd752f  Update to Sling Parent 23
     new 5e5797b  Testing: remove superflous sling.java.version=6 as it's the default now
     new 384b81a  Update rat exclude rules
     new a69eb1b  @no-jira : test failed with a timeout on jenkins - tring with 2sec timeout
     new 64dc2d0  SLING-4845 - MockBundleContext is not thread-safe
     new 9260a58  SLING-4845 - MockBundleContext is not thread-safe
     new e283546  set parent version to 24 and add empty relativePath where missing
     new e996493  remove unused LOG variable
     new 45d1dbc  SLING-4901 osgi-mock: Add support for ComponentContext.getUsingBundle()
     new ec78cea  [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-1.5.0
     new b693d17  [maven-release-plugin] prepare for next development iteration
     new 1e64d07  cosmetic: beautify error messages when setup/teardown fails
     new 2b257a4  SLING-5083 osgi-mock: Eliminate compile dependency to org.apache.felix.scr.annotations
     new ee4eeb2  SLING-5089 mock-osgi: Deactivate all services on shutdown
     new 3747fc7  SLING-5089 deactivate services in reverse order
     new 571dcdb  SLING-5090 osgi-mock: Support ServiceFactory
     new 29e4a32  SLING-5088 properly shutdown executor service in MockEventAdmin
     new a80c2f8  SLING-5088 deprecate activate/deactivate methods without bundleContext parameter because there is a small risk for memory leaks
     new 3e81888  cosmetic: fix javadoc errors
     new 07870d2  Update the main reactor to parent 25
     new 5f24bfb  [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-1.6.0
     new b52bba4  [maven-release-plugin] prepare for next development iteration
     new 5bdecdf  SLING-5143 osgi-mock: MockBundleContext is not thread-safe when using iterators
     new 3c17662  SLING-5198 osgi-mock: Add basic ConfigurationAdmin support
     new 4aa8c55  [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-1.7.0
     new 5b4b909  [maven-release-plugin] copy for tag org.apache.sling.testing.osgi-mock-1.7.0

The 86 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


-- 
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].

[sling-org-apache-sling-testing-osgi-mock] 01/05: [maven-release-plugin] prepare for next development iteration

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.testing.osgi-mock-1.7.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit b52bba4fc0503baa4ba66ff0e0fe508736ae7c83
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Oct 5 17:25:09 2015 +0000

    [maven-release-plugin] prepare for next development iteration
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1706878 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 29c793c..853ccbb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,16 +28,16 @@
     </parent>
 
     <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
-    <version>1.6.0</version>
+    <version>1.6.1-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
     <name>Apache Sling Testing OSGi Mock</name>
     <description>Mock implementation of selected OSGi APIs.</description>
 
     <scm>
-        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.osgi-mock-1.6.0</connection>
-        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.osgi-mock-1.6.0</developerConnection>
-        <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.testing.osgi-mock-1.6.0</url>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/testing/mocks/osgi-mock</url>
     </scm>
 
     <dependencies>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-testing-osgi-mock] 04/05: [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-1.7.0

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.testing.osgi-mock-1.7.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit 4aa8c55845885351549c125a8256e5ce702e8eff
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Wed Nov 4 21:34:27 2015 +0000

    [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-1.7.0
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1712659 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 853ccbb..62322d7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,16 +28,16 @@
     </parent>
 
     <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
-    <version>1.6.1-SNAPSHOT</version>
+    <version>1.7.0</version>
     <packaging>bundle</packaging>
 
     <name>Apache Sling Testing OSGi Mock</name>
     <description>Mock implementation of selected OSGi APIs.</description>
 
     <scm>
-        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock</connection>
-        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock</developerConnection>
-        <url>http://svn.apache.org/viewvc/sling/trunk/testing/mocks/osgi-mock</url>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.osgi-mock-1.7.0</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.osgi-mock-1.7.0</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.testing.osgi-mock-1.7.0</url>
     </scm>
 
     <dependencies>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-testing-osgi-mock] 02/05: SLING-5143 osgi-mock: MockBundleContext is not thread-safe when using iterators

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.testing.osgi-mock-1.7.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit 5bdecdf3e1780b928c5463563cea98556fcb584e
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Wed Oct 14 08:09:57 2015 +0000

    SLING-5143 osgi-mock: MockBundleContext is not thread-safe when using iterators
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1708556 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/testing/mock/osgi/MatchAllFilter.java    | 46 ++++++++++++++++++++++
 .../sling/testing/mock/osgi/MockBundleContext.java | 30 ++++++++------
 2 files changed, 65 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MatchAllFilter.java b/src/main/java/org/apache/sling/testing/mock/osgi/MatchAllFilter.java
new file mode 100644
index 0000000..0a7aaf3
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MatchAllFilter.java
@@ -0,0 +1,46 @@
+/*
+ * 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.sling.testing.mock.osgi;
+
+import java.util.Dictionary;
+
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * OSGi filter that matches all.
+ */
+class MatchAllFilter implements Filter {
+
+    @Override
+    public boolean match(ServiceReference reference) {
+        return true;
+    }
+
+    @Override
+    public boolean match(Dictionary dictionary) {
+        return true;
+    }
+
+    @Override
+    public boolean matchCase(Dictionary dictionary) {
+        return true;
+    }
+
+}
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
index 605fb82..5342e7f 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
@@ -18,21 +18,19 @@
  */
 package org.apache.sling.testing.mock.osgi;
 
-import static java.util.Collections.synchronizedList;
-import static java.util.Collections.synchronizedMap;
-import static java.util.Collections.synchronizedSortedSet;
-
 import java.io.File;
 import java.io.InputStream;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Dictionary;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Queue;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ConcurrentSkipListSet;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.felix.framework.FilterImpl;
@@ -60,9 +58,9 @@ import com.google.common.collect.ImmutableList;
 class MockBundleContext implements BundleContext {
 
     private final MockBundle bundle;
-    private final SortedSet<MockServiceRegistration> registeredServices = synchronizedSortedSet(new TreeSet<MockServiceRegistration>());
-    private final Map<ServiceListener, Filter> serviceListeners = synchronizedMap(new HashMap<ServiceListener, Filter>());
-    private final List<BundleListener> bundleListeners = synchronizedList(new ArrayList<BundleListener>());
+    private final SortedSet<MockServiceRegistration> registeredServices = new ConcurrentSkipListSet<MockServiceRegistration>();
+    private final Map<ServiceListener, Filter> serviceListeners = new ConcurrentHashMap<ServiceListener, Filter>();
+    private final Queue<BundleListener> bundleListeners = new ConcurrentLinkedQueue<BundleListener>();
 
     public MockBundleContext() {
         this.bundle = new MockBundle(this);
@@ -75,7 +73,12 @@ class MockBundleContext implements BundleContext {
 
     @Override
     public Filter createFilter(final String s) throws InvalidSyntaxException {
-        return new FilterImpl(s);
+        if (s == null) {
+            return new MatchAllFilter();
+        }
+        else {
+            return new FilterImpl(s);
+        }
     }
 
     @Override
@@ -221,7 +224,12 @@ class MockBundleContext implements BundleContext {
 
     @Override
     public void addServiceListener(final ServiceListener serviceListener) {
-        serviceListeners.put(serviceListener, null);
+        try {
+            addServiceListener(serviceListener, null);
+        }
+        catch (InvalidSyntaxException ex) {
+            throw new RuntimeException(ex);
+        }
     }
 
     @Override

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-testing-osgi-mock] 03/05: SLING-5198 osgi-mock: Add basic ConfigurationAdmin support

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.testing.osgi-mock-1.7.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit 3c176625d1ba6d92dedee6a626e57d2592152499
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Oct 26 17:49:05 2015 +0000

    SLING-5198 osgi-mock: Add basic ConfigurationAdmin support
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1710663 13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/testing/mock/osgi/MapUtil.java    |  64 ++++++++-----
 .../sling/testing/mock/osgi/MockBundleContext.java |   7 +-
 .../sling/testing/mock/osgi/MockConfiguration.java | 103 +++++++++++++++++++++
 .../testing/mock/osgi/MockConfigurationAdmin.java  |  62 +++++++++++++
 .../apache/sling/testing/mock/osgi/MockOsgi.java   |  25 ++++-
 .../testing/mock/osgi/MockServiceRegistration.java |  10 +-
 .../mock/osgi/MockConfigurationAdminTest.java      |  80 ++++++++++++++++
 .../mock/osgi/MockServiceReferenceTest.java        |   6 +-
 .../testing/mock/osgi/OsgiMetadataUtilTest.java    |   5 +-
 src/test/resources/OSGI-INF/serviceComponents.xml  |   4 +-
 10 files changed, 322 insertions(+), 44 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MapUtil.java b/src/main/java/org/apache/sling/testing/mock/osgi/MapUtil.java
index 8a9e4a8..45d7a31 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MapUtil.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MapUtil.java
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.testing.mock.osgi;
 
+import java.io.IOException;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -25,6 +26,9 @@ import java.util.Hashtable;
 import java.util.Map;
 
 import org.apache.sling.testing.mock.osgi.OsgiMetadataUtil.OsgiMetadata;
+import org.osgi.framework.Constants;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
 
 /**
  * Map util methods.
@@ -51,35 +55,51 @@ final class MapUtil {
         return map;
     }
 
-    public static Dictionary<String, Object> propertiesMergeWithOsgiMetadata(Object target, Dictionary<String, Object> properties) {
-        Dictionary<String, Object> mergedProperties = new Hashtable<String, Object>();
-        
-        OsgiMetadata metadata = OsgiMetadataUtil.getMetadata(target.getClass());
-        if (metadata != null && metadata.getProperties() != null) {
-            for (Map.Entry<String, Object> entry : metadata.getProperties().entrySet()) {
-                mergedProperties.put(entry.getKey(), entry.getValue());
-            }
-        }
-        
-        if (properties != null) {
-            Enumeration<String> keys = properties.keys();
-            while (keys.hasMoreElements()) {
-                String key = keys.nextElement();
-                mergedProperties.put(key, properties.get(key));
-            }
-        }
-        
-        return mergedProperties;
+    public static Dictionary<String, Object> propertiesMergeWithOsgiMetadata(Object target, 
+            ConfigurationAdmin configAdmin, 
+            Dictionary<String, Object> properties) {
+        return toDictionary(propertiesMergeWithOsgiMetadata(target, configAdmin, toMap(properties)));
     }
     
-    public static Map<String, Object> propertiesMergeWithOsgiMetadata(Object target, Map<String, Object> properties) {
+    /**
+     * Merge service properties from three sources (with this precedence):
+     * 1. Properties defined in calling unit test code
+     * 2. Properties from ConfigurationAdmin
+     * 3. Properties from OSGi SCR metadata
+     * @param target Target service
+     * @param configAdmin Configuration admin or null if none is registered
+     * @param properties Properties from unit test code or null if none where passed
+     * @return Merged properties
+     */
+    @SuppressWarnings("unchecked")
+    public static Map<String, Object> propertiesMergeWithOsgiMetadata(Object target,
+            ConfigurationAdmin configAdmin,
+            Map<String, Object> properties) {
         Map<String, Object> mergedProperties = new HashMap<String, Object>();
         
         OsgiMetadata metadata = OsgiMetadataUtil.getMetadata(target.getClass());
-        if (metadata != null && metadata.getProperties() != null) {
-            mergedProperties.putAll(metadata.getProperties());
+        if (metadata != null) {
+            Map<String,Object> metadataProperties = metadata.getProperties();
+            if (metadataProperties != null) {
+                mergedProperties.putAll(metadataProperties);
+
+                // merge with configuration from config admin
+                if (configAdmin != null) {
+                    Object pid = metadataProperties.get(Constants.SERVICE_PID);
+                    if (pid != null) {
+                        try {
+                            Configuration config = configAdmin.getConfiguration(pid.toString());
+                            mergedProperties.putAll(toMap(config.getProperties()));
+                        }
+                        catch (IOException ex) {
+                            throw new RuntimeException("Unable to read config for pid " + pid, ex);
+                        }
+                    }
+                }
+            }
         }
         
+        // merge with properties from calling unit test code
         if (properties != null) {
             mergedProperties.putAll(properties);
         }
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
index 5342e7f..786fad7 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
@@ -49,6 +49,7 @@ import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceListener;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationAdmin;
 
 import com.google.common.collect.ImmutableList;
 
@@ -61,9 +62,13 @@ class MockBundleContext implements BundleContext {
     private final SortedSet<MockServiceRegistration> registeredServices = new ConcurrentSkipListSet<MockServiceRegistration>();
     private final Map<ServiceListener, Filter> serviceListeners = new ConcurrentHashMap<ServiceListener, Filter>();
     private final Queue<BundleListener> bundleListeners = new ConcurrentLinkedQueue<BundleListener>();
+    private final ConfigurationAdmin configAdmin = new MockConfigurationAdmin();
 
     public MockBundleContext() {
         this.bundle = new MockBundle(this);
+        
+        // register configuration admin by default
+        registerService(ConfigurationAdmin.class.getName(), configAdmin, null);
     }
 
     @Override
@@ -100,7 +105,7 @@ class MockBundleContext implements BundleContext {
     @SuppressWarnings("unchecked")
     @Override
     public ServiceRegistration registerService(final String[] clazzes, final Object service, final Dictionary properties) {
-        Dictionary<String, Object> mergedPropertes = MapUtil.propertiesMergeWithOsgiMetadata(service, properties);
+        Dictionary<String, Object> mergedPropertes = MapUtil.propertiesMergeWithOsgiMetadata(service, configAdmin, properties);
         MockServiceRegistration registration = new MockServiceRegistration(this.bundle, clazzes, service, mergedPropertes, this);
         handleRefsUpdateOnRegister(registration);
         this.registeredServices.add(registration);
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockConfiguration.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockConfiguration.java
new file mode 100644
index 0000000..4959cb6
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockConfiguration.java
@@ -0,0 +1,103 @@
+/*
+ * 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.sling.testing.mock.osgi;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.osgi.framework.Constants;
+import org.osgi.service.cm.Configuration;
+
+/**
+ * Mock implementation of {@link Configuration}.
+ */
+class MockConfiguration implements Configuration {
+    
+    private final String pid;
+    private Dictionary<String, Object> props;
+    
+    /**
+     * @param pid PID
+     */
+    public MockConfiguration(String pid) {
+        this.pid = pid;
+        props = newConfig(pid);
+    }
+
+    @Override
+    public String getPid() {
+        return pid;
+    }
+
+    @Override
+    public Dictionary getProperties() {
+        // return copy of dictionary
+        return new Hashtable<String,Object>(MapUtil.toMap(props));
+    }
+
+    @Override
+    public void update() {
+        // the updating of services already registered in mock-osgi is currently not supported.
+        // still allow calling this method to allow usage of {@link update(Dictionary)}, but it works
+        // only if applied bevore registering a service in mock-osgi.
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void update(Dictionary properties) {
+        this.props = new Hashtable<String, Object>(MapUtil.toMap(properties));;
+        this.props.put(Constants.SERVICE_PID, pid);
+        this.update();
+    }
+
+    @Override
+    public void delete() {
+        // just clear the props map
+        props = newConfig(pid);
+    }
+    
+    @Override
+    public String toString() {
+        return props.toString();
+    }
+
+    private static Dictionary<String,Object> newConfig(String pid) {
+        Dictionary<String, Object> config = new Hashtable<String, Object>();
+        config.put(Constants.SERVICE_PID, pid);
+        return config;
+    }
+
+    // --- unsupported operations ---
+    
+    @Override
+    public void setBundleLocation(String bundleLocation) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public String getBundleLocation() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public String getFactoryPid() {
+        throw new UnsupportedOperationException();
+    }
+
+}
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockConfigurationAdmin.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockConfigurationAdmin.java
new file mode 100644
index 0000000..f195c1c
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockConfigurationAdmin.java
@@ -0,0 +1,62 @@
+/*
+ * 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.sling.testing.mock.osgi;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/**
+ * Mock implementation of {@link ConfigurationAdmin}.
+ */
+class MockConfigurationAdmin implements ConfigurationAdmin {
+    
+    private ConcurrentMap<String, Configuration> configs = new ConcurrentHashMap<String, Configuration>();
+
+    @Override
+    public Configuration getConfiguration(String pid) {
+        configs.putIfAbsent(pid, new MockConfiguration(pid));
+        return configs.get(pid);
+    }
+
+    // --- unsupported operations ---
+
+    @Override
+    public Configuration getConfiguration(String pid, String location) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Configuration createFactoryConfiguration(String factoryPid) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Configuration createFactoryConfiguration(String factoryPid, String location) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Configuration[] listConfigurations(String filter) {
+        throw new UnsupportedOperationException();
+    }
+
+}
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java
index af48885..a189fda 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java
@@ -27,6 +27,8 @@ import java.util.Map;
 
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.log.LogService;
 
@@ -157,7 +159,7 @@ public final class MockOsgi {
      */
     @Deprecated
     public static boolean activate(Object target, Dictionary<String, Object> properties) {
-        Dictionary<String, Object> mergedProperties = propertiesMergeWithOsgiMetadata(target, properties);
+        Dictionary<String, Object> mergedProperties = propertiesMergeWithOsgiMetadata(target, null, properties);
         ComponentContext componentContext = newComponentContext(mergedProperties);
         return OsgiServiceUtil.activateDeactivate(target, componentContext, true);
     }
@@ -183,7 +185,7 @@ public final class MockOsgi {
      * @return true if activation method was called. False if no activate method is defined.
      */
     public static boolean activate(Object target, BundleContext bundleContext, Dictionary<String, Object> properties) {
-        Dictionary<String, Object> mergedProperties = propertiesMergeWithOsgiMetadata(target, properties);
+        Dictionary<String, Object> mergedProperties = propertiesMergeWithOsgiMetadata(target, getConfigAdmin(bundleContext), properties);
         ComponentContext componentContext = newComponentContext(bundleContext, mergedProperties);
         return OsgiServiceUtil.activateDeactivate(target, componentContext, true);
     }
@@ -231,7 +233,7 @@ public final class MockOsgi {
      */
     @Deprecated
     public static boolean deactivate(Object target, Dictionary<String, Object> properties) {
-        Dictionary<String, Object> mergedProperties = propertiesMergeWithOsgiMetadata(target, properties);
+        Dictionary<String, Object> mergedProperties = propertiesMergeWithOsgiMetadata(target, null, properties);
         ComponentContext componentContext = newComponentContext(mergedProperties);
         return OsgiServiceUtil.activateDeactivate(target, componentContext, false);
     }
@@ -257,7 +259,7 @@ public final class MockOsgi {
      * @return true if deactivation method was called. False if no deactivate method is defined.
      */
     public static boolean deactivate(Object target, BundleContext bundleContext, Dictionary<String, Object> properties) {
-        Dictionary<String, Object> mergedProperties = propertiesMergeWithOsgiMetadata(target, properties);
+        Dictionary<String, Object> mergedProperties = propertiesMergeWithOsgiMetadata(target, getConfigAdmin(bundleContext), properties);
         ComponentContext componentContext = newComponentContext(bundleContext, mergedProperties);
         return OsgiServiceUtil.activateDeactivate(target, componentContext, false);
     }
@@ -292,7 +294,7 @@ public final class MockOsgi {
      * @return true if modified method was called. False if no modified method is defined.
      */
     public static boolean modified(Object target, BundleContext bundleContext, Map<String, Object> properties) {
-        Map<String, Object> mergedProperties = propertiesMergeWithOsgiMetadata(target, properties);
+        Map<String, Object> mergedProperties = propertiesMergeWithOsgiMetadata(target, getConfigAdmin(bundleContext), properties);
         return OsgiServiceUtil.modified(target, bundleContext, mergedProperties);
     }
     
@@ -304,4 +306,17 @@ public final class MockOsgi {
         ((MockBundleContext)bundleContext).shutdown();
     }
     
+    /**
+     * Get configuration admin.
+     * @param bundleContext Bundle context
+     * @return Configuration admin or null if not registered.
+     */
+    private static ConfigurationAdmin getConfigAdmin(BundleContext bundleContext) {
+        ServiceReference ref = bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
+        if (ref != null) {
+            return (ConfigurationAdmin)bundleContext.getService(ref);
+        }
+        return null;
+    }
+    
 }
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
index 488cfa7..8ef25a4 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
@@ -21,7 +21,6 @@ package org.apache.sling.testing.mock.osgi;
 import java.util.Dictionary;
 import java.util.HashSet;
 import java.util.Hashtable;
-import java.util.Map;
 import java.util.Set;
 
 import org.apache.commons.lang3.StringUtils;
@@ -124,8 +123,7 @@ class MockServiceRegistration implements ServiceRegistration, Comparable<MockSer
     }
 
     /**
-     * Try to read OSGI-metadata from /OSGI-INF and read all implemented
-     * interfaces and service properties
+     * Try to read OSGI-metadata from /OSGI-INF and read all implemented interfaces
      */
     private void readOsgiMetadata() {
         Class<?> serviceClass = service.getClass();
@@ -136,12 +134,6 @@ class MockServiceRegistration implements ServiceRegistration, Comparable<MockSer
 
         // add service interfaces from OSGi metadata
         clazzes.addAll(metadata.getServiceInterfaces());
-
-        // add properties from OSGi metadata
-        Map<String, Object> props = metadata.getProperties();
-        for (Map.Entry<String, Object> entry : props.entrySet()) {
-            properties.put(entry.getKey(), entry.getValue());
-        }
     }
 
     @Override
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MockConfigurationAdminTest.java b/src/test/java/org/apache/sling/testing/mock/osgi/MockConfigurationAdminTest.java
new file mode 100644
index 0000000..ded699f
--- /dev/null
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/MockConfigurationAdminTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.sling.testing.mock.osgi;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.sling.testing.mock.osgi.OsgiMetadataUtilTest.ServiceWithMetadata;
+import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
+import org.junit.Rule;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+import com.google.common.collect.ImmutableMap;
+
+public class MockConfigurationAdminTest {
+    
+    private static final String[] TEST_ADAPTABLES = new String[] {
+        "adaptable1",
+        "adaptable2"
+    };
+
+    @Rule
+    public OsgiContext context = new OsgiContext();
+
+    @Test
+    public void testGetConfigurationString() throws IOException {
+        ConfigurationAdmin configAdmin = context.getService(ConfigurationAdmin.class);
+        
+        Configuration config = configAdmin.getConfiguration("org.apache.sling.testing.mock.osgi.OsgiMetadataUtilTest$ServiceWithMetadata");
+        Dictionary<String, Object> configProps = new Hashtable<String, Object>();
+        configProps.put(Constants.SERVICE_RANKING, 3000);
+        configProps.put("adaptables", TEST_ADAPTABLES);
+        configProps.put("prop2", 2);
+        config.update(configProps);
+        
+        context.registerInjectActivateService(new ServiceWithMetadata(), ImmutableMap.<String, Object>builder()
+                .put(Constants.SERVICE_RANKING, 4000)
+                .put("prop1", 1)
+                .build());
+        
+        ServiceReference reference = context.bundleContext().getServiceReference(Comparable.class.getName());
+
+        // values passed over when registering service has highest precedence
+        assertEquals(4000, reference.getProperty(Constants.SERVICE_RANKING));
+        assertEquals(1, reference.getProperty("prop1"));
+
+        // values set in config admin has 2ndmost highest precedence
+        assertArrayEquals(TEST_ADAPTABLES, (String[])reference.getProperty("adaptables"));
+        assertEquals(2, reference.getProperty("prop2"));
+
+        // values set in OSGi SCR metadata
+        assertEquals("The Apache Software Foundation", reference.getProperty(Constants.SERVICE_VENDOR));
+        assertEquals("org.apache.sling.testing.mock.osgi.OsgiMetadataUtilTest$ServiceWithMetadata", reference.getProperty(Constants.SERVICE_PID));
+    }
+
+}
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MockServiceReferenceTest.java b/src/test/java/org/apache/sling/testing/mock/osgi/MockServiceReferenceTest.java
index 2eb7cc3..b938754 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/MockServiceReferenceTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/MockServiceReferenceTest.java
@@ -77,9 +77,9 @@ public class MockServiceReferenceTest {
         bundleContext.registerService((String) null, serviceWithMetadata, null);
         ServiceReference reference = this.bundleContext.getServiceReference(Comparable.class.getName());
 
-        assertEquals(5000, reference.getProperty("service.ranking"));
-        assertEquals("The Apache Software Foundation", reference.getProperty("service.vendor"));
-        assertEquals("org.apache.sling.models.impl.injectors.OSGiServiceInjector", reference.getProperty("service.pid"));
+        assertEquals(5000, reference.getProperty(Constants.SERVICE_RANKING));
+        assertEquals("The Apache Software Foundation", reference.getProperty(Constants.SERVICE_VENDOR));
+        assertEquals("org.apache.sling.testing.mock.osgi.OsgiMetadataUtilTest$ServiceWithMetadata", reference.getProperty(Constants.SERVICE_PID));
     }
 
 }
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtilTest.java b/src/test/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtilTest.java
index 6663f81..050d951 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtilTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtilTest.java
@@ -31,6 +31,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.sling.testing.mock.osgi.OsgiMetadataUtil.OsgiMetadata;
 import org.apache.sling.testing.mock.osgi.OsgiMetadataUtil.Reference;
 import org.junit.Test;
+import org.osgi.framework.Constants;
 
 public class OsgiMetadataUtilTest {
 
@@ -48,8 +49,8 @@ public class OsgiMetadataUtilTest {
         Map<String, Object> props = metadata.getProperties();
         assertEquals(4, props.size());
         assertEquals(5000, props.get("service.ranking"));
-        assertEquals("The Apache Software Foundation", props.get("service.vendor"));
-        assertEquals("org.apache.sling.models.impl.injectors.OSGiServiceInjector", props.get("service.pid"));
+        assertEquals("The Apache Software Foundation", props.get(Constants.SERVICE_VENDOR));
+        assertEquals("org.apache.sling.testing.mock.osgi.OsgiMetadataUtilTest$ServiceWithMetadata", props.get(Constants.SERVICE_PID));
         assertArrayEquals(new String[] { "org.apache.sling.api.resource.Resource", "org.apache.sling.api.resource.ResourceResolver" },
                 (String[])props.get("adaptables"));
     }
diff --git a/src/test/resources/OSGI-INF/serviceComponents.xml b/src/test/resources/OSGI-INF/serviceComponents.xml
index 14840ed..882de1c 100644
--- a/src/test/resources/OSGI-INF/serviceComponents.xml
+++ b/src/test/resources/OSGI-INF/serviceComponents.xml
@@ -19,7 +19,7 @@
 -->
 <!-- This file follows the old SCR convention using a fixed name "serviceComponents.xml" -->
 <components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0">
-  <scr:component name="org.apache.sling.testing.mock.osgi.OsgiMetadataUtilTest$ServiceWithMetadata" activate="activate">
+  <scr:component name="org.apache.sling.testing.mock.osgi.OsgiMetadataUtilTest$ServiceWithMetadata">
     <implementation class="org.apache.sling.testing.mock.osgi.OsgiMetadataUtilTest$ServiceWithMetadata"/>
     <service servicefactory="false">
       <provide interface="org.apache.sling.models.spi.Injector"/>
@@ -28,7 +28,7 @@
     </service>
     <property name="service.ranking" type="Integer" value="5000"/>
     <property name="service.vendor" value="The Apache Software Foundation"/>
-    <property name="service.pid" value="org.apache.sling.models.impl.injectors.OSGiServiceInjector"/>
+    <property name="service.pid" value="org.apache.sling.testing.mock.osgi.OsgiMetadataUtilTest$ServiceWithMetadata"/>
     <property name="adaptables">
        org.apache.sling.api.resource.Resource
        org.apache.sling.api.resource.ResourceResolver

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-testing-osgi-mock] 05/05: [maven-release-plugin] copy for tag org.apache.sling.testing.osgi-mock-1.7.0

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.testing.osgi-mock-1.7.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit 5b4b909ad0afc1b1027f0b5e3f0fadf934c7269b
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Wed Nov 4 21:34:40 2015 +0000

    [maven-release-plugin] copy for tag org.apache.sling.testing.osgi-mock-1.7.0
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.osgi-mock-1.7.0@1712660 13f79535-47bb-0310-9956-ffa450edef68

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.