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:21:29 UTC

[sling-org-apache-sling-testing-osgi-mock] annotated tag org.apache.sling.testing.osgi-mock-2.2.0 created (now 04e2fe6)

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


      at 04e2fe6  (tag)
 tagging cdd909d51ff06f1fad4d4cfcf8c2a89c09a9a1b3 (commit)
      by Stefan Seifert
      on Mon Dec 5 17:46:30 2016 +0000

- Log -----------------------------------------------------------------
org.apache.sling.testing.osgi-mock-2.2.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 9618e26  SLING-5323 Update to OSGi R6
     new 3f5a172  SLING-5324 osgi-mock: Support OSGi R6 field-based reference bindings
     new bf51720  SLING-5325 osgi-mock: Support target filtering on DS references
     new 5e0ac1d  SLING-5323 no need to update to JDK 1.7, we stick with JDK 1.6.
     new eb580c3  SLING-5327 refactor and unify lifecycle method handling (and fix missing argument variants for modified methods - should support the same as the activate method)
     new db27b68  SLING-5327 osgi-mock: Support OSGi R6 Component propert types for configuration
     new b29a918  SLING-5327 inline the required classes from org.apache.felix.scr
     new 5d2ecfe  SLING-5372 osgi-mock: MockBundleContext.getServices(Class,String) throws NPE when no services found
     new 4e489a6  [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-2.0.0
     new 9c07ff3  [maven-release-plugin] prepare for next development iteration
     new b3f468c  SLING-5391 osgi-mock: Switch to osgi.core and osgi.cmpn dependencies
     new 2efd6e6  Switch to parent pom 26
     new 6759271  SLING-5453 implement MockBundleContext.getDataFile
     new 7d50f99  SLING-5453 implement MockBundleContext.getDataFile
     new c79ef61  SLING-5462 - demonstrate the wrong sorting of mock service references
     new 0e10e45  SLING-5462 ensure service references are sorted ascending by service ranking, not descending
     new fe2625e  SLING-5462 switch to comparable implementation from commons.osgi and change wrong assumptions in unit test
     new 09964b1  [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-2.0.2
     new a8a4072  [maven-release-plugin] prepare for next development iteration
     new 8a090aa  SLING-5544 osgi-mock: Catch RejectedExecutionException in MockEventAdmin
     new 1c6b586  SLING-5667 MockBundleContext.getServiceReference(...) does not return service reference with highest ranking
     new b251609  [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-2.0.4
     new eff1945  [maven-release-plugin] prepare for next development iteration
     new 4f1cc0f  SLING-5871 osgi-mock: Update to org.apache.felix.scr 2.0.4
     new 9e41f2c  SLING-5905 osgi-mock: Shade and relocate Sling and Felix Dependencies
     new 6b59209  cosmetic: fix typo in error message
     new 3171277  SLING-5905 some files from felix.framework where missing includes shaded source attachments
     new 9583f78  SLING-5970 mocks: Update to Parent Pom 28
     new a6a37d7  SLING-5970 switch to osgi annotations
     new c5195c6  add git ignore files for testing projects
     new 8ec500d  SLING-6051 osgi-mock: Support passing map/dictionary properties with object vararg parameter
     new 4dcc5a8  update dependencies
     new 423c717  [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-2.1.0
     new e03a67a  [maven-release-plugin] prepare for next development iteration
     new 65c00bc  update dependencies to latest snapshots until released versions are available in maven central
     new 56f46e7  switch back to released versions
     new 0265add  update to parent 29
     new 3038287  SLING-6356 osgi-mock: Fallback to default when reference field collection type is missing in SCR metadata
     new dea5c88  SLING-6358 osgi-mock: OsgiContext.getServices should return correctly typed array when empty
     new 3f1b5cf  SLING-6359 osgi-mock, sling-mock: Make ContextCallback and ContextBuilder more flexible
     new fbdc5fc  fix javadoc errors
     new 25f3e13  SLING-6359 context plugin support
     new 2843214  SLING-6359 context plugin support
     new e644885  SLING-6362 osgi-mock: ManifestScanner
     new 9ec13c9  [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-2.2.0
     new cdd909d  [maven-release-plugin] copy for tag org.apache.sling.testing.osgi-mock-2.2.0

The 133 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] 02/13: update dependencies to latest snapshots until released versions are available in maven central

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

commit 65c00bc28ec12a0f75915cec3986e8abff1e4383
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Wed Sep 14 22:15:54 2016 +0000

    update dependencies to latest snapshots until released versions are available in maven central
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1760812 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index f65123d..801e3a4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -115,7 +115,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.logging-mock</artifactId>
-            <version>2.0.0</version>
+            <version>2.0.1-SNAPSHOT</version>
             <scope>test</scope>
         </dependency>
 

-- 
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] 10/13: SLING-6359 context plugin 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-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit 284321490c561be244660e0c5bd7a96be39ad6f6
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Sat Dec 3 14:41:13 2016 +0000

    SLING-6359 context plugin support
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1772469 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/testing/mock/osgi/context/ContextPlugins.java  | 15 +++++++++++++++
 .../testing/mock/osgi/context/ContextPluginsTest.java    | 16 ++++++++--------
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugins.java b/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugins.java
index a4ae2dd..503bf92 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugins.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugins.java
@@ -68,6 +68,9 @@ public final class ContextPlugins {
     @SafeVarargs
     public final <T extends OsgiContextImpl> void addPlugin(ContextPlugin<T>... plugin) {
         for (final ContextPlugin<T> item : plugin) {
+            if (item == null) {
+                continue;
+            }
             plugins.add(item);
         }
     }
@@ -80,6 +83,9 @@ public final class ContextPlugins {
     @SafeVarargs
     public final <T extends OsgiContextImpl> void addBeforeSetUpCallback(final ContextCallback<T>... beforeSetUpCallback) {
         for (final ContextCallback<T> item : beforeSetUpCallback) {
+            if (item == null) {
+                continue;
+            }
             plugins.add(new AbstractContextPlugin<T>() {
                 @Override
                 public void beforeSetUp(T context) throws Exception {
@@ -101,6 +107,9 @@ public final class ContextPlugins {
     @SafeVarargs
     public final <T extends OsgiContextImpl> void addAfterSetUpCallback(final ContextCallback<T>... afterSetUpCallback) {
         for (final ContextCallback<T> item : afterSetUpCallback) {
+            if (item == null) {
+                continue;
+            }
             plugins.add(new AbstractContextPlugin<T>() {
                 @Override
                 public void afterSetUp(T context) throws Exception {
@@ -122,6 +131,9 @@ public final class ContextPlugins {
     @SafeVarargs
     public final <T extends OsgiContextImpl> void addBeforeTearDownCallback(final ContextCallback<T>... beforeTearDownCallback) {
         for (final ContextCallback<T> item : beforeTearDownCallback) {
+            if (item == null) {
+                continue;
+            }
             plugins.add(new AbstractContextPlugin<T>() {
                 @Override
                 public void beforeTearDown(T context) throws Exception {
@@ -143,6 +155,9 @@ public final class ContextPlugins {
     @SafeVarargs
     public final <T extends OsgiContextImpl> void addAfterTearDownCallback(final ContextCallback<T>... afterTearDownCallback) {
         for (final ContextCallback<T> item : afterTearDownCallback) {
+            if (item == null) {
+                continue;
+            }
             plugins.add(new AbstractContextPlugin<T>() {
                 @Override
                 public void afterTearDown(T context) throws Exception {
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/context/ContextPluginsTest.java b/src/test/java/org/apache/sling/testing/mock/osgi/context/ContextPluginsTest.java
index c6b5462..cee77f0 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/context/ContextPluginsTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/context/ContextPluginsTest.java
@@ -71,7 +71,7 @@ public class ContextPluginsTest {
     @Test
     public void testExecuteBeforeSetUpCallback() throws Exception {
         ContextPlugins underTest = new ContextPlugins();
-        underTest.addPlugin(plugin1, plugin2);
+        underTest.addPlugin(plugin1, plugin2, null);
         
         assertEquals(2, underTest.getPlugins().size());
         
@@ -85,7 +85,7 @@ public class ContextPluginsTest {
     @Test
     public void testExecuteAfterSetUpCallback() throws Exception {
         ContextPlugins underTest = new ContextPlugins();
-        underTest.addPlugin(plugin1, plugin2);
+        underTest.addPlugin(plugin1, plugin2, null);
         
         assertEquals(2, underTest.getPlugins().size());
         
@@ -99,7 +99,7 @@ public class ContextPluginsTest {
     @Test
     public void testExecuteBeforeTearDownCallback() throws Exception {
         ContextPlugins underTest = new ContextPlugins();
-        underTest.addPlugin(plugin1, plugin2);
+        underTest.addPlugin(plugin1, plugin2, null);
         
         assertEquals(2, underTest.getPlugins().size());
         
@@ -113,7 +113,7 @@ public class ContextPluginsTest {
     @Test
     public void testExecuteAfterTearDownCallback() throws Exception {
         ContextPlugins underTest = new ContextPlugins();
-        underTest.addPlugin(plugin1, plugin2);
+        underTest.addPlugin(plugin1, plugin2, null);
         
         assertEquals(2, underTest.getPlugins().size());
         
@@ -127,7 +127,7 @@ public class ContextPluginsTest {
     @Test
     public void testAddBeforeSetUpCallback() throws Exception {
         ContextPlugins underTest = new ContextPlugins();
-        underTest.addBeforeSetUpCallback(callback1, callback2);
+        underTest.addBeforeSetUpCallback(callback1, callback2, null);
         
         assertEquals(2, underTest.getPlugins().size());
         
@@ -139,7 +139,7 @@ public class ContextPluginsTest {
     @Test
     public void testAddAfterSetUpCallback() throws Exception {
         ContextPlugins underTest = new ContextPlugins();
-        underTest.addAfterSetUpCallback(callback1, callback2);
+        underTest.addAfterSetUpCallback(callback1, callback2, null);
         
         assertEquals(2, underTest.getPlugins().size());
         
@@ -151,7 +151,7 @@ public class ContextPluginsTest {
     @Test
     public void testAddBeforeTearDownCallback() throws Exception {
         ContextPlugins underTest = new ContextPlugins();
-        underTest.addBeforeTearDownCallback(callback1, callback2);
+        underTest.addBeforeTearDownCallback(callback1, callback2, null);
         
         assertEquals(2, underTest.getPlugins().size());
         
@@ -163,7 +163,7 @@ public class ContextPluginsTest {
     @Test
     public void testAddAfterTearDownCallback() throws Exception {
         ContextPlugins underTest = new ContextPlugins();
-        underTest.addAfterTearDownCallback(callback1, callback2);
+        underTest.addAfterTearDownCallback(callback1, callback2, null);
         
         assertEquals(2, underTest.getPlugins().size());
         

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

commit cdd909d51ff06f1fad4d4cfcf8c2a89c09a9a1b3
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Dec 5 17:46:30 2016 +0000

    [maven-release-plugin] copy for tag org.apache.sling.testing.osgi-mock-2.2.0
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.osgi-mock-2.2.0@1772732 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] 05/13: SLING-6356 osgi-mock: Fallback to default when reference field collection type is missing in SCR metadata

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

commit 3038287dba70c81cbf4cff886d4e3792f881bf81
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Dec 2 10:40:45 2016 +0000

    SLING-6356 osgi-mock: Fallback to default when reference field collection type is missing in SCR metadata
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1772326 13f79535-47bb-0310-9956-ffa450edef68
---
 src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java b/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java
index 3d5f3a9..3b6a10d 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java
@@ -524,7 +524,7 @@ final class OsgiMetadataUtil {
                     return item;
                 }
             }
-            return null;
+            return FieldCollectionType.SERVICE;
         }
 
     }

-- 
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] 07/13: SLING-6359 osgi-mock, sling-mock: Make ContextCallback and ContextBuilder more flexible

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

commit 3f1b5cf92a12f834007657dcc7577585647115c0
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Sat Dec 3 10:01:00 2016 +0000

    SLING-6359 osgi-mock, sling-mock: Make ContextCallback and ContextBuilder more flexible
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1772443 13f79535-47bb-0310-9956-ffa450edef68
---
 ...sgiContextCallback.java => CallbackParams.java} | 33 ++++----
 ...giContextCallback.java => ContextCallback.java} | 12 +--
 .../sling/testing/mock/osgi/junit/OsgiContext.java | 87 +++++++++++++-------
 .../mock/osgi/junit/OsgiContextBuilder.java        | 92 ++++++++++++++++++++++
 .../mock/osgi/junit/OsgiContextCallback.java       | 13 +--
 .../testing/mock/osgi/junit/package-info.java      |  2 +-
 .../testing/mock/osgi/junit/OsgiContextTest.java   | 20 +++--
 7 files changed, 194 insertions(+), 65 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java b/src/main/java/org/apache/sling/testing/mock/osgi/junit/CallbackParams.java
similarity index 55%
copy from src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java
copy to src/main/java/org/apache/sling/testing/mock/osgi/junit/CallbackParams.java
index a283f38..a7d69a1 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/junit/CallbackParams.java
@@ -18,19 +18,24 @@
  */
 package org.apache.sling.testing.mock.osgi.junit;
 
-import java.io.IOException;
-
-/**
- * Callback-interface for application-specific setup and teardown operations to
- * customize the {@link OsgiContext} JUnit rule.
- */
-public interface OsgiContextCallback {
-
-    /**
-     * Execute callback action
-     * @param context OSGi context
-     * @throws IOException I/O exception
-     */
-    void execute(OsgiContext context) throws IOException;
+final class CallbackParams {
 
+    ContextCallback[] beforeSetUpCallback;
+    ContextCallback[] afterSetUpCallback;
+    ContextCallback[] beforeTearDownCallback;
+    ContextCallback[] afterTearDownCallback;
+    
+    CallbackParams() {
+        // no callbacks
+    }
+    
+    CallbackParams(ContextCallback afterSetUpCallback) {
+        this.afterSetUpCallback = new ContextCallback[] { afterSetUpCallback }; 
+    }
+    
+    CallbackParams(ContextCallback afterSetUpCallback, ContextCallback beforeTearDownCallback) {
+        this.afterSetUpCallback = new ContextCallback[] { afterSetUpCallback }; 
+        this.beforeTearDownCallback = new ContextCallback[] { beforeTearDownCallback }; 
+    }
+    
 }
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java b/src/main/java/org/apache/sling/testing/mock/osgi/junit/ContextCallback.java
similarity index 77%
copy from src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java
copy to src/main/java/org/apache/sling/testing/mock/osgi/junit/ContextCallback.java
index a283f38..12f0c29 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/junit/ContextCallback.java
@@ -18,19 +18,19 @@
  */
 package org.apache.sling.testing.mock.osgi.junit;
 
-import java.io.IOException;
+import org.apache.sling.testing.mock.osgi.context.OsgiContextImpl;
 
 /**
  * Callback-interface for application-specific setup and teardown operations to
- * customize the {@link OsgiContext} JUnit rule.
+ * customize the {@link SlingContext} JUnit rule.
  */
-public interface OsgiContextCallback {
+public interface ContextCallback<T extends OsgiContextImpl> {
 
     /**
      * Execute callback action
-     * @param context OSGi context
-     * @throws IOException I/O exception
+     * @param context Sling context
+     * @throws Exception exception
      */
-    void execute(OsgiContext context) throws IOException;
+    void execute(T context) throws Exception;
 
 }
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContext.java b/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContext.java
index cd527b1..d64876d 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContext.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContext.java
@@ -29,53 +29,54 @@ import org.junit.runners.model.Statement;
  */
 public final class OsgiContext extends OsgiContextImpl implements TestRule {
 
-    private final OsgiContextCallback setUpCallback;
-    private final OsgiContextCallback tearDownCallback;
+    private final CallbackParams callbackParams;
     private final TestRule delegate;
 
     /**
      * Initialize OSGi context.
      */
     public OsgiContext() {
-        this(null, null);
+        this(new CallbackParams());
     }
 
     /**
      * Initialize OSGi context.
-     * @param setUpCallback Allows the application to register an own callback
-     *            function that is called after the built-in setup rules are
-     *            executed.
+     * @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
      */
-    public OsgiContext(final OsgiContextCallback setUpCallback) {
-        this(setUpCallback, null);
+    public OsgiContext(final ContextCallback afterSetUpCallback) {
+        this(new CallbackParams(afterSetUpCallback));
     }
 
     /**
      * Initialize OSGi context.
-     * @param setUpCallback Allows the application to register an own callback
-     *            function that is called after the built-in setup rules are
-     *            executed.
-     * @param tearDownCallback Allows the application to register an own
-     *            callback function that is called before the built-in teardown
-     *            rules are executed.
+     * @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
+     * @param beforeTearDownCallback Allows the application to register an own callback function that is called before the built-in teardown rules are executed.
      */
-    public OsgiContext(final OsgiContextCallback setUpCallback, final OsgiContextCallback tearDownCallback) {
+    public OsgiContext(final ContextCallback afterSetUpCallback, final ContextCallback beforeTearDownCallback) {
+        this(new CallbackParams(afterSetUpCallback, beforeTearDownCallback));
+    }
 
-        this.setUpCallback = setUpCallback;
-        this.tearDownCallback = tearDownCallback;
+    /**
+     * Initialize OSGi context with resource resolver type.
+     * @param callbackParams Callback parameters
+     */
+    OsgiContext(final CallbackParams callbackParams) {
+        this.callbackParams = callbackParams;
 
         // wrap {@link ExternalResource} rule executes each test method once
         this.delegate = new ExternalResource() {
             @Override
             protected void before() {
+                OsgiContext.this.executeBeforeSetUpCallback();
                 OsgiContext.this.setUp();
-                OsgiContext.this.executeSetUpCallback();
+                OsgiContext.this.executeAfterSetUpCallback();
             }
 
             @Override
             protected void after() {
-                OsgiContext.this.executeTearDownCallback();
+                OsgiContext.this.executeBeforeTearDownCallback();
                 OsgiContext.this.tearDown();
+                OsgiContext.this.executeAfterTearDownCallback();
             }
         };
     }
@@ -85,22 +86,54 @@ public final class OsgiContext extends OsgiContextImpl implements TestRule {
         return this.delegate.apply(base, description);
     }
 
-    private void executeSetUpCallback() {
-        if (this.setUpCallback != null) {
+    @SuppressWarnings("unchecked")
+    private void executeBeforeSetUpCallback() {
+        if (callbackParams.beforeSetUpCallback != null) {
+            try {
+                for (ContextCallback callback : callbackParams.beforeSetUpCallback) {
+                    callback.execute(this);
+                }
+            } catch (Throwable ex) {
+                throw new RuntimeException("Before setup failed: " + ex.getMessage(), ex);
+            }
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private void executeAfterSetUpCallback() {
+        if (callbackParams.afterSetUpCallback != null) {
+            try {
+                for (ContextCallback callback : callbackParams.afterSetUpCallback) {
+                    callback.execute(this);
+                }
+            } catch (Throwable ex) {
+                throw new RuntimeException("After setup failed: " + ex.getMessage(), ex);
+            }
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private void executeBeforeTearDownCallback() {
+        if (callbackParams.beforeTearDownCallback != null) {
             try {
-                this.setUpCallback.execute(this);
+                for (ContextCallback callback : callbackParams.beforeTearDownCallback) {
+                    callback.execute(this);
+                }
             } catch (Throwable ex) {
-                throw new RuntimeException("Setup failed: " + ex.getMessage(), ex);
+                throw new RuntimeException("Before teardown failed: " + ex.getMessage(), ex);
             }
         }
     }
 
-    private void executeTearDownCallback() {
-        if (this.tearDownCallback != null) {
+    @SuppressWarnings("unchecked")
+    private void executeAfterTearDownCallback() {
+        if (callbackParams.afterTearDownCallback != null) {
             try {
-                this.tearDownCallback.execute(this);
+                for (ContextCallback callback : callbackParams.afterTearDownCallback) {
+                    callback.execute(this);
+                }
             } catch (Throwable ex) {
-                throw new RuntimeException("Teardown failed: " + ex.getMessage(), ex);
+                throw new RuntimeException("After teardown failed: " + ex.getMessage(), ex);
             }
         }
     }
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java b/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
new file mode 100644
index 0000000..f6d6305
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
@@ -0,0 +1,92 @@
+/*
+ * 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.junit;
+
+/**
+ * Builder class for creating {@link OsgiContext} instances with different sets of parameters.
+ */
+public final class OsgiContextBuilder {
+    
+    private final CallbackParams callbackParams = new CallbackParams();
+    
+    /**
+     * Create builder with default resource resolver type.
+     */
+    public OsgiContextBuilder() {}
+    
+    /**
+     * @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
+     * @return this
+     */
+    public OsgiContextBuilder setUp(ContextCallback... afterSetUpCallback) {
+        return afterSetUp(afterSetUpCallback);
+    }
+
+    /**
+     * @param beforeSetUpCallback Allows the application to register an own callback function that is called before the built-in setup rules are executed.
+     * @return this
+     */
+    public OsgiContextBuilder beforeSetUp(ContextCallback... beforeSetUpCallback) {
+        callbackParams.beforeSetUpCallback = beforeSetUpCallback;
+        return this;
+    }
+
+    /**
+     * @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
+     * @return this
+     */
+    public OsgiContextBuilder afterSetUp(ContextCallback... afterSetUpCallback) {
+        callbackParams.afterSetUpCallback = afterSetUpCallback;
+        return this;
+    }
+
+    /**
+     * @param beforeTearDownCallback Allows the application to register an own callback function that is called before the built-in teardown rules are executed.
+     * @return this
+     */
+    public OsgiContextBuilder tearDown(ContextCallback... beforeTearDownCallback) {
+        return beforeTearDown(beforeTearDownCallback);
+    }
+
+    /**
+     * @param beforeTearDownCallback Allows the application to register an own callback function that is called before the built-in teardown rules are executed.
+     * @return this
+     */
+    public OsgiContextBuilder beforeTearDown(ContextCallback... beforeTearDownCallback) {
+        callbackParams.beforeTearDownCallback = beforeTearDownCallback;
+        return this;
+    }
+
+    /**
+     * @param afterTearDownCallback Allows the application to register an own callback function that is after before the built-in teardown rules are executed.
+     * @return this
+     */
+    public OsgiContextBuilder afterTearDown(ContextCallback... afterTearDownCallback) {
+        callbackParams.afterTearDownCallback = afterTearDownCallback;
+        return this;
+    }
+
+    /**
+     * @return Build {@link OsgiContext} instance.
+     */
+    public OsgiContext build() {
+        return new OsgiContext(callbackParams);
+    }
+    
+}
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java b/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java
index a283f38..779e86f 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java
@@ -18,19 +18,12 @@
  */
 package org.apache.sling.testing.mock.osgi.junit;
 
-import java.io.IOException;
-
 /**
  * Callback-interface for application-specific setup and teardown operations to
  * customize the {@link OsgiContext} JUnit rule.
  */
-public interface OsgiContextCallback {
-
-    /**
-     * Execute callback action
-     * @param context OSGi context
-     * @throws IOException I/O exception
-     */
-    void execute(OsgiContext context) throws IOException;
+public interface OsgiContextCallback extends ContextCallback<OsgiContext> {
 
+    // specialized version of ContextCallback
+    
 }
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 eeb2980..2295cbc 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.
  */
-@org.osgi.annotation.versioning.Version("1.1")
+@org.osgi.annotation.versioning.Version("2.0")
 package org.apache.sling.testing.mock.osgi.junit;
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextTest.java b/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextTest.java
index 0de149b..840e951 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextTest.java
@@ -22,8 +22,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
-import java.io.IOException;
-
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -33,16 +31,24 @@ import org.mockito.runners.MockitoJUnitRunner;
 @RunWith(MockitoJUnitRunner.class)
 public class OsgiContextTest {
 
-    private final OsgiContextCallback contextSetup = mock(OsgiContextCallback.class);
-    private final OsgiContextCallback contextTeardown = mock(OsgiContextCallback.class);
+    private final OsgiContextCallback contextBeforeSetup = mock(OsgiContextCallback.class);
+    private final OsgiContextCallback contextAfterSetup = mock(OsgiContextCallback.class);
+    private final OsgiContextCallback contextBeforeTeardown = mock(OsgiContextCallback.class);
+    private final OsgiContextCallback contextAfterTeardown = mock(OsgiContextCallback.class);
 
     // Run all unit tests for each resource resolver types listed here
     @Rule
-    public OsgiContext context = new OsgiContext(contextSetup, contextTeardown);
+    public OsgiContext context = new OsgiContextBuilder()
+        .beforeSetUp(contextBeforeSetup)
+        .afterSetUp(contextAfterSetup)
+        .beforeTearDown(contextBeforeTeardown)
+        .afterTearDown(contextAfterTeardown)
+        .build();
 
     @Before
-    public void setUp() throws IOException {
-        verify(contextSetup).execute(context);
+    public void setUp() throws Exception {
+        verify(contextBeforeSetup).execute(context);
+        verify(contextAfterSetup).execute(context);
     }
 
     @Test

-- 
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] 12/13: [maven-release-plugin] prepare release org.apache.sling.testing.osgi-mock-2.2.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-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit 9ec13c91757cf736910d0c6d5c2be9581a390b02
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Dec 5 17:46:17 2016 +0000

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

diff --git a/pom.xml b/pom.xml
index e8522aa..63358a2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,16 +28,16 @@
     </parent>
 
     <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
-    <version>2.1.1-SNAPSHOT</version>
+    <version>2.2.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-2.2.0</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.osgi-mock-2.2.0</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.testing.osgi-mock-2.2.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] 08/13: fix javadoc errors

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

commit fbdc5fc60cc475cb3ef451e585661418d87fa7fe
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Sat Dec 3 10:59:28 2016 +0000

    fix javadoc errors
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1772454 13f79535-47bb-0310-9956-ffa450edef68
---
 src/main/java/org/apache/sling/testing/mock/osgi/MapUtil.java         | 4 ++++
 .../org/apache/sling/testing/mock/osgi/junit/ContextCallback.java     | 4 ++--
 2 files changed, 6 insertions(+), 2 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 c596fed..11891a0 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
@@ -37,6 +37,8 @@ public final class MapUtil {
 
     /**
      * Convert map to dictionary.
+     * @param <T> Key
+     * @param <U> Value
      * @param map Map
      * @return Dictionary
      */
@@ -49,6 +51,8 @@ public final class MapUtil {
 
     /**
      * Convert Dictionary to map
+     * @param <T> Key
+     * @param <U> Value
      * @param dictionary Dictionary
      * @return Map
      */
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/ContextCallback.java b/src/main/java/org/apache/sling/testing/mock/osgi/junit/ContextCallback.java
index 12f0c29..fee823e 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/junit/ContextCallback.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/junit/ContextCallback.java
@@ -22,13 +22,13 @@ import org.apache.sling.testing.mock.osgi.context.OsgiContextImpl;
 
 /**
  * Callback-interface for application-specific setup and teardown operations to
- * customize the {@link SlingContext} JUnit rule.
+ * customize the {@link OsgiContext} JUnit rule.
  */
 public interface ContextCallback<T extends OsgiContextImpl> {
 
     /**
      * Execute callback action
-     * @param context Sling context
+     * @param context OSGi context
      * @throws Exception exception
      */
     void execute(T context) throws Exception;

-- 
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/13: switch back to released versions

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

commit 56f46e7461c3968ea1b65d01385d0038d6abbaa6
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Sep 19 09:26:36 2016 +0000

    switch back to released versions
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1761405 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 801e3a4..f65123d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -115,7 +115,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.logging-mock</artifactId>
-            <version>2.0.1-SNAPSHOT</version>
+            <version>2.0.0</version>
             <scope>test</scope>
         </dependency>
 

-- 
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/13: update to parent 29

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

commit 0265add7601307415b96865e4037d5f1f6fd15f8
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Tue Nov 1 20:41:46 2016 +0000

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

diff --git a/pom.xml b/pom.xml
index f65123d..e8522aa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>28</version>
+        <version>29</version>
         <relativePath />
     </parent>
 

-- 
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] 09/13: SLING-6359 context plugin 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-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit 25f3e13ba98f7e2ca6ae84380fec67857461eb07
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Sat Dec 3 13:14:34 2016 +0000

    SLING-6359 context plugin support
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1772466 13f79535-47bb-0310-9956-ffa450edef68
---
 .../AbstractContextPlugin.java}                    |  41 ++--
 .../osgi/{junit => context}/ContextCallback.java   |  10 +-
 .../testing/mock/osgi/context/ContextPlugin.java   |  59 ++++++
 .../testing/mock/osgi/context/ContextPlugins.java  | 234 +++++++++++++++++++++
 .../testing/mock/osgi/context/package-info.java    |   2 +-
 .../sling/testing/mock/osgi/junit/OsgiContext.java |  85 ++------
 .../mock/osgi/junit/OsgiContextBuilder.java        |  52 +++--
 .../mock/osgi/junit/OsgiContextCallback.java       |   6 +-
 .../mock/osgi/context/ContextPluginsTest.java      | 175 +++++++++++++++
 9 files changed, 556 insertions(+), 108 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/CallbackParams.java b/src/main/java/org/apache/sling/testing/mock/osgi/context/AbstractContextPlugin.java
similarity index 51%
rename from src/main/java/org/apache/sling/testing/mock/osgi/junit/CallbackParams.java
rename to src/main/java/org/apache/sling/testing/mock/osgi/context/AbstractContextPlugin.java
index a7d69a1..5d71c9c 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/junit/CallbackParams.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/context/AbstractContextPlugin.java
@@ -16,26 +16,35 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.testing.mock.osgi.junit;
+package org.apache.sling.testing.mock.osgi.context;
 
-final class CallbackParams {
+import org.osgi.annotation.versioning.ConsumerType;
 
-    ContextCallback[] beforeSetUpCallback;
-    ContextCallback[] afterSetUpCallback;
-    ContextCallback[] beforeTearDownCallback;
-    ContextCallback[] afterTearDownCallback;
-    
-    CallbackParams() {
-        // no callbacks
+/**
+ * Default implementation of {@link ContextPlugin}.
+ * @param <T> Context
+ */
+@ConsumerType
+public abstract class AbstractContextPlugin<T extends OsgiContextImpl> implements ContextPlugin<T> {
+
+    @Override
+    public void beforeSetUp(T context) throws Exception {
+        // can be overridden by subclasses
     }
-    
-    CallbackParams(ContextCallback afterSetUpCallback) {
-        this.afterSetUpCallback = new ContextCallback[] { afterSetUpCallback }; 
+
+    @Override
+    public void afterSetUp(T context) throws Exception {
+        // can be overridden by subclasses
     }
-    
-    CallbackParams(ContextCallback afterSetUpCallback, ContextCallback beforeTearDownCallback) {
-        this.afterSetUpCallback = new ContextCallback[] { afterSetUpCallback }; 
-        this.beforeTearDownCallback = new ContextCallback[] { beforeTearDownCallback }; 
+
+    @Override
+    public void beforeTearDown(T context) throws Exception {
+        // can be overridden by subclasses
+    }
+
+    @Override
+    public void afterTearDown(T context) throws Exception {
+        // can be overridden by subclasses
     }
     
 }
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/ContextCallback.java b/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextCallback.java
similarity index 81%
rename from src/main/java/org/apache/sling/testing/mock/osgi/junit/ContextCallback.java
rename to src/main/java/org/apache/sling/testing/mock/osgi/context/ContextCallback.java
index fee823e..aa2ed12 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/junit/ContextCallback.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextCallback.java
@@ -16,14 +16,16 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.testing.mock.osgi.junit;
+package org.apache.sling.testing.mock.osgi.context;
 
-import org.apache.sling.testing.mock.osgi.context.OsgiContextImpl;
+import org.osgi.annotation.versioning.ConsumerType;
 
 /**
- * Callback-interface for application-specific setup and teardown operations to
- * customize the {@link OsgiContext} JUnit rule.
+ * Callback interface for application-specific setup and teardown operations to
+ * customize the mock context.
+ * @param <T> Context
  */
+@ConsumerType
 public interface ContextCallback<T extends OsgiContextImpl> {
 
     /**
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugin.java b/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugin.java
new file mode 100644
index 0000000..4fe3616
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugin.java
@@ -0,0 +1,59 @@
+/*
+ * 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.context;
+
+import org.osgi.annotation.versioning.ConsumerType;
+
+/**
+ * Callback plugin for application-specific setup and teardown operations to
+ * customize the mock context.
+ * @param <T> Context
+ */
+@ConsumerType
+public interface ContextPlugin<T extends OsgiContextImpl> {
+
+    /**
+     * Is executed before the built-in setup rules are executed.
+     * @param context OSGi context
+     * @throws Exception exception
+     */
+    void beforeSetUp(T context) throws Exception;
+
+    /**
+     * Is executed after the built-in setup rules are executed.
+     * @param context OSGi context
+     * @throws Exception exception
+     */
+    void afterSetUp(T context) throws Exception;
+
+    /**
+     * Is executed before the built-in teardown rules are executed.
+     * @param context OSGi context
+     * @throws Exception exception
+     */
+    void beforeTearDown(T context) throws Exception;
+
+    /**
+     * Is executed after the built-in teardown rules are executed.
+     * @param context OSGi context
+     * @throws Exception exception
+     */
+    void afterTearDown(T context) throws Exception;
+
+}
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugins.java b/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugins.java
new file mode 100644
index 0000000..a4ae2dd
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugins.java
@@ -0,0 +1,234 @@
+/*
+ * 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.context;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.osgi.annotation.versioning.ProviderType;
+
+/**
+ * Collects list of context plugins.
+ */
+@ProviderType
+public final class ContextPlugins {
+    
+    private List<ContextPlugin<? extends OsgiContextImpl>> plugins = new ArrayList<>();
+
+    /**
+     * Start with empty list.
+     */
+    public ContextPlugins() {
+        // empty list
+    }
+    
+    /**
+     * Start with some callbacks.
+     * @param <T> context type
+     * @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
+     */
+    public <T extends OsgiContextImpl> ContextPlugins(final ContextCallback<T> afterSetUpCallback) {
+        addAfterSetUpCallback(afterSetUpCallback);
+    }
+    
+    /**
+     * Start with some callbacks.
+     * @param <U> context type
+     * @param <V> context type
+     * @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
+     * @param beforeTearDownCallback Allows the application to register an own callback function that is called before the built-in teardown rules are executed.
+     */
+    public <U extends OsgiContextImpl, V extends OsgiContextImpl> ContextPlugins(final ContextCallback<U> afterSetUpCallback, final ContextCallback<V> beforeTearDownCallback) {
+        addAfterSetUpCallback(afterSetUpCallback);
+        addBeforeTearDownCallback(beforeTearDownCallback);
+    }
+    
+    /**
+     * Add plugin
+     * @param <T> context type
+     * @param plugin Plugin
+     */
+    @SafeVarargs
+    public final <T extends OsgiContextImpl> void addPlugin(ContextPlugin<T>... plugin) {
+        for (final ContextPlugin<T> item : plugin) {
+            plugins.add(item);
+        }
+    }
+    
+    /**
+     * Add callback
+     * @param <T> context type
+     * @param beforeSetUpCallback Allows the application to register an own callback function that is called before the built-in setup rules are executed.
+     */
+    @SafeVarargs
+    public final <T extends OsgiContextImpl> void addBeforeSetUpCallback(final ContextCallback<T>... beforeSetUpCallback) {
+        for (final ContextCallback<T> item : beforeSetUpCallback) {
+            plugins.add(new AbstractContextPlugin<T>() {
+                @Override
+                public void beforeSetUp(T context) throws Exception {
+                    item.execute(context);
+                }
+                @Override
+                public String toString() {
+                    return item.toString();
+                }
+            });
+        }
+    }
+    
+    /**
+     * Add callback
+     * @param <T> context type
+     * @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
+     */
+    @SafeVarargs
+    public final <T extends OsgiContextImpl> void addAfterSetUpCallback(final ContextCallback<T>... afterSetUpCallback) {
+        for (final ContextCallback<T> item : afterSetUpCallback) {
+            plugins.add(new AbstractContextPlugin<T>() {
+                @Override
+                public void afterSetUp(T context) throws Exception {
+                    item.execute(context);
+                }
+                @Override
+                public String toString() {
+                    return item.toString();
+                }
+            });
+        }
+    }
+    
+    /**
+     * Add callback
+     * @param <T> context type
+     * @param beforeTearDownCallback Allows the application to register an own callback function that is called before the built-in teardown rules are executed.
+     */
+    @SafeVarargs
+    public final <T extends OsgiContextImpl> void addBeforeTearDownCallback(final ContextCallback<T>... beforeTearDownCallback) {
+        for (final ContextCallback<T> item : beforeTearDownCallback) {
+            plugins.add(new AbstractContextPlugin<T>() {
+                @Override
+                public void beforeTearDown(T context) throws Exception {
+                    item.execute(context);
+                }
+                @Override
+                public String toString() {
+                    return item.toString();
+                }
+            });
+        }
+    }
+    
+    /**
+     * Add callback
+     * @param <T> context type
+     * @param afterTearDownCallback Allows the application to register an own callback function that is after before the built-in teardown rules are executed.
+     */
+    @SafeVarargs
+    public final <T extends OsgiContextImpl> void addAfterTearDownCallback(final ContextCallback<T>... afterTearDownCallback) {
+        for (final ContextCallback<T> item : afterTearDownCallback) {
+            plugins.add(new AbstractContextPlugin<T>() {
+                @Override
+                public void afterTearDown(T context) throws Exception {
+                    item.execute(context);
+                }
+                @Override
+                public String toString() {
+                    return item.toString();
+                }
+            });
+        }
+    }
+    
+    /**
+     * @return All plugins
+     */
+    public Collection<ContextPlugin<? extends OsgiContextImpl>> getPlugins() {
+        return plugins;
+    }
+    
+    /**
+     * Execute all before setup callbacks.
+     * @param <T> context type
+     * @param context Context
+     */
+    @SuppressWarnings("unchecked")
+    public <T extends OsgiContextImpl> void executeBeforeSetUpCallback(final T context) {
+        for (ContextPlugin plugin : plugins) {
+            try {
+                plugin.beforeSetUp(context);
+            }
+            catch (Throwable ex) {
+                throw new RuntimeException("Before setup failed (" + plugin.toString() + "): " + ex.getMessage(), ex);
+            }
+        }
+    }
+
+    /**
+     * Execute all after setup callbacks.
+     * @param <T> context type
+     * @param context Context
+     */
+    @SuppressWarnings("unchecked")
+    public <T extends OsgiContextImpl> void executeAfterSetUpCallback(final T context) {
+        for (ContextPlugin plugin : plugins) {
+            try {
+                plugin.afterSetUp(context);
+            }
+            catch (Throwable ex) {
+                throw new RuntimeException("After setup failed (" + plugin.toString() + "): " + ex.getMessage(), ex);
+            }
+        }
+    }
+
+    /**
+     * Execute all before teardown callbacks.
+     * @param <T> context type
+     * @param context Context
+     */
+    @SuppressWarnings("unchecked")
+    public <T extends OsgiContextImpl> void executeBeforeTearDownCallback(final T context) {
+        for (ContextPlugin plugin : plugins) {
+            try {
+                plugin.beforeTearDown(context);
+            }
+            catch (Throwable ex) {
+                throw new RuntimeException("Before teardown failed (" + plugin.toString() + "): " + ex.getMessage(), ex);
+            }
+        }
+    }
+
+    /**
+     * Execute all after teardown callbacks.
+     * @param <T> context type
+     * @param context Context
+     */
+    @SuppressWarnings("unchecked")
+    public <T extends OsgiContextImpl> void executeAfterTearDownCallback(final T context) {
+        for (ContextPlugin plugin : plugins) {
+            try {
+                plugin.afterTearDown(context);
+            }
+            catch (Throwable ex) {
+                throw new RuntimeException("After teardown failed (" + plugin.toString() + "): " + ex.getMessage(), ex);
+            }
+        }
+    }
+
+}
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 c54910f..6e57ffd 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.
  */
-@org.osgi.annotation.versioning.Version("1.1")
+@org.osgi.annotation.versioning.Version("1.2")
 package org.apache.sling.testing.mock.osgi.context;
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContext.java b/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContext.java
index d64876d..77e8ad5 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContext.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContext.java
@@ -18,65 +18,72 @@
  */
 package org.apache.sling.testing.mock.osgi.junit;
 
+import org.apache.sling.testing.mock.osgi.context.ContextCallback;
+import org.apache.sling.testing.mock.osgi.context.ContextPlugins;
 import org.apache.sling.testing.mock.osgi.context.OsgiContextImpl;
 import org.junit.rules.ExternalResource;
 import org.junit.rules.TestRule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
+import org.osgi.annotation.versioning.ProviderType;
 
 /**
  * JUnit rule for setting up and tearing down OSGi context for unit tests.
  */
+@ProviderType
 public final class OsgiContext extends OsgiContextImpl implements TestRule {
 
-    private final CallbackParams callbackParams;
+    private final ContextPlugins plugins;
     private final TestRule delegate;
 
     /**
      * Initialize OSGi context.
      */
     public OsgiContext() {
-        this(new CallbackParams());
+        this(new ContextPlugins());
     }
 
     /**
      * Initialize OSGi context.
+     * @param <T> context type
      * @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
      */
-    public OsgiContext(final ContextCallback afterSetUpCallback) {
-        this(new CallbackParams(afterSetUpCallback));
+    public <T extends OsgiContextImpl> OsgiContext(final ContextCallback<T> afterSetUpCallback) {
+        this(new ContextPlugins(afterSetUpCallback));
     }
 
     /**
      * Initialize OSGi context.
+     * @param <U> context type
+     * @param <V> context type
      * @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
      * @param beforeTearDownCallback Allows the application to register an own callback function that is called before the built-in teardown rules are executed.
      */
-    public OsgiContext(final ContextCallback afterSetUpCallback, final ContextCallback beforeTearDownCallback) {
-        this(new CallbackParams(afterSetUpCallback, beforeTearDownCallback));
+    public <U extends OsgiContextImpl, V extends OsgiContextImpl> OsgiContext(final ContextCallback<U> afterSetUpCallback, final ContextCallback<V> beforeTearDownCallback) {
+        this(new ContextPlugins(afterSetUpCallback, beforeTearDownCallback));
     }
 
     /**
      * Initialize OSGi context with resource resolver type.
-     * @param callbackParams Callback parameters
+     * @param contextPlugins Context plugins
      */
-    OsgiContext(final CallbackParams callbackParams) {
-        this.callbackParams = callbackParams;
+    OsgiContext(final ContextPlugins contextPlugins) {
+        this.plugins = contextPlugins;
 
         // wrap {@link ExternalResource} rule executes each test method once
         this.delegate = new ExternalResource() {
             @Override
             protected void before() {
-                OsgiContext.this.executeBeforeSetUpCallback();
+                plugins.executeBeforeSetUpCallback(OsgiContext.this);
                 OsgiContext.this.setUp();
-                OsgiContext.this.executeAfterSetUpCallback();
+                plugins.executeAfterSetUpCallback(OsgiContext.this);
             }
 
             @Override
             protected void after() {
-                OsgiContext.this.executeBeforeTearDownCallback();
+                plugins.executeBeforeTearDownCallback(OsgiContext.this);
                 OsgiContext.this.tearDown();
-                OsgiContext.this.executeAfterTearDownCallback();
+                plugins.executeAfterTearDownCallback(OsgiContext.this);
             }
         };
     }
@@ -86,56 +93,4 @@ public final class OsgiContext extends OsgiContextImpl implements TestRule {
         return this.delegate.apply(base, description);
     }
 
-    @SuppressWarnings("unchecked")
-    private void executeBeforeSetUpCallback() {
-        if (callbackParams.beforeSetUpCallback != null) {
-            try {
-                for (ContextCallback callback : callbackParams.beforeSetUpCallback) {
-                    callback.execute(this);
-                }
-            } catch (Throwable ex) {
-                throw new RuntimeException("Before setup failed: " + ex.getMessage(), ex);
-            }
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    private void executeAfterSetUpCallback() {
-        if (callbackParams.afterSetUpCallback != null) {
-            try {
-                for (ContextCallback callback : callbackParams.afterSetUpCallback) {
-                    callback.execute(this);
-                }
-            } catch (Throwable ex) {
-                throw new RuntimeException("After setup failed: " + ex.getMessage(), ex);
-            }
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    private void executeBeforeTearDownCallback() {
-        if (callbackParams.beforeTearDownCallback != null) {
-            try {
-                for (ContextCallback callback : callbackParams.beforeTearDownCallback) {
-                    callback.execute(this);
-                }
-            } catch (Throwable ex) {
-                throw new RuntimeException("Before teardown failed: " + ex.getMessage(), ex);
-            }
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    private void executeAfterTearDownCallback() {
-        if (callbackParams.afterTearDownCallback != null) {
-            try {
-                for (ContextCallback callback : callbackParams.afterTearDownCallback) {
-                    callback.execute(this);
-                }
-            } catch (Throwable ex) {
-                throw new RuntimeException("After teardown failed: " + ex.getMessage(), ex);
-            }
-        }
-    }
-
 }
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java b/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
index f6d6305..9207e40 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
@@ -18,12 +18,19 @@
  */
 package org.apache.sling.testing.mock.osgi.junit;
 
+import org.apache.sling.testing.mock.osgi.context.ContextPlugins;
+import org.apache.sling.testing.mock.osgi.context.OsgiContextImpl;
+import org.apache.sling.testing.mock.osgi.context.ContextCallback;
+import org.apache.sling.testing.mock.osgi.context.ContextPlugin;
+import org.osgi.annotation.versioning.ProviderType;
+
 /**
  * Builder class for creating {@link OsgiContext} instances with different sets of parameters.
  */
+@ProviderType
 public final class OsgiContextBuilder {
     
-    private final CallbackParams callbackParams = new CallbackParams();
+    private final ContextPlugins plugins = new ContextPlugins();
     
     /**
      * Create builder with default resource resolver type.
@@ -31,54 +38,57 @@ public final class OsgiContextBuilder {
     public OsgiContextBuilder() {}
     
     /**
-     * @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
+     * @param <T> context type
+     * @param plugin Context plugin which listens to context lifecycle events.
      * @return this
      */
-    public OsgiContextBuilder setUp(ContextCallback... afterSetUpCallback) {
-        return afterSetUp(afterSetUpCallback);
+    @SafeVarargs
+    public final <T extends OsgiContextImpl> OsgiContextBuilder plugin(ContextPlugin<T>... plugin) {
+        plugins.addPlugin(plugin);
+        return this;
     }
 
     /**
+     * @param <T> context type
      * @param beforeSetUpCallback Allows the application to register an own callback function that is called before the built-in setup rules are executed.
      * @return this
      */
-    public OsgiContextBuilder beforeSetUp(ContextCallback... beforeSetUpCallback) {
-        callbackParams.beforeSetUpCallback = beforeSetUpCallback;
+    @SafeVarargs
+    public final <T extends OsgiContextImpl> OsgiContextBuilder beforeSetUp(ContextCallback<T>... beforeSetUpCallback) {
+        plugins.addBeforeSetUpCallback(beforeSetUpCallback);
         return this;
     }
 
     /**
+     * @param <T> context type
      * @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
      * @return this
      */
-    public OsgiContextBuilder afterSetUp(ContextCallback... afterSetUpCallback) {
-        callbackParams.afterSetUpCallback = afterSetUpCallback;
+    @SafeVarargs
+    public final <T extends OsgiContextImpl> OsgiContextBuilder afterSetUp(ContextCallback<T>... afterSetUpCallback) {
+        plugins.addAfterSetUpCallback(afterSetUpCallback);
         return this;
     }
 
     /**
+     * @param <T> context type
      * @param beforeTearDownCallback Allows the application to register an own callback function that is called before the built-in teardown rules are executed.
      * @return this
      */
-    public OsgiContextBuilder tearDown(ContextCallback... beforeTearDownCallback) {
-        return beforeTearDown(beforeTearDownCallback);
-    }
-
-    /**
-     * @param beforeTearDownCallback Allows the application to register an own callback function that is called before the built-in teardown rules are executed.
-     * @return this
-     */
-    public OsgiContextBuilder beforeTearDown(ContextCallback... beforeTearDownCallback) {
-        callbackParams.beforeTearDownCallback = beforeTearDownCallback;
+    @SafeVarargs
+    public final <T extends OsgiContextImpl> OsgiContextBuilder beforeTearDown(ContextCallback<T>... beforeTearDownCallback) {
+        plugins.addBeforeTearDownCallback(beforeTearDownCallback);
         return this;
     }
 
     /**
+     * @param <T> context type
      * @param afterTearDownCallback Allows the application to register an own callback function that is after before the built-in teardown rules are executed.
      * @return this
      */
-    public OsgiContextBuilder afterTearDown(ContextCallback... afterTearDownCallback) {
-        callbackParams.afterTearDownCallback = afterTearDownCallback;
+    @SafeVarargs
+    public final <T extends OsgiContextImpl> OsgiContextBuilder afterTearDown(ContextCallback<T>... afterTearDownCallback) {
+        plugins.addAfterTearDownCallback(afterTearDownCallback);
         return this;
     }
 
@@ -86,7 +96,7 @@ public final class OsgiContextBuilder {
      * @return Build {@link OsgiContext} instance.
      */
     public OsgiContext build() {
-        return new OsgiContext(callbackParams);
+        return new OsgiContext(plugins);
     }
     
 }
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java b/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java
index 779e86f..710b65d 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java
@@ -18,10 +18,14 @@
  */
 package org.apache.sling.testing.mock.osgi.junit;
 
+import org.apache.sling.testing.mock.osgi.context.ContextCallback;
+import org.osgi.annotation.versioning.ConsumerType;
+
 /**
- * Callback-interface for application-specific setup and teardown operations to
+ * Callback interface for application-specific setup and teardown operations to
  * customize the {@link OsgiContext} JUnit rule.
  */
+@ConsumerType
 public interface OsgiContextCallback extends ContextCallback<OsgiContext> {
 
     // specialized version of ContextCallback
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/context/ContextPluginsTest.java b/src/test/java/org/apache/sling/testing/mock/osgi/context/ContextPluginsTest.java
new file mode 100644
index 0000000..c6b5462
--- /dev/null
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/context/ContextPluginsTest.java
@@ -0,0 +1,175 @@
+/*
+ * 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.context;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
+import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+@SuppressWarnings("unchecked")
+public class ContextPluginsTest {
+    
+    private OsgiContext context = new OsgiContext();
+
+    @Mock
+    private ContextPlugin plugin1;
+    @Mock
+    private ContextPlugin plugin2;
+    @Mock
+    private ContextCallback callback1;
+    @Mock
+    private ContextCallback callback2;
+    
+    @Test
+    public void testConstructorSetUp() throws Exception {
+        ContextPlugins underTest = new ContextPlugins(callback1);
+        
+        assertEquals(1, underTest.getPlugins().size());
+        
+        underTest.executeAfterSetUpCallback(context);
+        
+        verify(callback1, times(1)).execute(context);
+    }
+
+    @Test
+    public void testConstructorSetUpTearDown() throws Exception {
+        ContextPlugins underTest = new ContextPlugins(callback1, callback2);
+        
+        assertEquals(2, underTest.getPlugins().size());
+        
+        underTest.executeAfterSetUpCallback(context);
+        underTest.executeBeforeTearDownCallback(context);
+
+        verify(callback1, times(1)).execute(context);
+        verify(callback2, times(1)).execute(context);
+    }
+
+    @Test
+    public void testExecuteBeforeSetUpCallback() throws Exception {
+        ContextPlugins underTest = new ContextPlugins();
+        underTest.addPlugin(plugin1, plugin2);
+        
+        assertEquals(2, underTest.getPlugins().size());
+        
+        underTest.executeBeforeSetUpCallback(context);
+        verify(plugin1, times(1)).beforeSetUp(context);
+        verify(plugin2, times(1)).beforeSetUp(context);
+        verifyNoMoreInteractions(plugin1);
+        verifyNoMoreInteractions(plugin2);
+    }
+
+    @Test
+    public void testExecuteAfterSetUpCallback() throws Exception {
+        ContextPlugins underTest = new ContextPlugins();
+        underTest.addPlugin(plugin1, plugin2);
+        
+        assertEquals(2, underTest.getPlugins().size());
+        
+        underTest.executeAfterSetUpCallback(context);
+        verify(plugin1, times(1)).afterSetUp(context);
+        verify(plugin2, times(1)).afterSetUp(context);
+        verifyNoMoreInteractions(plugin1);
+        verifyNoMoreInteractions(plugin2);
+    }
+
+    @Test
+    public void testExecuteBeforeTearDownCallback() throws Exception {
+        ContextPlugins underTest = new ContextPlugins();
+        underTest.addPlugin(plugin1, plugin2);
+        
+        assertEquals(2, underTest.getPlugins().size());
+        
+        underTest.executeBeforeTearDownCallback(context);
+        verify(plugin1, times(1)).beforeTearDown(context);
+        verify(plugin2, times(1)).beforeTearDown(context);
+        verifyNoMoreInteractions(plugin1);
+        verifyNoMoreInteractions(plugin2);
+    }
+
+    @Test
+    public void testExecuteAfterTearDownCallback() throws Exception {
+        ContextPlugins underTest = new ContextPlugins();
+        underTest.addPlugin(plugin1, plugin2);
+        
+        assertEquals(2, underTest.getPlugins().size());
+        
+        underTest.executeAfterTearDownCallback(context);
+        verify(plugin1, times(1)).afterTearDown(context);
+        verify(plugin2, times(1)).afterTearDown(context);
+        verifyNoMoreInteractions(plugin1);
+        verifyNoMoreInteractions(plugin2);
+    }
+
+    @Test
+    public void testAddBeforeSetUpCallback() throws Exception {
+        ContextPlugins underTest = new ContextPlugins();
+        underTest.addBeforeSetUpCallback(callback1, callback2);
+        
+        assertEquals(2, underTest.getPlugins().size());
+        
+        underTest.executeBeforeSetUpCallback(context);
+        verify(callback1, times(1)).execute(context);
+        verify(callback2, times(1)).execute(context);
+    }
+
+    @Test
+    public void testAddAfterSetUpCallback() throws Exception {
+        ContextPlugins underTest = new ContextPlugins();
+        underTest.addAfterSetUpCallback(callback1, callback2);
+        
+        assertEquals(2, underTest.getPlugins().size());
+        
+        underTest.executeAfterSetUpCallback(context);
+        verify(callback1, times(1)).execute(context);
+        verify(callback2, times(1)).execute(context);
+    }
+
+    @Test
+    public void testAddBeforeTearDownCallback() throws Exception {
+        ContextPlugins underTest = new ContextPlugins();
+        underTest.addBeforeTearDownCallback(callback1, callback2);
+        
+        assertEquals(2, underTest.getPlugins().size());
+        
+        underTest.executeBeforeTearDownCallback(context);
+        verify(callback1, times(1)).execute(context);
+        verify(callback2, times(1)).execute(context);
+    }
+
+    @Test
+    public void testAddAfterTearDownCallback() throws Exception {
+        ContextPlugins underTest = new ContextPlugins();
+        underTest.addAfterTearDownCallback(callback1, callback2);
+        
+        assertEquals(2, underTest.getPlugins().size());
+        
+        underTest.executeAfterTearDownCallback(context);
+        verify(callback1, times(1)).execute(context);
+        verify(callback2, times(1)).execute(context);
+    }
+
+}

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

commit e03a67a9114ffb5bf17c6326526b8a87be08037e
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Wed Sep 14 21:27:49 2016 +0000

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

diff --git a/pom.xml b/pom.xml
index 96d9b89..f65123d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,16 +28,16 @@
     </parent>
 
     <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
-    <version>2.1.0</version>
+    <version>2.1.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-2.1.0</connection>
-        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.osgi-mock-2.1.0</developerConnection>
-        <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.testing.osgi-mock-2.1.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] 11/13: SLING-6362 osgi-mock: ManifestScanner

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

commit e6448851a31f63aed86cec887850c2bea2167010
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Sun Dec 4 07:22:34 2016 +0000

    SLING-6362 osgi-mock: ManifestScanner
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1772506 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/testing/mock/osgi/ManifestScanner.java   | 93 ++++++++++++++++++++++
 .../sling/testing/mock/osgi/package-info.java      |  2 +-
 .../testing/mock/osgi/ManifestScannerTest.java}    | 28 ++++++-
 3 files changed, 118 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/ManifestScanner.java b/src/main/java/org/apache/sling/testing/mock/osgi/ManifestScanner.java
new file mode 100644
index 0000000..2058e71
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/ManifestScanner.java
@@ -0,0 +1,93 @@
+/*
+ * 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.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Scan METAINF/MANIFEST.MF files.
+ */
+public final class ManifestScanner {
+    
+    private static final Logger log = LoggerFactory.getLogger(ManifestScanner.class);
+    
+    private ManifestScanner() {
+        // static methods only
+    }
+
+    /**
+     * Get all bundle header values stored in MANIFEST.MF files as attributes.
+     * Attributes values from all manifest files are collected, and values separated by "," are returned individually.
+     * The order of the values from each entry is preserved, but the overall order when multiple bundles define such an entry
+     * is not deterministic. Duplicate values are eliminated.
+     * @param attributeName Attribute / Bundle header name.
+     * @return List of values.
+     */
+    public static Collection<String> getValues(final String attributeName) {
+        Set<String> values = new LinkedHashSet<String>();
+        try {
+            Enumeration<URL> resEnum = ManifestScanner.class.getClassLoader().getResources(JarFile.MANIFEST_NAME);
+            while (resEnum.hasMoreElements()) {
+                try {
+                    URL url = (URL)resEnum.nextElement();
+                    InputStream is = url.openStream();
+                    if (is != null) {
+                        try {
+                            Manifest manifest = new Manifest(is);
+                            Attributes mainAttribs = manifest.getMainAttributes();
+                            String valueList = mainAttribs.getValue(attributeName);
+                            String[] valueArray = StringUtils.split(valueList, ",");
+                            if (valueArray != null) {
+                                for (String value : valueArray) {
+                                    if (!StringUtils.isBlank(value)) {
+                                        values.add(StringUtils.trim(value));
+                                    }
+                                }
+                            }
+                        }
+                        finally {
+                            is.close();
+                        }
+                    }
+                }
+                catch (Throwable ex) {
+                    log.warn("Unable to read JAR manifest.", ex);
+                }
+            }
+        }
+        catch (IOException ex) {
+            log.warn("Unable to read JAR manifests.", ex);
+        }
+        return values; 
+    }
+
+}
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 b0f0eaf..94cd4bc 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.
  */
-@org.osgi.annotation.versioning.Version("3.1")
+@org.osgi.annotation.versioning.Version("3.2")
 package org.apache.sling.testing.mock.osgi;
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java b/src/test/java/org/apache/sling/testing/mock/osgi/ManifestScannerTest.java
similarity index 53%
copy from src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
copy to src/test/java/org/apache/sling/testing/mock/osgi/ManifestScannerTest.java
index b0f0eaf..8a536c5 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/ManifestScannerTest.java
@@ -16,8 +16,28 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/**
- * Mock implementation of selected OSGi APIs.
- */
-@org.osgi.annotation.versioning.Version("3.1")
 package org.apache.sling.testing.mock.osgi;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+
+import org.junit.Test;
+import org.osgi.framework.Constants;
+
+public class ManifestScannerTest {
+
+    /**
+     * Test some MANIFEST entries from commons-io:commons-io:2.4
+     */
+    @Test
+    public void testGetValues() {
+        Collection<String> bundleSymbolicNames = ManifestScanner.getValues(Constants.BUNDLE_SYMBOLICNAME);
+        assertTrue(bundleSymbolicNames.contains("org.apache.commons.io"));
+
+        Collection<String> includeResource = ManifestScanner.getValues("Include-Resource");
+        assertTrue(includeResource.contains("META-INF/LICENSE.txt=LICENSE.txt"));
+        assertTrue(includeResource.contains("META-INF/NOTICE.txt=NOTICE.txt"));
+    }
+
+}

-- 
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/13: SLING-6358 osgi-mock: OsgiContext.getServices should return correctly typed array when empty

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

commit dea5c88d556353670c91c8dff9a440038c3a8671
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Dec 2 16:55:16 2016 +0000

    SLING-6358 osgi-mock: OsgiContext.getServices should return correctly typed array when empty
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1772373 13f79535-47bb-0310-9956-ffa450edef68
---
 .../org/apache/sling/testing/mock/osgi/context/OsgiContextImpl.java | 3 +--
 .../apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java | 6 +++++-
 2 files changed, 6 insertions(+), 3 deletions(-)

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 63b4b41..cf23354 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
@@ -23,7 +23,6 @@ import java.util.Dictionary;
 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;
@@ -208,7 +207,7 @@ public class OsgiContextImpl {
                 }
                 return services;
             } else {
-                return (ServiceType[])ArrayUtils.EMPTY_OBJECT_ARRAY;
+                return (ServiceType[])Array.newInstance(serviceType, 0);
             }
         } catch (InvalidSyntaxException ex) {
             throw new RuntimeException("Invalid filter syntax: " + filter, ex);
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 65b7251..ab67824 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
@@ -94,6 +94,9 @@ public class OsgiContextImplTest {
 
     @Test
     public void testRegisterMultipleServices() {
+        Set[] serviceResults = context.getServices(Set.class, null);
+        assertEquals(0, serviceResults.length);
+
         Set<String> myService1 = new HashSet<String>();
         context.registerService(Set.class, myService1);
         Set<String> myService2 = new HashSet<String>();
@@ -102,7 +105,8 @@ public class OsgiContextImplTest {
         assertSame(myService1, context.getService(Set.class));
 
         // expected: ascending order because ordering ascending by service ID
-        Set[] serviceResults = context.getServices(Set.class, null);
+        serviceResults = context.getServices(Set.class, null);
+        assertEquals(2, serviceResults.length);
         assertSame(myService1, serviceResults[0]);
         assertSame(myService2, serviceResults[1]);
     }

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