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:20:11 UTC

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

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.8.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git.


      at b631d04  (tag)
 tagging 5a2fd5ab2e9881a04ddb852752e8d9a1d39d19ce (commit)
      by Stefan Seifert
      on Wed Sep 14 21:45:22 2016 +0000

- Log -----------------------------------------------------------------
org.apache.sling.testing.osgi-mock-1.8.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 d38d8c1  [maven-release-plugin] prepare for next development iteration
     new 505f211  SLING-5312 osgi-mock: Eliminate runtime-depenency to Felix SCR annotations
     new 4553407  1.x branch
     new 6dab99f  update scm urls for branch
     new 52b14aa  SLING-5453 implement MockBundleContext.getDataFile
     new 8682e4e  SLING-5462 ensure service references are sorted ascending by service ranking, not descending
     new 3a3b1f7  SLING-5462 switch to comparable implementation from commons.osgi and change wrong assumptions in unit test
     new 93af131  [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-1.7.2
     new 852ecbc  [maven-release-plugin] prepare for next development iteration
     new dba4e2b  Switch to parent pom 26
     new 1a0e5ad  SLING-5544 osgi-mock: Catch RejectedExecutionException in MockEventAdmin
     new 29207e0  SLING-6051 osgi-mock: Support passing map/dictionary properties with object vararg parameter
     new 3c1c87c  [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-1.8.0
     new 5a2fd5a  [maven-release-plugin] copy for tag org.apache.sling.testing.osgi-mock-1.8.0

The 99 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] 06/06: [maven-release-plugin] copy for tag org.apache.sling.testing.osgi-mock-1.8.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.8.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit 5a2fd5ab2e9881a04ddb852752e8d9a1d39d19ce
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Wed Sep 14 21:45:22 2016 +0000

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

-- 
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/06: SLING-6051 osgi-mock: Support passing map/dictionary properties with object vararg parameter

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.8.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit 29207e030a22ad4234d7bdd9fb76c2a2a307c666
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Tue Sep 13 09:30:53 2016 +0000

    SLING-6051 osgi-mock: Support passing map/dictionary properties with object vararg parameter
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/branches/testing/mocks/osgi-mock-1.x@1760503 13f79535-47bb-0310-9956-ffa450edef68
---
 .../testing/mock/osgi/ComponentContextBuilder.java |  5 ++
 .../mock/osgi/{MapUtil.java => MapMergeUtil.java}  | 31 ++------
 .../apache/sling/testing/mock/osgi/MapUtil.java    | 93 ++++++++++------------
 .../sling/testing/mock/osgi/MockBundleContext.java |  2 +-
 .../apache/sling/testing/mock/osgi/MockOsgi.java   | 56 ++++++++++++-
 .../testing/mock/osgi/context/OsgiContextImpl.java | 31 +++++++-
 .../testing/mock/osgi/context/package-info.java    |  2 +-
 .../testing/mock/osgi/junit/package-info.java      |  2 +-
 .../sling/testing/mock/osgi/package-info.java      |  2 +-
 .../sling/testing/mock/osgi/MapUtilTest.java       | 57 +++++++++++++
 .../OsgiServiceUtilActivateDeactivateTest.java     |  2 +-
 .../testing/mock/osgi/OsgiServiceUtilTest.java     |  3 +
 .../mock/osgi/context/OsgiContextImplTest.java     | 19 +++++
 13 files changed, 223 insertions(+), 82 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/ComponentContextBuilder.java b/src/main/java/org/apache/sling/testing/mock/osgi/ComponentContextBuilder.java
index 2e8916a..a87ed41 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/ComponentContextBuilder.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/ComponentContextBuilder.java
@@ -54,6 +54,11 @@ public final class ComponentContextBuilder {
         return this;
     }
         
+    public ComponentContextBuilder properties(Object... properties) {
+        this.properties = MapUtil.toDictionary(properties);
+        return this;
+    }
+        
     public ComponentContextBuilder usingBundle(Bundle usingBundle) {
         this.usingBundle = usingBundle;
         return this;
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MapUtil.java b/src/main/java/org/apache/sling/testing/mock/osgi/MapMergeUtil.java
similarity index 83%
copy from src/main/java/org/apache/sling/testing/mock/osgi/MapUtil.java
copy to src/main/java/org/apache/sling/testing/mock/osgi/MapMergeUtil.java
index 45d7a31..c6dccb7 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MapUtil.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MapMergeUtil.java
@@ -18,11 +18,12 @@
  */
 package org.apache.sling.testing.mock.osgi;
 
+import static org.apache.sling.testing.mock.osgi.MapUtil.toDictionary;
+import static org.apache.sling.testing.mock.osgi.MapUtil.toMap;
+
 import java.io.IOException;
 import java.util.Dictionary;
-import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.Hashtable;
 import java.util.Map;
 
 import org.apache.sling.testing.mock.osgi.OsgiMetadataUtil.OsgiMetadata;
@@ -31,28 +32,12 @@ import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
 
 /**
- * Map util methods.
+ * Map merge util methods.
  */
-final class MapUtil {
-
-    public static <T, U> Dictionary<T, U> toDictionary(Map<T, U> map) {
-        if (map == null) {
-            return null;
-        }
-        return new Hashtable<T, U>(map);
-    }
-
-    public static <T, U> Map<T, U> toMap(Dictionary<T, U> dictionary) {
-        if (dictionary == null) {
-            return null;
-        }
-        Map<T, U> map = new HashMap<T, U>();
-        Enumeration<T> keys = dictionary.keys();
-        while (keys.hasMoreElements()) {
-            T key = keys.nextElement();
-            map.put(key, dictionary.get(key));
-        }
-        return map;
+final class MapMergeUtil {
+    
+    private MapMergeUtil() {
+        // static methods only
     }
 
     public static Dictionary<String, Object> propertiesMergeWithOsgiMetadata(Object target, 
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 45d7a31..0f0775c 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,23 +18,28 @@
  */
 package org.apache.sling.testing.mock.osgi;
 
-import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
 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.
  */
-final class MapUtil {
+public final class MapUtil {
+    
+    private MapUtil() {
+        // static methods only
+    }
 
+    /**
+     * Convert map to dictionary.
+     * @param map Map
+     * @return Dictionary
+     */
     public static <T, U> Dictionary<T, U> toDictionary(Map<T, U> map) {
         if (map == null) {
             return null;
@@ -42,6 +47,11 @@ final class MapUtil {
         return new Hashtable<T, U>(map);
     }
 
+    /**
+     * Convert Dictionary to map
+     * @param dictionary Dictionary
+     * @return Map
+     */
     public static <T, U> Map<T, U> toMap(Dictionary<T, U> dictionary) {
         if (dictionary == null) {
             return null;
@@ -55,56 +65,41 @@ final class MapUtil {
         return map;
     }
 
-    public static Dictionary<String, Object> propertiesMergeWithOsgiMetadata(Object target, 
-            ConfigurationAdmin configAdmin, 
-            Dictionary<String, Object> properties) {
-        return toDictionary(propertiesMergeWithOsgiMetadata(target, configAdmin, toMap(properties)));
+    /**
+     * Convert key/value pairs to dictionary
+     * @param args Key/value pairs
+     * @return Dictionary
+     */
+    public static Dictionary<String, Object> toDictionary(Object... args) {
+        return toDictionary(toMap(args));
     }
     
     /**
-     * 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
+     * Convert key/value pairs to map
+     * @param args Key/value pairs
+     * @return Map
      */
     @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) {
-            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);
-                        }
-                    }
-                }
+    public static Map<String, Object> toMap(Object... args) {
+        if (args == null || args.length == 0) {
+            return Collections.emptyMap();
+        }
+        if (args.length == 1) {
+            if (args[0] instanceof Map) {
+                return (Map)args[0];
+            }
+            else if (args[0] instanceof Dictionary) {
+                return toMap((Dictionary)args[0]);
             }
         }
-        
-        // merge with properties from calling unit test code
-        if (properties != null) {
-            mergedProperties.putAll(properties);
+        if (args.length % 2 != 0) {
+            throw new IllegalArgumentException("args must be an even number of name/values:" + Arrays.asList(args));
+        }
+        final Map<String, Object> result = new HashMap<String, Object>();
+        for (int i=0 ; i < args.length; i+=2) {
+            result.put(args[i].toString(), args[i+1]);
         }
-        
-        return mergedProperties;
+        return result;
     }
     
 }
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 003a304..ce94c04 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
@@ -109,7 +109,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, configAdmin, properties);
+        Dictionary<String, Object> mergedPropertes = MapMergeUtil.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/MockOsgi.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java
index a189fda..4e04921 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
@@ -18,7 +18,7 @@
  */
 package org.apache.sling.testing.mock.osgi;
 
-import static org.apache.sling.testing.mock.osgi.MapUtil.propertiesMergeWithOsgiMetadata;
+import static org.apache.sling.testing.mock.osgi.MapMergeUtil.propertiesMergeWithOsgiMetadata;
 import static org.apache.sling.testing.mock.osgi.MapUtil.toDictionary;
 import static org.apache.sling.testing.mock.osgi.MapUtil.toMap;
 
@@ -82,6 +82,14 @@ public final class MockOsgi {
     }
 
     /**
+     * @param properties Properties
+     * @return Mocked {@link ComponentContext} instance
+     */
+    public static ComponentContext newComponentContext(Object... properties) {
+        return componentContext().properties(properties).build();
+    }
+
+    /**
      * @param bundleContext Bundle context
      * @param properties Properties
      * @return Mocked {@link ComponentContext} instance
@@ -96,7 +104,18 @@ public final class MockOsgi {
      * @param properties Properties
      * @return Mocked {@link ComponentContext} instance
      */
-    public static ComponentContext newComponentContext(BundleContext bundleContext, Map<String, Object> properties) {
+    public static ComponentContext newComponentContext(BundleContext bundleContext,
+            Map<String, Object> properties) {
+        return componentContext().bundleContext(bundleContext).properties(properties).build();
+    }
+
+    /**
+     * @param bundleContext Bundle context
+     * @param properties Properties
+     * @return Mocked {@link ComponentContext} instance
+     */
+    public static ComponentContext newComponentContext(BundleContext bundleContext,
+            Object... properties) {
         return componentContext().bundleContext(bundleContext).properties(properties).build();
     }
 
@@ -202,6 +221,17 @@ public final class MockOsgi {
     }
 
     /**
+     * Simulate activation of service instance. Invokes the @Activate annotated method.
+     * @param target Service instance.
+     * @param bundleContext Bundle context
+     * @param properties Properties
+     * @return true if activation method was called. False if no activate method is defined.
+     */
+    public static boolean activate(Object target, BundleContext bundleContext, Object... properties) {
+        return activate(target, bundleContext, toDictionary(properties));
+    }
+
+    /**
      * Simulate deactivation of service instance. Invokes the @Deactivate annotated method.
      * @param target Service instance.
      * @return true if deactivation method was called. False if no deactivate method is defined.
@@ -276,6 +306,17 @@ public final class MockOsgi {
     }
 
     /**
+     * Simulate activation of service instance. Invokes the @Deactivate annotated method.
+     * @param target Service instance.
+     * @param bundleContext Bundle context
+     * @param properties Properties
+     * @return true if deactivation method was called. False if no deactivate method is defined.
+     */
+    public static boolean deactivate(Object target, BundleContext bundleContext, Object... properties) {
+        return deactivate(target, bundleContext, toDictionary(properties));
+    }
+
+    /**
      * Simulate configuration modification of service instance. Invokes the @Modified annotated method.
      * @param target Service instance.
      * @param bundleContext Bundle context
@@ -299,6 +340,17 @@ public final class MockOsgi {
     }
     
     /**
+     * Simulate configuration modification of service instance. Invokes the @Modified annotated method.
+     * @param target Service instance.
+     * @param bundleContext Bundle context
+     * @param properties Properties
+     * @return true if modified method was called. False if no modified method is defined.
+     */
+    public static boolean modified(Object target, BundleContext bundleContext, Object... properties) {
+        return modified(target, bundleContext, toMap(properties));
+    }
+    
+    /**
      * Deactivates all bundles registered in the mocked bundle context.
      * @param bundleContext Bundle context
      */
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImpl.java b/src/main/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImpl.java
index 4847a2d..ab160ac 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImpl.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImpl.java
@@ -24,6 +24,7 @@ import java.util.Hashtable;
 import java.util.Map;
 
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.sling.testing.mock.osgi.MapUtil;
 import org.apache.sling.testing.mock.osgi.MockEventAdmin;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.osgi.framework.BundleContext;
@@ -92,7 +93,7 @@ public class OsgiContextImpl {
      * @return Registered service instance
      */
     public final <T> T registerService(final T service) {
-        return registerService(null, service, null);
+        return registerService(null, service, (Map<String,Object>)null);
     }
 
     /**
@@ -103,7 +104,7 @@ public class OsgiContextImpl {
      * @return Registered service instance
      */
     public final <T> T registerService(final Class<T> serviceClass, final T service) {
-        return registerService(serviceClass, service, null);
+        return registerService(serviceClass, service, (Map<String,Object>)null);
     }
 
     /**
@@ -124,6 +125,18 @@ public class OsgiContextImpl {
     }
 
     /**
+     * Registers a service in the mocked OSGi environment.
+     * @param <T> Service type
+     * @param serviceClass Service class
+     * @param service Service instance
+     * @param properties Service properties (optional)
+     * @return Registered service instance
+     */
+    public final <T> T registerService(final Class<T> serviceClass, final T service, final Object... properties) {
+        return registerService(serviceClass, service, MapUtil.toMap(properties));
+    }
+    
+    /**
      * Injects dependencies, activates and registers a service in the mocked
      * OSGi environment.
      * @param <T> Service type
@@ -131,7 +144,7 @@ public class OsgiContextImpl {
      * @return Registered service instance
      */
     public final <T> T registerInjectActivateService(final T service) {
-        return registerInjectActivateService(service, null);
+        return registerInjectActivateService(service, (Map<String,Object>)null);
     }
 
     /**
@@ -150,6 +163,18 @@ public class OsgiContextImpl {
     }
 
     /**
+     * Injects dependencies, activates and registers a service in the mocked
+     * OSGi environment.
+     * @param <T> Service type
+     * @param service Service instance
+     * @param properties Service properties (optional)
+     * @return Registered service instance
+     */
+    public final <T> T registerInjectActivateService(final T service, final Object... properties) {
+        return registerInjectActivateService(service, MapUtil.toMap(properties));
+    }
+
+    /**
      * Lookup a single service
      * @param <ServiceType> Service type
      * @param serviceType The type (interface) of the service.
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/context/package-info.java b/src/main/java/org/apache/sling/testing/mock/osgi/context/package-info.java
index 1ac49a4..debaa88 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/context/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/context/package-info.java
@@ -19,5 +19,5 @@
 /**
  * OSGi context implementation for unit tests.
  */
-@aQute.bnd.annotation.Version("1.0")
+@aQute.bnd.annotation.Version("1.1")
 package org.apache.sling.testing.mock.osgi.context;
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/package-info.java b/src/main/java/org/apache/sling/testing/mock/osgi/junit/package-info.java
index dd18eb6..83cd0a8 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/junit/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/junit/package-info.java
@@ -19,5 +19,5 @@
 /**
  * Rule for providing easy access to OSGi context in JUnit tests.
  */
-@aQute.bnd.annotation.Version("1.0")
+@aQute.bnd.annotation.Version("1.1")
 package org.apache.sling.testing.mock.osgi.junit;
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java b/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
index fe5f126..1d3d622 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
@@ -19,5 +19,5 @@
 /**
  * Mock implementation of selected OSGi APIs.
  */
-@aQute.bnd.annotation.Version("2.4")
+@aQute.bnd.annotation.Version("2.5")
 package org.apache.sling.testing.mock.osgi;
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MapUtilTest.java b/src/test/java/org/apache/sling/testing/mock/osgi/MapUtilTest.java
new file mode 100644
index 0000000..369abdf
--- /dev/null
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/MapUtilTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.assertEquals;
+
+import java.util.Dictionary;
+import java.util.Map;
+
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class MapUtilTest {
+
+    @Test
+    public void testMapDictionary() {
+        Map<String,Object> map = ImmutableMap.<String, Object>of("param1", "var1", "param2", 123, "param3", true);
+        
+        Dictionary<String, Object> dict = MapUtil.toDictionary(map);
+        Map<String,Object> convertedMap = MapUtil.toMap(dict);
+        
+        assertEquals(map, convertedMap);
+    }
+    
+    @Test
+    public void testMapObjectVarargs() {
+        Map<String, Object> convertedMap = MapUtil.toMap("param1", "var1", "param2", 123, "param3", true);
+        
+        assertEquals(ImmutableMap.<String, Object>of("param1", "var1", "param2", 123, "param3", true), convertedMap);
+    }
+    
+    @Test
+    public void testDictionaryObjectVarargs() {
+        Dictionary<String, Object> dict = MapUtil.toDictionary("param1", "var1", "param2", 123, "param3", true);
+        Map<String,Object> convertedMap = MapUtil.toMap(dict);
+        
+        assertEquals(ImmutableMap.<String, Object>of("param1", "var1", "param2", 123, "param3", true), convertedMap);
+    }
+    
+}
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilActivateDeactivateTest.java b/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilActivateDeactivateTest.java
index d848fe2..efd898d 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilActivateDeactivateTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilActivateDeactivateTest.java
@@ -58,7 +58,7 @@ public class OsgiServiceUtilActivateDeactivateTest {
     public void testService2() {
         Service2 service = new Service2();
         
-        assertTrue(MockOsgi.activate(service, bundleContext, map));
+        assertTrue(MockOsgi.activate(service, bundleContext, "prop1", "value1"));
         assertTrue(service.isActivated());
         assertSame(bundleContext, service.getBundleContext());
         
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java b/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java
index f8b9a73..253b401 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java
@@ -121,6 +121,9 @@ public class OsgiServiceUtilTest {
         Dictionary<String,Object> newPropertiesDictonary = new Hashtable<String,Object>(newProperties);
         MockOsgi.modified(service3, bundleContext, newPropertiesDictonary);
         assertEquals(newProperties.get("prop3"), service3.getConfig().get("prop3"));
+
+        MockOsgi.modified(service3, bundleContext, "prop3", "value4");
+        assertEquals("value4", service3.getConfig().get("prop3"));
     }
 
     @Test
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java b/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java
index 7086325..2ab6bd8 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java
@@ -82,6 +82,17 @@ public class OsgiContextImplTest {
     }
 
     @Test
+    public void testRegisterServiceWithPropertiesVarargs() {
+        Set<String> myService = new HashSet<String>();
+        context.registerService(Set.class, myService, "prop1", "value1");
+
+        ServiceReference serviceReference = context.bundleContext().getServiceReference(Set.class.getName());
+        Object serviceResult = context.bundleContext().getService(serviceReference);
+        assertSame(myService, serviceResult);
+        assertEquals("value1", serviceReference.getProperty("prop1"));
+    }
+
+    @Test
     public void testRegisterMultipleServices() {
         Set<String> myService1 = new HashSet<String>();
         context.registerService(Set.class, myService1);
@@ -101,6 +112,14 @@ public class OsgiContextImplTest {
         context.registerInjectActivateService(new OsgiServiceUtilTest.Service3());
     }
 
+    @Test
+    public void testRegisterInjectActivateWithProperties() {
+        context.registerService(ServiceInterface1.class, mock(ServiceInterface1.class));
+        context.registerService(ServiceInterface2.class, mock(ServiceInterface2.class));
+        OsgiServiceUtilTest.Service3 service = context.registerInjectActivateService(new OsgiServiceUtilTest.Service3(), "prop1", "value3");
+        assertEquals("value3", service.getConfig().get("prop1"));
+    }
+
     @Test(expected=RuntimeException.class)
     public void testRegisterInjectActivate_RefrenceMissing() {
         context.registerInjectActivateService(new OsgiServiceUtilTest.Service3());

-- 
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/06: SLING-5544 osgi-mock: Catch RejectedExecutionException in MockEventAdmin

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.8.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit 1a0e5ad91a33904f87b987125b0b56d58b7b58c6
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Feb 22 23:58:14 2016 +0000

    SLING-5544 osgi-mock: Catch RejectedExecutionException in MockEventAdmin
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/branches/testing/mocks/osgi-mock-1.x@1731759 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/testing/mock/osgi/MockEventAdmin.java       | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockEventAdmin.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockEventAdmin.java
index 55628da..d182d1f 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MockEventAdmin.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockEventAdmin.java
@@ -22,6 +22,7 @@ import java.util.Map;
 import java.util.TreeMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.RejectedExecutionException;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -69,12 +70,18 @@ public final class MockEventAdmin implements EventAdmin {
 
     @Override
     public void postEvent(final Event event) {
-        asyncHandler.execute(new Runnable() {
-            @Override
-            public void run() {
-                distributeEvent(event);
-            }
-        });
+        try {
+            asyncHandler.execute(new Runnable() {
+                @Override
+                public void run() {
+                    distributeEvent(event);
+                }
+            });
+        }
+        catch (RejectedExecutionException ex) {
+            // ignore
+            log.debug("Ignore rejected execution: " + ex.getMessage(), 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] 05/06: [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-1.8.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.8.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit 3c1c87cb4a7e3284aa67aef28050ccab4fa6e76b
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Wed Sep 14 21:45:09 2016 +0000

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

diff --git a/pom.xml b/pom.xml
index 43651c1..7c4dd07 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,16 +28,16 @@
     </parent>
 
     <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
-    <version>1.7.3-SNAPSHOT</version>
+    <version>1.8.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/branches/testing/mocks/osgi-mock-1.x</connection>
-        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/branches/testing/mocks/osgi-mock-1.x</developerConnection>
-        <url>http://svn.apache.org/viewvc/sling/branches/testing/mocks/osgi-mock-1.x</url>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.osgi-mock-1.8.0</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.osgi-mock-1.8.0</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.testing.osgi-mock-1.8.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] 01/06: [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.8.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit 852ecbce4087df4bb617287af573a537b78f7e74
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Feb 5 22:20:57 2016 +0000

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

diff --git a/pom.xml b/pom.xml
index 971886b..af7aab1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,16 +28,16 @@
     </parent>
 
     <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
-    <version>1.7.2</version>
+    <version>1.7.3-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.7.2</connection>
-        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.osgi-mock-1.7.2</developerConnection>
-        <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.testing.osgi-mock-1.7.2</url>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/branches/testing/mocks/osgi-mock-1.x</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/branches/testing/mocks/osgi-mock-1.x</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/branches/testing/mocks/osgi-mock-1.x</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/06: Switch to parent pom 26

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.8.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit dba4e2b6c7fccdbc964a5d069e61f0c17d590817
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Feb 5 22:35:59 2016 +0000

    Switch to parent pom 26
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/branches/testing/mocks/osgi-mock-1.x@1728760 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index af7aab1..43651c1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>25</version>
+        <version>26</version>
         <relativePath />
     </parent>
 

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