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:26:07 UTC
[sling-org-apache-sling-testing-sling-mock] annotated tag
org.apache.sling.testing.sling-mock-2.2.0 created (now 9ae7404)
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a change to annotated tag org.apache.sling.testing.sling-mock-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git.
at 9ae7404 (tag)
tagging 1ca5846bcb76a0c437ade50375dcfcb7ac4789c2 (commit)
by Stefan Seifert
on Mon Dec 5 17:48:19 2016 +0000
- Log -----------------------------------------------------------------
org.apache.sling.testing.sling-mock-2.2.0
-----------------------------------------------------------------------
This annotated tag includes the following new commits:
new 2aa4712 SLING-4042 Donate sling-mock, jcr-mock, osgi-mock implementation
new d63d89c svn:ignore
new a6e7c1a SLING-4042 move all mock projects to mocks/ subdirectory
new d1f839a SLING-4042 add missing package-info files
new e9e968a SLING-4042 per default no charencoding should be set in mock response
new 43eb350 SLING-4042 do not forget to register ResourceResolverFactory in OSGi context as well
new 3d36daf SLING-4042 make sure JCR mock supports accessing data using multiple sessions
new 4fc4baf SLING-4042 add README files
new 4aa90b9 add/update SCM urls
new 22c8024 update to released versions
new 1ba5459 [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.0.0
new 5dcb3d7 [maven-release-plugin] prepare for next development iteration
new 5b0b3fe update dependencies in release process to next snapshot version
new 1f52235 SLING-4085 NPE when using SlingContext rule without constructor argument
new 9442dd8 SLING-4086 SlingHttpServlerRequest should support getResourceBundle() methods
new 2f5faf4 set to released version now available on maven central
new 6964d49 SLING-4090 Define package versions for Sling Mock, JCR Mock, OSGi Mock
new 448fe45 SLING-4108 JCR/Sling/ResourceResolver Mock: Support providing authentication info
new 5b4c01c fix some javadoc errors and warnings
new cb5f237 SLING-4162 Introduce "OsgiContext" junit rule for OSGi and OsgiContextImpl
new e72ad4b SLING-4229 add test cases for deep path access support in sling-mock as well
new a07abf8 SLING-4108 default to getAdministrativeResourceResolver in sling-mock to support jackrabbit resource resolver adapter as well
new 3cbedc6 fix some javadoc errors/warnings
new 47cc45e update to released versions
new fccd947 [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.1.0
new 4b72ed2 [maven-release-plugin] prepare for next development iteration
new 85cdaa4 update to next snapshot version until releases available in maven central
new 2de8a96 SLING-4266 - SlingContext always uses the default resourceResolverType
new 0a167f6 SLING-4268 - ContentLoader should not try to import ACLs
new 9ee66c6 SLING-4269 - SlingContextImpl's resource resolver should be an administrative one
new 6f6321b switch back to released versions for dependencies
new a969262 SLING-4267 add some more property names to be ignored on import because they are managed by JCR internally
new 62e7e2a SLING-4267 support importing nt:resource noded in jackrabbit with empty binary data enable content loader unit tests in sling-mock-jackrabbit
new 6569ce2 assertions can be activated now after updating to latest mock dependencies
new b816e47 SLING-4267 support importing nt:resource nodes in jackrabbit with empty binary data
new 32c3978 update dependencies to released versions
new c05aeae [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.1.2
new e57b7e1 [maven-release-plugin] prepare for next development iteration
new d9fcb59 update to next development snapshot unit released artifacts are in maven central
new c0e8f71 switch back to released versions now available in maven central
new e8d2807 SLING-4362 make sure JCR namespaces are correctly registered in JCR mock on initialization through sling mock
new 90ddb94 SLING-4376 ResourceResolver.resolve(null) should resolve to root resource
new c49b0e1 SLING-4394 Sling Mock with JCR-based Resource Resolver: Support default search paths
new 5e1c2d6 SLING-848 Support getting versioned resources by using uri path parameters
new 4e72c06 Use the recent resourceresolver SNAPSHOT in sling-mock
new eb9da99 SLING-848 revert updating sling api/resource resolver/jcr resource dependenciens - using sling mock in a project should not enforce using the latest version of those keep adding of getThreadResourceResolver() method, but throw UnsupportedOperationException
new 2259bfe SLING-4431 Sling Mocks: Remove Dependency on ResourceResolverInjector
new 74de88f cosmetic code formatting changes
new 9e35c02 SLING-4434 refactor integration with sling models: remove MockModelAdapterFactory and directly integrate the original ModelAdapterFactory using the new osgi mock dynamic service reference feature
new 71bbb5c SLING-4437 MockJcrResourceResolverFactory should allow to register services dynamically
new fc5346f SLING-4433 use real AdapterManagerImpl implementation with support for ADAPTER_CLASSES/ADAPTABLE_CLASSES
new a4d3ac9 SLING-4433 remove dependency to org.apache.sling.adapter and inline helper classes instead
new 58f81ee update to release versions
new ac35a62 update package version
new 29e7fda [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.2.0
new f96f34a [maven-release-plugin] prepare for next development iteration
new 93110e5 remove service description and vendor for this mock service - makes problems with baseline check
new f187b33 remove service description and vendor for this mock service - makes problems with baseline check
new 1b68139 update to next development snapshot unit released artifacts are in maven central
new 53be964 switch to released versions
new 34954fa SLING-4522 Sling Mocks: ContentLoader fails for UTF8 encoded json files on Windows Systems
new 75d379a Fix scr xml parsing when updating to new scr plugin by using fix for SLING-4670
new b0f4a0a SLING-4698 - Set parent.relativePath to empty for all modules
new 28f1b00 SLING-4654 Support ResourceResolver.findResources with JCR_MOCK
new 6728203 SLING-4721 sling-mock: Fully support ResourceResolverFactoryActivator for jcr-mock
new 8a9b3c4 SLING-4729 Sling Mock: Add "NONE" resource resolver type
new 5d2ffa2 SLING-4470 introduce separate "logging-mock" project for default log configuration in mock tests, remove compile-dependency on slf4j-simple
new 192936d update dependencies for release
new ab204bb update dependencies for release
new 5482f51 [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.3.0
new 7baf341 [maven-release-plugin] prepare for next development iteration
new 9a0fa2b update to next development snapshot unit released artifacts are in maven central
new bb58061 SLING-4605 - Add support for an Oak resource resolver type mock
new 3601bfd Mocks: use latest snapshots
new b6207fb SLING-4605 - Add support for an Oak resource resolver type mock
new bac4c7f update to released mock versions
new 37c868a SLING-4756 add support for filtering via felix.framework FilterImpl implementation
new 546986a SLING-4605 javadoc updates and add initializing for ContextResourceResolverFactory
new 6e3e339 Minor wording fixes when the ResourceResolverTypeAdapter can't be found.
new f4c6d5d SLING-4775 - MockSlingSettingService shoud support getSlingId()
new 7a57b01 SLING-4775 move the now supported method out of the "unsupported operations" block
new e0cc675 SLING-4773 ensure sling namespace is always registered when using JCR_MOCK resource resolver adapter
new d39a8a6 update to released versions
new 54d3fe0 [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.4.0
new 8913f6c [maven-release-plugin] prepare for next development iteration
new 37fa126 update to latest development snapshots
new df31839 Update to Sling Parent 23
new e497760 Testing: remove superflous sling.java.version=6 as it's the default now
new d8691fa switch to released versions
new a3f2ae9 set parent version to 24 and add empty relativePath where missing
new 05758ef SLING-4932, make compatible with o.a.s.jcr.resource 2.5 (requires also an upgrade to Sling API 2.9)
new 169f6e0 SLING-4932 switch back to old api/jcr.resource versions and ensure compatibility by initiating PathMapper service by reflection if it exists
new 9ab5f09 SLING-4938 exclude optional transitive dependencies of reflections
new 347ce2a SLING-4990 Support HttpSession invalidate, new, lastAccessedTime, maxInteractiveInterval
new 602f4a9 SLING-4993 Support RequestParameter in MockSlingHttpServlerRequest
new ec0efee SLING-4994 Support InputStream, ContentLenght, ContentType and CharacterEncoding in Request
new 489ae34 SLING-4998 ResponseBodySupport - use default charset if no response charset is set
new 9832809 cosmetic: beautify error messages when setup/teardown fails
new da53509 SLING-5002 - [sling-mock] Update dependency version of org.reflections
new 3fafd8e SLING-5003 Support request dispatcher in MockSlingHttpServletRequest
new b4037bf SLING-5002 switch back to 0.9.9 due to threading issues in 0.9.10 when running junit tests in parallel
new e52575e update other mocks to latest releases
new 2a934a4 [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.5.0
new 8f19c45 [maven-release-plugin] prepare for next development iteration
new d58abbe switch to latest snapshot version until release is available in maven central
new 07c6650 SLING-5007 add unit test to explicitly test root path child listing in sling-mock as well
new d5ebb42 SLING-5007 realx unit test to test root path child listing in sling-mock-jackrabbit and sling-mock-jackrabbit and sling-mock-oak because in real repositories multiple root test nodes may be created in parallel, or nodes already exist
new 8580a55 update release versions
new 5846795 update to next snapshot version until releases are available in maven central
new f960880 SLING-5007 use same unit tests for root node tests for all resource resolver types without counting the number of children.
new 0ac864b switch back to released version
new add520f SLING-5042 ResourceResolver.commit() does not call session.save() on the backing JCR Session
new 8123868 SLING-5043 sling-mocks: Execute commit() after ContentLoader operations
new c1ce2e6 SLING-5057 - Support HttpServletRequest#getRemoteUser
new b10d3bb SLING-5057 - Support HttpServletRequest#getRemoteUser
new 53bfbe5 SLING-5064 sling-mock: Register JCR node types for OSGi bundles in class path
new 853e02b SLING-5064 sling-mock: Register JCR node types for OSGi bundles in class path
new c7551b3 cosmetic: fix log message
new 317bf58 SLING-5066 sling-mock: Close ResourceResolver on JUnit test tearDown
new f008644 SLING-5064 sling-mock: Register JCR node types for OSGi bundles in class path
new 8c79b81 SLING-5067 sling-mock: "uniqueRoot()" to simplify creation and cleanup of unique root paths in repository
new b24a116 SLING-5067 rewrite unit tests to use new "uniqueRoot" feature
new 3c296a7 SLING-5064 manual registration of node types no longer required; register namespaces and node types centrally depending on NodeTypeMode
new d795bcc SLING-5067 fix cleanup issue with "uniqueRoot" feature
new d74181d SLING-5086 sling-mock: Add SlingContext.registerAdapter convenience method
new fd0b260 SLING-5086 sling-mock: Add SlingContext.registerAdapter convenience method
new cf03565 cosmetic: eliminate some javadoc warnings
new 5c7c77d SLING-5088 update to latest osgi-mock to make sure all services are deactivated properly
new 856784c SLING-5088 refactor unit test to make sure resource resolver and bundle contexts are properly shutdown
new b90bd44 SLING-5088 refactor resource resolver initialization
new 81f87d0 SLING-5088 rewrite setup code for resource resolver factory
new 1b9e8db SLING-5088 deprecate all methods that may lead to thread leaks
new 8801d99 SLING-5088 control SlingRepository resources via activate/deactivate methods; make sure all oak ExecutorServices are shutdown properly
new c1525db cosmetic: fix javadoc errors
new 47f0035 SLING-5088 avoid registering ResourceResolverFactory twice
new 21a5c64 SLING-5088 register default service user mapping for mock bundle
new 2b7ac22 Update the main reactor to parent 25
new 1089980 update dependency
new 8949c00 [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.6.0
new 90239a1 [maven-release-plugin] prepare for next development iteration
new 9f9253b set dependencies to next snapshot version until released versions are available in maven central
new 7ac242f switch back to released versions of dependency
new 1f318cf SLING-5197 sling-mock: Do not override ResourceResolverFactoryActivator's default values
new f7609c8 SLING-5197 sling-mock: Do not override ResourceResolverFactoryActivator's default values
new d444456 update to latest osgi-mock version
new dd7948a SLING-5339 sling-mock: Support remote add, remote host and remote port in MockSlingHttpSevletRequest
new a52790b SLING-5392 sling-mock: Use javax.servlet-api dependency instead of mortbay version
new 3234a24 Switch to parent pom 26
new dfd873c SLING-5428 Move MockSlingHttpServletRequest+Response to org.apache.sling.servlet-helpers
new e7cd297 update mock dependencies to latest versions
new 0186990 fix javadoc errors
new 64a8b38 [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.6.2
new a56450f [maven-release-plugin] prepare for next development iteration
new 37d2b26 update to next snapshot dependency until released artifacts are available in maven central
new e39da4c update to released versions
new 6759ae4 SLING-5546 Update to Sling API 2.11 and dependencies
new 41b471d SLING-5546 remove deprecated methods
new 22cce0c SLING-5547 Update sling-mock-oak to Sling API 2.11 and Oak 1.3.15
new 05a8c47 SLING-5548 Remove JCR_JACKRABBIT resource resolver type
new e2054b1 SLING-5547 Update sling-mock-oak to Sling API 2.11 and Oak 1.3.15
new 8476a66 add unit test to test adapter factory overlays
new 57b714b SLING-5667 adapt to changes service ranking order in osgi-mock
new 08b7fd5 SLING-5769 expose resource resolver factory from SlingContext
new ec77950 SLING-5769 reverted r1747508 since it is already exposed through getService(...)
new 3239d98 SLING-5770 add support for custom resource resolver factory activator configuration via SlingContextBuilder add support for additional callbacks before setup and after teardown
new 7d5c794 SLING-5770 update javadoc
new 0b0cd7e update dependencies to released versions
new 17d3932 [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-2.0.0
new edd14e1 [maven-release-plugin] prepare for next development iteration
new a3952b6 SLING-5968 sling-mock: Update to latest servlet-helpers
new b296e07 SLING-5970 mocks: Update to Parent Pom 28
new 143930c SLING-5970 switch to osgi annotations
new dcea6ec Update to 3.0.2 to avoid heap space problem
new 2891337 SLING-6040 add ResourceBuilder support to SlingContext This closes #167
new 256b173 SLING-6049 sling-mock ContentBuilder: Support creating resources with object vararg parameter
new f412e8d SLING-6049 use MapUtil from osgi-mock
new 0e3ccde update dependencies
new 70d871d [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-2.1.0
new 2b820fa [maven-release-plugin] prepare for next development iteration
new ab2cc19 update dependencies to latest snapshots until released versions are available in maven central
new e5cf893 switch back to released versions
new 0bf6410 fix indentation
new df1f8db SLING-6077 sling-mock: ResourceResolverFactory is registered twice
new 4341eb9 [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-2.1.2
new be969f7 [maven-release-plugin] prepare for next development iteration
new fa2b952 update to latest resourcebuilder snapshot
new 843e0c8 update to released version
new 3d5d93e update to parent 29
new df62a8e SLING-6356 osgi-mock: Fallback to default when reference field collection type is missing in SCR metadata
new 02a5370 SLING-6359 osgi-mock, sling-mock: Make ContextCallback and ContextBuilder more flexible
new c539b44 fix javadoc errors
new 99270aa SLING-6359 context plugin support
new 80d0e0d SLING-6363 Automatically register Sling Models from Classpath also: - add SlingContext.addModelsForClasses method - fix bug in addModelsForPackages that registered "sibling" packages with same prefix as well - make sure classpath scanning takes place only once for alle unit tests, not for each unit test which requests the same package - witch NodeTypeDefinitionScanner to osgi-mock ManifestScanner as well
new a7e2fa4 fix javadoc errors
new 28317f0 update osgi-mock dependency
new 80bc845 [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-2.2.0
new 1ca5846 [maven-release-plugin] copy for tag org.apache.sling.testing.sling-mock-2.2.0
The 197 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-sling-mock] 07/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.sling-mock-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit c539b440635d1bc2e83cbd14801837c9de7c4b94
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/sling-mock@1772454 13f79535-47bb-0310-9956-ffa450edef68
---
.../org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java b/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java
index d058e12..4120292 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java
@@ -201,6 +201,7 @@ public class MockAdapterManagerImpl implements AdapterManager {
/**
* Bind a new adapter factory.
+ * @param reference Service reference
*/
protected void bindAdapterFactory(final ServiceReference reference) {
boolean create = true;
@@ -219,6 +220,7 @@ public class MockAdapterManagerImpl implements AdapterManager {
/**
* Unbind a adapter factory.
+ * @param reference Service reference
*/
protected void unbindAdapterFactory(final ServiceReference reference) {
unregisterAdapterFactory(reference);
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-testing-sling-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.sling-mock-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit be969f765d2a3838b3c003a33104c19f1b04e046
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Thu Oct 6 20:46:11 2016 +0000
[maven-release-plugin] prepare for next development iteration
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1763658 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 9ed1a0e..1ac0bac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,16 +28,16 @@
</parent>
<artifactId>org.apache.sling.testing.sling-mock</artifactId>
- <version>2.1.2</version>
+ <version>2.1.3-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>Apache Sling Testing Sling Mock</name>
<description>Mock implementation of selected Sling APIs.</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.sling-mock-2.1.2</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.sling-mock-2.1.2</developerConnection>
- <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.testing.sling-mock-2.1.2</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-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-sling-mock] 13/13:
[maven-release-plugin] copy for tag
org.apache.sling.testing.sling-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.sling-mock-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit 1ca5846bcb76a0c437ade50375dcfcb7ac4789c2
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Dec 5 17:48:19 2016 +0000
[maven-release-plugin] copy for tag org.apache.sling.testing.sling-mock-2.2.0
git-svn-id: https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.sling-mock-2.2.0@1772736 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-sling-mock] 09/13: SLING-6363
Automatically register Sling Models from Classpath also: - add
SlingContext.addModelsForClasses method - fix bug in addModelsForPackages
that registered "sibling" packages with same prefix as well - make sure
classpath scanning takes place only once for alle unit tests,
not for each unit test which requests the same package - witch
NodeTypeDefinitionScanner to osgi-mock ManifestScanner as well
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.sling-mock-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit 80d0e0d70b39f6006aa8bbd8b9602746add369fd
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Sun Dec 4 10:37:46 2016 +0000
SLING-6363 Automatically register Sling Models from Classpath
also:
- add SlingContext.addModelsForClasses method
- fix bug in addModelsForPackages that registered "sibling" packages with same prefix as well
- make sure classpath scanning takes place only once for alle unit tests, not for each unit test which requests the same package
- witch NodeTypeDefinitionScanner to osgi-mock ManifestScanner as well
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1772518 13f79535-47bb-0310-9956-ffa450edef68
---
.../mock/sling/NodeTypeDefinitionScanner.java | 44 +-----
.../context/ContextResourceResolverFactory.java | 2 -
.../sling/context/ModelAdapterFactoryUtil.java | 176 ++++++++++++++++++---
.../mock/sling/context/SlingContextImpl.java | 34 +++-
...va => AbstractModelAdapterFactoryUtilTest.java} | 62 ++------
.../context/AbstractSlingContextImplTest.java | 39 +----
.../ModelAdapterFactoryUtilClassesTest.java | 52 ++++++
.../ModelAdapterFactoryUtilPackagesTest.java | 44 ++++++
.../sling/context/models/OsgiServiceModel.java | 36 +++++
.../context/models/RequestAttributeModel.java | 35 ++++
.../sling/context/models/ServiceInterface.java | 28 ++++
.../sling/context/models/ServiceInterfaceImpl.java | 40 +++++
12 files changed, 436 insertions(+), 156 deletions(-)
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java b/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java
index fed6cd7..55287e9 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java
@@ -18,18 +18,12 @@
*/
package org.apache.sling.testing.mock.sling;
-import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
-import java.net.URL;
import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
-import java.util.jar.Attributes;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
import javax.jcr.NamespaceRegistry;
import javax.jcr.RepositoryException;
@@ -48,11 +42,11 @@ import javax.jcr.nodetype.PropertyDefinition;
import javax.jcr.nodetype.PropertyDefinitionTemplate;
import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.commons.cnd.CndImporter;
import org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader;
import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory;
import org.apache.jackrabbit.commons.cnd.TemplateBuilderFactory;
+import org.apache.sling.testing.mock.osgi.ManifestScanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -231,41 +225,7 @@ public final class NodeTypeDefinitionScanner {
* @return List of node type definition class paths
*/
private static List<String> findeNodeTypeDefinitions() {
- List<String> nodeTypeDefinitions = new ArrayList<String>();
- try {
- Enumeration<URL> resEnum = NodeTypeDefinitionScanner.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 nodeTypeDefinitionList = mainAttribs.getValue("Sling-Nodetypes");
- String[] nodeTypeDefinitionArray = StringUtils.split(nodeTypeDefinitionList, ",");
- if (nodeTypeDefinitionArray != null) {
- for (String nodeTypeDefinition : nodeTypeDefinitionArray) {
- if (!StringUtils.isBlank(nodeTypeDefinition)) {
- nodeTypeDefinitions.add(StringUtils.trim(nodeTypeDefinition));
- }
- }
- }
- }
- finally {
- is.close();
- }
- }
- }
- catch (Throwable ex) {
- log.warn("Unable to read JAR manifest.", ex);
- }
- }
- }
- catch (IOException ex2) {
- log.warn("Unable to read JAR manifests.", ex2);
- }
- return nodeTypeDefinitions;
+ return new ArrayList<String>(ManifestScanner.getValues("Sling-Nodetypes"));
}
public static NodeTypeDefinitionScanner get() {
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/ContextResourceResolverFactory.java b/src/main/java/org/apache/sling/testing/mock/sling/context/ContextResourceResolverFactory.java
index 3b61fdb..65cf6d2 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/ContextResourceResolverFactory.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/ContextResourceResolverFactory.java
@@ -24,13 +24,11 @@ import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.testing.mock.sling.MockSling;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
-import org.osgi.annotation.versioning.ProviderType;
import org.osgi.framework.BundleContext;
/**
* Create resolve resolver instance and initialize it depending on it's type.
*/
-@ProviderType
final class ContextResourceResolverFactory {
private ContextResourceResolverFactory() {
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java b/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java
index 478c101..38675ee 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java
@@ -24,6 +24,8 @@ import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
@@ -31,10 +33,13 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import org.apache.commons.lang3.StringUtils;
import org.apache.sling.models.annotations.Model;
+import org.apache.sling.testing.mock.osgi.ManifestScanner;
import org.apache.sling.testing.mock.osgi.MockOsgi;
-import org.osgi.annotation.versioning.ProviderType;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
@@ -46,39 +51,165 @@ import org.reflections.Reflections;
/**
* Helper methos for simulating sling models bundle events.
*/
-@ProviderType
final class ModelAdapterFactoryUtil {
+ private static final String PACKAGE_HEADER = "Sling-Model-Packages";
+ private static final String CLASSES_HEADER = "Sling-Model-Classes";
+
+ private static final String[] MODELS_PACKAGES_FROM_MANIFEST;
+ private static final String[] MODELS_CLASSES_FROM_MANIFEST;
+
+ private static final ConcurrentMap<String, List<URL>> MODEL_URLS_FOR_PACKAGES = new ConcurrentHashMap<String, List<URL>>();
+ private static final ConcurrentMap<String, List<URL>> MODEL_URLS_FOR_CLASSES = new ConcurrentHashMap<String, List<URL>>();
+
static {
- // disable logging of reflections library to avoid spamming log files during unit tests
+ // suppress log entries from Reflections library
Reflections.log = null;
+
+ // scan classpath for models bundle header entries only once
+ MODELS_PACKAGES_FROM_MANIFEST = toArray(ManifestScanner.getValues(PACKAGE_HEADER));
+ MODELS_CLASSES_FROM_MANIFEST = toArray(ManifestScanner.getValues(CLASSES_HEADER));
}
private ModelAdapterFactoryUtil() {
// static methods only
}
+ private static String[] toArray(Collection<String> values) {
+ return values.toArray(new String[values.size()]);
+ }
+
/**
- * Scan classpaths for given package name (and sub packages) to scan for and
+ * Search classpath for given java package names (and sub packages) to scan for and
* register all classes with @Model annotation.
- * @param packageName Java package name
+ * @param bundleContext Bundle context
+ * @param packageNames Java package names
*/
- public static void addModelsForPackage(String packageName, BundleContext bundleContext) {
- Bundle bundle = new ModelsPackageBundle(packageName, Bundle.ACTIVE, bundleContext);
+ public static void addModelsForPackages(BundleContext bundleContext, String... packageNames) {
+ Bundle bundle = new RegisterModelsBundle(bundleContext, Bundle.ACTIVE, packageNames, null);
BundleEvent event = new BundleEvent(BundleEvent.STARTED, bundle);
MockOsgi.sendBundleEvent(bundleContext, event);
}
- private static class ModelsPackageBundle implements Bundle {
+ /**
+ * Search classpath for given class names to scan for and register all classes with @Model annotation.
+ * @param bundleContext Bundle context
+ * @param classNames Java class names
+ */
+ public static void addModelsForClasses(BundleContext bundleContext, String... classNames) {
+ Bundle bundle = new RegisterModelsBundle(bundleContext, Bundle.ACTIVE, null, classNames);
+ BundleEvent event = new BundleEvent(BundleEvent.STARTED, bundle);
+ MockOsgi.sendBundleEvent(bundleContext, event);
+ }
+
+ /**
+ * Search classpath for given class names to scan for and register all classes with @Model annotation.
+ * @param bundleContext Bundle context
+ * @param classNames Java class names
+ */
+ public static void addModelsForClasses(BundleContext bundleContext, Class... classes) {
+ String[] classNames = new String[classes.length];
+ for (int i = 0; i < classes.length; i++) {
+ classNames[i] = classes[i].getName();
+ }
+ addModelsForClasses(bundleContext, classNames);
+ }
+
+ /**
+ * Scan MANIFEST.MF in the classpath and automatically register all sling model classes found.
+ * @param bundleContext Bundle context
+ */
+ public static void addModelsForManifestEntries(BundleContext bundleContext) {
+ if (MODELS_PACKAGES_FROM_MANIFEST.length > 0) {
+ addModelsForPackages(bundleContext, MODELS_PACKAGES_FROM_MANIFEST);
+ }
+ if (MODELS_CLASSES_FROM_MANIFEST.length > 0) {
+ addModelsForClasses(bundleContext, MODELS_CLASSES_FROM_MANIFEST);
+ }
+ }
+
+ /**
+ * Get model classes in list of packages (and subpackages), and cache result in static map.
+ * @param packageNames Package names
+ * @return List of URLs
+ */
+ private static Collection<URL> getModelClassUrlsForPackages(String packageNames) {
+ List<URL> urls = MODEL_URLS_FOR_PACKAGES.get(packageNames);
+ if (urls == null) {
+ urls = new ArrayList<URL>();
+ String[] packageNameArray = StringUtils.split(packageNames, ",");
+ // add "." to each package name because it's a prefix, not a package name
+ Object[] prefixArray = new Object[packageNameArray.length];
+ for (int i = 0; i < packageNameArray.length; i++) {
+ prefixArray[i] = packageNameArray[i] + ".";
+ }
+ Reflections reflections = new Reflections(prefixArray);
+ Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Model.class);
+ for (Class<?> clazz : classes) {
+ urls.add(classToUrl(clazz));
+ }
+ MODEL_URLS_FOR_PACKAGES.putIfAbsent(packageNames, urls);
+ }
+ return urls;
+ }
+
+ /**
+ * Get model classes in list of class names, and cache result in static map.
+ * @param packageNames Class names
+ * @return List of URLs
+ */
+ private static Collection<URL> getModelClassUrlsForClasses(String classNames) {
+ List<URL> urls = MODEL_URLS_FOR_CLASSES.get(classNames);
+ if (urls == null) {
+ urls = new ArrayList<URL>();
+ String[] packageNameArray = StringUtils.split(classNames, ",");
+ for (String className : packageNameArray) {
+ try {
+ Class<?> clazz = Class.forName(className);
+ if (clazz.isAnnotationPresent(Model.class)) {
+ urls.add(classToUrl(clazz));
+ }
+ }
+ catch (ClassNotFoundException e) {
+ // ignore
+ }
+ }
+ MODEL_URLS_FOR_CLASSES.putIfAbsent(classNames, urls);
+ }
+ return urls;
+ }
+
+ private static URL classToUrl(Class clazz) {
+ try {
+ return new URL("file:/" + clazz.getName().replace('.', '/') + ".class");
+ }
+ catch (MalformedURLException ex) {
+ throw new RuntimeException("Malformed URL.", ex);
+ }
+ }
+
+
+ private static class RegisterModelsBundle implements Bundle {
+
+ private static final String MAGIC_STRING = "MOCKS-YOU-KNOW-WHAT-TO-SCAN";
- private final String packageName;
- private final int state;
private final BundleContext bundleContext;
+ private final int state;
+ private final String packageNames;
+ private final String classNames;
- public ModelsPackageBundle(String packageName, int state, BundleContext bundleContext) {
- this.packageName = packageName;
- this.state = state;
+ public RegisterModelsBundle(BundleContext bundleContext, int state, String[] packageNames, String[] classNames) {
this.bundleContext = bundleContext;
+ this.state = state;
+ this.packageNames = normalizeValueList(packageNames);
+ this.classNames = normalizeValueList(classNames);
+ }
+
+ private String normalizeValueList(String[] values) {
+ if (values == null || values.length == 0) {
+ return null;
+ }
+ return StringUtils.join(values, ",");
}
@Override
@@ -89,25 +220,22 @@ final class ModelAdapterFactoryUtil {
@Override
public Dictionary<String,String> getHeaders() {
Dictionary<String, String> headers = new Hashtable<String, String>();
- headers.put("Sling-Model-Packages", this.packageName);
+ headers.put(PACKAGE_HEADER, MAGIC_STRING);
return headers;
}
@Override
public Enumeration<URL> findEntries(String path, String filePattern, boolean recurse) {
- Reflections reflections = new Reflections(this.packageName);
- Set<Class<?>> types = reflections.getTypesAnnotatedWith(Model.class);
Vector<URL> urls = new Vector<URL>(); // NOPMD
- try {
- for (Class<?> type : types) {
- urls.add(new URL("file:/" + type.getName().replace('.', '/') + ".class"));
- }
- } catch (MalformedURLException ex) {
- throw new RuntimeException("Malformed URL.", ex);
+ if (packageNames != null) {
+ urls.addAll(getModelClassUrlsForPackages(packageNames));
+ }
+ if (classNames != null) {
+ urls.addAll(getModelClassUrlsForClasses(classNames));
}
return urls.elements();
}
-
+
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
return getClass().getClassLoader().loadClass(name);
@@ -237,7 +365,7 @@ final class ModelAdapterFactoryUtil {
public File getDataFile(String filename) {
return null;
}
-
+
}
}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
index 834b40e..7e1776f 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
@@ -176,6 +176,9 @@ public class SlingContextImpl extends OsgiContextImpl {
registerService(SlingSettingsService.class, new MockSlingSettingService(DEFAULT_RUN_MODES));
registerService(MimeTypeService.class, new MockMimeTypeService());
registerInjectActivateService(new ResourceBuilderFactoryService());
+
+ // scan for models defined via bundle headers in classpath
+ ModelAdapterFactoryUtil.addModelsForManifestEntries(this.bundleContext());
}
/**
@@ -358,12 +361,37 @@ public class SlingContextImpl extends OsgiContextImpl {
}
/**
- * Scan classpaths for given package name (and sub packages) to scan for and
+ * Search classpath for given java package names (and sub packages) to scan for and
* register all classes with @Model annotation.
- * @param packageName Java package name
+ * @param packageNames Java package name
*/
public final void addModelsForPackage(String packageName) {
- ModelAdapterFactoryUtil.addModelsForPackage(packageName, bundleContext());
+ ModelAdapterFactoryUtil.addModelsForPackages(bundleContext(), packageName);
+ }
+
+ /**
+ * Search classpath for given java package names (and sub packages) to scan for and
+ * register all classes with @Model annotation.
+ * @param packageNames Java package names
+ */
+ public final void addModelsForPackage(String... packageNames) {
+ ModelAdapterFactoryUtil.addModelsForPackages(bundleContext(), packageNames);
+ }
+
+ /**
+ * Search classpath for given class names to scan for and register all classes with @Model annotation.
+ * @param classNames Java class names
+ */
+ public final void addModelsForClasses(String... classNames) {
+ ModelAdapterFactoryUtil.addModelsForClasses(bundleContext(), classNames);
+ }
+
+ /**
+ * Search classpath for given class names to scan for and register all classes with @Model annotation.
+ * @param classNames Java class names
+ */
+ public final void addModelsForClasses(Class... classes) {
+ ModelAdapterFactoryUtil.addModelsForClasses(bundleContext(), classes);
}
/**
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilTest.java b/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractModelAdapterFactoryUtilTest.java
similarity index 50%
rename from src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilTest.java
rename to src/test/java/org/apache/sling/testing/mock/sling/context/AbstractModelAdapterFactoryUtilTest.java
index 68a707d..eb68682 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractModelAdapterFactoryUtilTest.java
@@ -22,42 +22,31 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import javax.inject.Inject;
-
-import org.apache.sling.api.SlingHttpServletRequest;
-import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.mime.MimeTypeService;
-import org.apache.sling.models.annotations.Model;
+import org.apache.sling.testing.mock.sling.context.models.OsgiServiceModel;
+import org.apache.sling.testing.mock.sling.context.models.RequestAttributeModel;
+import org.apache.sling.testing.mock.sling.context.models.ServiceInterface;
import org.apache.sling.testing.mock.sling.junit.SlingContext;
import org.apache.sling.testing.mock.sling.services.MockMimeTypeService;
-import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-public class ModelAdapterFactoryUtilTest {
-
- @Rule
- public SlingContext context = new SlingContext();
+public abstract class AbstractModelAdapterFactoryUtilTest {
- @Before
- public void setUp() throws Exception {
- // scan for @Model classes
- context.addModelsForPackage("org.apache.sling.testing.mock.sling.context");
- }
+ protected abstract SlingContext context();
@Test
public void testRequestAttribute() {
- context.request().setAttribute("prop1", "myValue");
- RequestAttributeModel model = context.request().adaptTo(RequestAttributeModel.class);
+ context().request().setAttribute("prop1", "myValue");
+ RequestAttributeModel model = context().request().adaptTo(RequestAttributeModel.class);
assertNotNull(model);
assertEquals("myValue", model.getProp1());
}
@Test
public void testOsgiService() {
- context.registerService(MimeTypeService.class, new MockMimeTypeService());
+ context().registerService(MimeTypeService.class, new MockMimeTypeService());
- OsgiServiceModel model = context.resourceResolver().adaptTo(OsgiServiceModel.class);
+ OsgiServiceModel model = context().resourceResolver().adaptTo(OsgiServiceModel.class);
assertNotNull(model);
assertNotNull(model.getMimeTypeService());
assertEquals("text/html", model.getMimeTypeService().getMimeType("html"));
@@ -65,43 +54,16 @@ public class ModelAdapterFactoryUtilTest {
@Test
public void testInvalidAdapt() {
- OsgiServiceModel model = context.request().adaptTo(OsgiServiceModel.class);
+ OsgiServiceModel model = context().request().adaptTo(OsgiServiceModel.class);
assertNull(model);
}
@Test
public void testAdaptToInterface() {
- context.request().setAttribute("prop1", "myValue");
- ServiceInterface model = context.request().adaptTo(ServiceInterface.class);
+ context().request().setAttribute("prop1", "myValue");
+ ServiceInterface model = context().request().adaptTo(ServiceInterface.class);
assertNotNull(model);
assertEquals("myValue", model.getPropValue());
}
- @Model(adaptables = SlingHttpServletRequest.class)
- public interface RequestAttributeModel {
- @Inject
- String getProp1();
- }
-
- @Model(adaptables = ResourceResolver.class)
- public interface OsgiServiceModel {
- @Inject
- MimeTypeService getMimeTypeService();
- }
-
- public interface ServiceInterface {
- String getPropValue();
- }
-
- @Model(adaptables = SlingHttpServletRequest.class, adapters = ServiceInterface.class)
- public static class ServiceInterfaceImpl implements ServiceInterface {
- @Inject
- private String prop1;
-
- @Override
- public String getPropValue() {
- return this.prop1;
- }
- }
-
}
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java b/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
index a921e10..6299dfb 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
@@ -26,17 +26,14 @@ import static org.junit.Assert.assertTrue;
import java.util.Set;
-import javax.inject.Inject;
-
-import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.scripting.SlingBindings;
-import org.apache.sling.commons.mime.MimeTypeService;
-import org.apache.sling.models.annotations.Model;
import org.apache.sling.settings.SlingSettingsService;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.context.models.OsgiServiceModel;
+import org.apache.sling.testing.mock.sling.context.models.RequestAttributeModel;
+import org.apache.sling.testing.mock.sling.context.models.ServiceInterface;
import org.apache.sling.testing.mock.sling.junit.SlingContext;
import org.apache.sling.testing.mock.sling.loader.ContentLoader;
import org.apache.sling.testing.mock.sling.services.MockMimeTypeService;
@@ -51,7 +48,7 @@ public abstract class AbstractSlingContextImplTest {
@Before
public void setUp() throws Exception {
- context.addModelsForPackage("org.apache.sling.testing.mock.sling.context");
+ context.addModelsForPackage("org.apache.sling.testing.mock.sling.context.models");
ContentLoader contentLoader = this.context.load();
contentLoader.json("/json-import-samples/content.json", "/content/sample/en");
@@ -147,32 +144,4 @@ public abstract class AbstractSlingContextImplTest {
assertEquals(1, factories.length);
}
- @Model(adaptables = SlingHttpServletRequest.class)
- public interface RequestAttributeModel {
- @Inject
- String getProp1();
- }
-
- @Model(adaptables = ResourceResolver.class)
- public interface OsgiServiceModel {
- @Inject
- MimeTypeService getMimeTypeService();
- }
-
- public interface ServiceInterface {
- String getPropValue();
- }
-
- @Model(adaptables = SlingHttpServletRequest.class, adapters = ServiceInterface.class)
- public static class ServiceInterfaceImpl implements ServiceInterface {
-
- @Inject
- private String prop1;
-
- @Override
- public String getPropValue() {
- return this.prop1;
- }
- }
-
}
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilClassesTest.java b/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilClassesTest.java
new file mode 100644
index 0000000..f576075
--- /dev/null
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilClassesTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.sling.context;
+
+import org.apache.sling.testing.mock.sling.context.models.OsgiServiceModel;
+import org.apache.sling.testing.mock.sling.context.models.RequestAttributeModel;
+import org.apache.sling.testing.mock.sling.context.models.ServiceInterfaceImpl;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.Before;
+import org.junit.Rule;
+
+public class ModelAdapterFactoryUtilClassesTest extends AbstractModelAdapterFactoryUtilTest {
+
+ @Rule
+ public SlingContext context = new SlingContext();
+
+ @Override
+ protected SlingContext context() {
+ return context;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ // add Model classes individually
+ // although this is not supported before Sling Models Impl 1.3.4 in mocks this works even with older sling models versions
+ // because the class path scanning is implemented differently
+ context.addModelsForClasses(
+ OsgiServiceModel.class.getName()
+ );
+ context.addModelsForClasses(
+ RequestAttributeModel.class,
+ ServiceInterfaceImpl.class
+ );
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilPackagesTest.java b/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilPackagesTest.java
new file mode 100644
index 0000000..204d40e
--- /dev/null
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilPackagesTest.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.testing.mock.sling.context;
+
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.Before;
+import org.junit.Rule;
+
+public class ModelAdapterFactoryUtilPackagesTest extends AbstractModelAdapterFactoryUtilTest {
+
+ @Rule
+ public SlingContext context = new SlingContext();
+
+ @Override
+ protected SlingContext context() {
+ return context;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ // scan for @Model classes
+ context.addModelsForPackage(
+ "org.apache.sling.testing.mock.sling.context",
+ "org.apache.sling.testing.mock.sling.context.models"
+ );
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/models/OsgiServiceModel.java b/src/test/java/org/apache/sling/testing/mock/sling/context/models/OsgiServiceModel.java
new file mode 100644
index 0000000..add20e9
--- /dev/null
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/models/OsgiServiceModel.java
@@ -0,0 +1,36 @@
+/*
+ * 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.sling.context.models;
+
+import javax.inject.Inject;
+
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.commons.mime.MimeTypeService;
+import org.apache.sling.models.annotations.Model;
+
+/**
+ * For testing Sling Models support.
+ */
+@Model(adaptables = ResourceResolver.class)
+public interface OsgiServiceModel {
+
+ @Inject
+ MimeTypeService getMimeTypeService();
+
+}
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/models/RequestAttributeModel.java b/src/test/java/org/apache/sling/testing/mock/sling/context/models/RequestAttributeModel.java
new file mode 100644
index 0000000..958b67d
--- /dev/null
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/models/RequestAttributeModel.java
@@ -0,0 +1,35 @@
+/*
+ * 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.sling.context.models;
+
+import javax.inject.Inject;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.models.annotations.Model;
+
+/**
+ * For testing Sling Models support.
+ */
+@Model(adaptables = SlingHttpServletRequest.class)
+public interface RequestAttributeModel {
+
+ @Inject
+ String getProp1();
+
+}
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/models/ServiceInterface.java b/src/test/java/org/apache/sling/testing/mock/sling/context/models/ServiceInterface.java
new file mode 100644
index 0000000..d434f56
--- /dev/null
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/models/ServiceInterface.java
@@ -0,0 +1,28 @@
+/*
+ * 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.sling.context.models;
+
+/**
+ * For testing Sling Models support.
+ */
+public interface ServiceInterface {
+
+ String getPropValue();
+
+}
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/models/ServiceInterfaceImpl.java b/src/test/java/org/apache/sling/testing/mock/sling/context/models/ServiceInterfaceImpl.java
new file mode 100644
index 0000000..ef1a639
--- /dev/null
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/models/ServiceInterfaceImpl.java
@@ -0,0 +1,40 @@
+/*
+ * 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.sling.context.models;
+
+import javax.inject.Inject;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.models.annotations.Model;
+
+/**
+ * For testing Sling Models support.
+ */
+@Model(adaptables = SlingHttpServletRequest.class, adapters = ServiceInterface.class)
+public class ServiceInterfaceImpl implements ServiceInterface {
+
+ @Inject
+ private String prop1;
+
+ @Override
+ public String getPropValue() {
+ return this.prop1;
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-testing-sling-mock] 06/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.sling-mock-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit 02a5370304b2263e28bac41b14785f64c495b042
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/sling-mock@1772443 13f79535-47bb-0310-9956-ffa450edef68
---
...ingContextCallback.java => CallbackParams.java} | 36 ++++++------
.../testing/mock/sling/junit/SlingContext.java | 67 +++++++++++-----------
.../mock/sling/junit/SlingContextBuilder.java | 41 ++++++++-----
.../mock/sling/junit/SlingContextCallback.java | 14 +----
.../testing/mock/sling/junit/package-info.java | 2 +-
.../testing/mock/sling/junit/SlingContextTest.java | 5 +-
6 files changed, 87 insertions(+), 78 deletions(-)
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextCallback.java b/src/main/java/org/apache/sling/testing/mock/sling/junit/CallbackParams.java
similarity index 53%
copy from src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextCallback.java
copy to src/main/java/org/apache/sling/testing/mock/sling/junit/CallbackParams.java
index 247185b..680ce04 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextCallback.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/junit/CallbackParams.java
@@ -18,22 +18,26 @@
*/
package org.apache.sling.testing.mock.sling.junit;
-import java.io.IOException;
+import org.apache.sling.testing.mock.osgi.junit.ContextCallback;
-import org.apache.sling.api.resource.PersistenceException;
-
-/**
- * Callback-interface for application-specific setup and teardown operations to
- * customize the {@link SlingContext} JUnit rule.
- */
-public interface SlingContextCallback {
-
- /**
- * Execute callback action
- * @param context Sling context
- * @throws IOException I/O exception
- * @throws PersistenceException Persistence exception
- */
- void execute(SlingContext context) throws IOException, PersistenceException;
+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/sling/junit/SlingContext.java b/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContext.java
index 9dcd712..37cfdcf 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContext.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContext.java
@@ -20,6 +20,7 @@ package org.apache.sling.testing.mock.sling.junit;
import java.util.Map;
+import org.apache.sling.testing.mock.osgi.junit.ContextCallback;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
import org.apache.sling.testing.mock.sling.context.SlingContextImpl;
import org.junit.rules.ExternalResource;
@@ -34,10 +35,7 @@ import org.junit.runners.model.Statement;
*/
public final class SlingContext extends SlingContextImpl implements TestRule {
- private final SlingContextCallback beforeSetUpCallback;
- private final SlingContextCallback afterSetUpCallback;
- private final SlingContextCallback beforeTearDownCallback;
- private final SlingContextCallback afterTearDownCallback;
+ private final CallbackParams callbackParams;
private final TestRule delegate;
/**
@@ -45,7 +43,7 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
* {@link org.apache.sling.testing.mock.sling.MockSling#DEFAULT_RESOURCERESOLVER_TYPE}.
*/
public SlingContext() {
- this(null, null, null);
+ this(new CallbackParams(), null, null);
}
/**
@@ -53,7 +51,7 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
* @param resourceResolverType Resource resolver type.
*/
public SlingContext(final ResourceResolverType resourceResolverType) {
- this(null, null, resourceResolverType);
+ this(new CallbackParams(), null, resourceResolverType);
}
/**
@@ -61,8 +59,8 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
* {@link org.apache.sling.testing.mock.sling.MockSling#DEFAULT_RESOURCERESOLVER_TYPE}.
* @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
*/
- public SlingContext(final SlingContextCallback afterSetUpCallback) {
- this(afterSetUpCallback, null, null);
+ public SlingContext(final ContextCallback<?> afterSetUpCallback) {
+ this(new CallbackParams(afterSetUpCallback), null, null);
}
/**
@@ -70,8 +68,8 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
* @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
* @param resourceResolverType Resource resolver type.
*/
- public SlingContext(final SlingContextCallback afterSetUpCallback, final ResourceResolverType resourceResolverType) {
- this(afterSetUpCallback, null, resourceResolverType);
+ public SlingContext(final ContextCallback<?> afterSetUpCallback, final ResourceResolverType resourceResolverType) {
+ this(new CallbackParams(afterSetUpCallback), null, resourceResolverType);
}
/**
@@ -80,8 +78,8 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
* @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 SlingContext(final SlingContextCallback afterSetUpCallback, final SlingContextCallback beforeTearDownCallback) {
- this(afterSetUpCallback, beforeTearDownCallback, null);
+ public SlingContext(final ContextCallback<?> afterSetUpCallback, final ContextCallback<?> beforeTearDownCallback) {
+ this(new CallbackParams(afterSetUpCallback, beforeTearDownCallback), null, null);
}
/**
@@ -90,29 +88,22 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
* @param beforeTearDownCallback Allows the application to register an own callback function that is called before the built-in teardown rules are executed.
* @param resourceResolverType Resource resolver type.
*/
- public SlingContext(final SlingContextCallback afterSetUpCallback, final SlingContextCallback beforeTearDownCallback,
+ public SlingContext(final ContextCallback<?> afterSetUpCallback, final ContextCallback<?> beforeTearDownCallback,
final ResourceResolverType resourceResolverType) {
- this(null, afterSetUpCallback, beforeTearDownCallback, null, null, resourceResolverType);
+ this(new CallbackParams(afterSetUpCallback, beforeTearDownCallback), null, resourceResolverType);
}
/**
* Initialize Sling context with resource resolver type.
- * @param beforeSetUpCallback Allows the application to register an own callback function that is called before 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.
- * @param beforeTearDownCallback Allows the application to register an own callback function that is called before the built-in teardown rules are executed.
- * @param afterTearDownCallback Allows the application to register an own callback function that is after before the built-in teardown rules are executed.
+ * @param callbackParams Callback parameters
* @param resourceResolverFactoryActivatorProps Allows to override OSGi configuration parameters for the Resource Resolver Factory Activator service.
* @param resourceResolverType Resource resolver type.
*/
- SlingContext(final SlingContextCallback beforeSetUpCallback, final SlingContextCallback afterSetUpCallback,
- final SlingContextCallback beforeTearDownCallback, final SlingContextCallback afterTearDownCallback,
+ SlingContext(final CallbackParams callbackParams,
final Map<String, Object> resourceResolverFactoryActivatorProps,
final ResourceResolverType resourceResolverType) {
- this.beforeSetUpCallback = beforeSetUpCallback;
- this.afterSetUpCallback = afterSetUpCallback;
- this.beforeTearDownCallback = beforeTearDownCallback;
- this.afterTearDownCallback = afterTearDownCallback;
+ this.callbackParams = callbackParams;
setResourceResolverFactoryActivatorProps(resourceResolverFactoryActivatorProps);
// set resource resolver type in parent context
@@ -141,40 +132,52 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
return this.delegate.apply(base, description);
}
+ @SuppressWarnings("unchecked")
private void executeBeforeSetUpCallback() {
- if (this.beforeSetUpCallback != null) {
+ if (callbackParams.beforeSetUpCallback != null) {
try {
- this.beforeSetUpCallback.execute(this);
+ 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 (this.afterSetUpCallback != null) {
+ if (callbackParams.afterSetUpCallback != null) {
try {
- this.afterSetUpCallback.execute(this);
+ 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 (this.beforeTearDownCallback != null) {
+ if (callbackParams.beforeTearDownCallback != null) {
try {
- this.beforeTearDownCallback.execute(this);
+ 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 (this.afterTearDownCallback != null) {
+ if (callbackParams.afterTearDownCallback != null) {
try {
- this.afterTearDownCallback.execute(this);
+ 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/sling/junit/SlingContextBuilder.java b/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextBuilder.java
index 62080fa..38adb2c 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextBuilder.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextBuilder.java
@@ -20,6 +20,7 @@ package org.apache.sling.testing.mock.sling.junit;
import java.util.Map;
+import org.apache.sling.testing.mock.osgi.junit.ContextCallback;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
/**
@@ -27,11 +28,8 @@ import org.apache.sling.testing.mock.sling.ResourceResolverType;
*/
public final class SlingContextBuilder {
+ private final CallbackParams callbackParams = new CallbackParams();
private ResourceResolverType resourceResolverType;
- private SlingContextCallback beforeSetUpCallback;
- private SlingContextCallback afterSetUpCallback;
- private SlingContextCallback beforeTearDownCallback;
- private SlingContextCallback afterTearDownCallback;
private Map<String, Object> resourceResolverFactoryActivatorProps;
/**
@@ -57,11 +55,19 @@ public final class SlingContextBuilder {
}
/**
+ * @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 SlingContextBuilder 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 SlingContextBuilder beforeSetUp(SlingContextCallback beforeSetUpCallback) {
- this.beforeSetUpCallback = beforeSetUpCallback;
+ public SlingContextBuilder beforeSetUp(ContextCallback... beforeSetUpCallback) {
+ callbackParams.beforeSetUpCallback = beforeSetUpCallback;
return this;
}
@@ -69,8 +75,8 @@ public final class SlingContextBuilder {
* @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 SlingContextBuilder afterSetUp(SlingContextCallback afterSetUpCallback) {
- this.afterSetUpCallback = afterSetUpCallback;
+ public SlingContextBuilder afterSetUp(ContextCallback... afterSetUpCallback) {
+ callbackParams.afterSetUpCallback = afterSetUpCallback;
return this;
}
@@ -78,8 +84,16 @@ public final class SlingContextBuilder {
* @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 SlingContextBuilder beforeTearDown(SlingContextCallback beforeTearDownCallback) {
- this.beforeTearDownCallback = beforeTearDownCallback;
+ public SlingContextBuilder 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 SlingContextBuilder beforeTearDown(ContextCallback... beforeTearDownCallback) {
+ callbackParams.beforeTearDownCallback = beforeTearDownCallback;
return this;
}
@@ -87,8 +101,8 @@ public final class SlingContextBuilder {
* @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 SlingContextBuilder afterTearDown(SlingContextCallback afterTearDownCallback) {
- this.afterTearDownCallback = afterTearDownCallback;
+ public SlingContextBuilder afterTearDown(ContextCallback... afterTearDownCallback) {
+ callbackParams.afterTearDownCallback = afterTearDownCallback;
return this;
}
@@ -106,8 +120,7 @@ public final class SlingContextBuilder {
* @return Build {@link SlingContext} instance.
*/
public SlingContext build() {
- return new SlingContext(this.beforeSetUpCallback, this.afterSetUpCallback,
- this.beforeTearDownCallback, this.afterTearDownCallback,
+ return new SlingContext(this.callbackParams,
this.resourceResolverFactoryActivatorProps,
this.resourceResolverType);
}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextCallback.java b/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextCallback.java
index 247185b..4efdf44 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextCallback.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextCallback.java
@@ -18,22 +18,14 @@
*/
package org.apache.sling.testing.mock.sling.junit;
-import java.io.IOException;
-
-import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.testing.mock.osgi.junit.ContextCallback;
/**
* Callback-interface for application-specific setup and teardown operations to
* customize the {@link SlingContext} JUnit rule.
*/
-public interface SlingContextCallback {
+public interface SlingContextCallback extends ContextCallback<SlingContext> {
- /**
- * Execute callback action
- * @param context Sling context
- * @throws IOException I/O exception
- * @throws PersistenceException Persistence exception
- */
- void execute(SlingContext context) throws IOException, PersistenceException;
+ // specialized version of ContextCallback
}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java b/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
index 93bf32e..3225203 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
@@ -19,5 +19,5 @@
/**
* Rule for providing easy access to Sling context in JUnit tests.
*/
-@org.osgi.annotation.versioning.Version("3.3")
+@org.osgi.annotation.versioning.Version("4.0")
package org.apache.sling.testing.mock.sling.junit;
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java b/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java
index 71e9352..52b73d0 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java
@@ -24,11 +24,8 @@ import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import java.io.IOException;
-
import org.apache.sling.api.adapter.AdapterFactory;
import org.apache.sling.api.adapter.SlingAdaptable;
-import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
@@ -64,7 +61,7 @@ public class SlingContextTest {
.build();
@Before
- public void setUp() throws IOException, PersistenceException {
+ public void setUp() throws Exception {
verify(contextBeforeSetup).execute(context);
verify(contextAfterSetup).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-sling-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.sling-mock-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit 3d5d93e528aec59e7c7eb1c3f6f456e31ba97854
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/sling-mock@1767567 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/pom.xml b/pom.xml
index bd3ea90..3e62264 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>
@@ -261,8 +261,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
- <!-- Update to 3.0.2 to avoid heap space problem -->
- <version>3.0.2</version>
<executions>
<execution>
<goals>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-testing-sling-mock] 11/13: update osgi-mock
dependency
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.sling-mock-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit 28317f0a496d45282c380cb318d76b9696e13c73
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Dec 5 17:47:36 2016 +0000
update osgi-mock dependency
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1772734 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 4b20987..3857e6a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -45,7 +45,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.osgi-mock</artifactId>
- <version>2.1.1-SNAPSHOT</version>
+ <version>2.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-testing-sling-mock] 08/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.sling-mock-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit 99270aa95ed496a2ab46f5bf6f9b5cf32b713687
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/sling-mock@1772466 13f79535-47bb-0310-9956-ffa450edef68
---
.../context/ContextResourceResolverFactory.java | 2 +
.../sling/context/ModelAdapterFactoryUtil.java | 2 +
.../testing/mock/sling/context/UniqueRoot.java | 2 +
.../testing/mock/sling/context/package-info.java | 2 +-
.../testing/mock/sling/junit/CallbackParams.java | 43 ---------
.../testing/mock/sling/junit/SlingContext.java | 100 ++++++---------------
.../mock/sling/junit/SlingContextBuilder.java | 52 ++++++-----
.../mock/sling/junit/SlingContextCallback.java | 6 +-
8 files changed, 70 insertions(+), 139 deletions(-)
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/ContextResourceResolverFactory.java b/src/main/java/org/apache/sling/testing/mock/sling/context/ContextResourceResolverFactory.java
index 65cf6d2..3b61fdb 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/ContextResourceResolverFactory.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/ContextResourceResolverFactory.java
@@ -24,11 +24,13 @@ import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.testing.mock.sling.MockSling;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.osgi.annotation.versioning.ProviderType;
import org.osgi.framework.BundleContext;
/**
* Create resolve resolver instance and initialize it depending on it's type.
*/
+@ProviderType
final class ContextResourceResolverFactory {
private ContextResourceResolverFactory() {
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java b/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java
index e0044a4..478c101 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java
@@ -34,6 +34,7 @@ import java.util.Vector;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.testing.mock.osgi.MockOsgi;
+import org.osgi.annotation.versioning.ProviderType;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
@@ -45,6 +46,7 @@ import org.reflections.Reflections;
/**
* Helper methos for simulating sling models bundle events.
*/
+@ProviderType
final class ModelAdapterFactoryUtil {
static {
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java b/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java
index 39bc2cc..7e897ef 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java
@@ -26,6 +26,7 @@ import org.apache.jackrabbit.JcrConstants;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
+import org.osgi.annotation.versioning.ConsumerType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,6 +38,7 @@ import com.google.common.collect.ImmutableMap;
* where the repository is not cleaned for each test run. This class provides
* unique root paths for each run, and cleans them up when done.
*/
+@ConsumerType
public class UniqueRoot {
private final SlingContextImpl context;
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java b/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
index d5b9338..cae884c 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
@@ -19,5 +19,5 @@
/**
* Sling context implementation for unit tests.
*/
-@org.osgi.annotation.versioning.Version("3.3")
+@org.osgi.annotation.versioning.Version("3.4")
package org.apache.sling.testing.mock.sling.context;
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/junit/CallbackParams.java b/src/main/java/org/apache/sling/testing/mock/sling/junit/CallbackParams.java
deleted file mode 100644
index 680ce04..0000000
--- a/src/main/java/org/apache/sling/testing/mock/sling/junit/CallbackParams.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.testing.mock.sling.junit;
-
-import org.apache.sling.testing.mock.osgi.junit.ContextCallback;
-
-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/sling/junit/SlingContext.java b/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContext.java
index 37cfdcf..bcd5da5 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContext.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContext.java
@@ -20,22 +20,26 @@ package org.apache.sling.testing.mock.sling.junit;
import java.util.Map;
-import org.apache.sling.testing.mock.osgi.junit.ContextCallback;
+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.apache.sling.testing.mock.sling.ResourceResolverType;
import org.apache.sling.testing.mock.sling.context.SlingContextImpl;
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 Sling context objects for unit tests.
* You can use {@link SlingContextBuilder} alternatively to the constructors on this class - it offers
* more options and fine-grained control about setting up the test context.
*/
+@ProviderType
public final class SlingContext extends SlingContextImpl implements TestRule {
- private final CallbackParams callbackParams;
+ private final ContextPlugins plugins;
private final TestRule delegate;
/**
@@ -43,7 +47,7 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
* {@link org.apache.sling.testing.mock.sling.MockSling#DEFAULT_RESOURCERESOLVER_TYPE}.
*/
public SlingContext() {
- this(new CallbackParams(), null, null);
+ this(new ContextPlugins(), null, null);
}
/**
@@ -51,59 +55,65 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
* @param resourceResolverType Resource resolver type.
*/
public SlingContext(final ResourceResolverType resourceResolverType) {
- this(new CallbackParams(), null, resourceResolverType);
+ this(new ContextPlugins(), null, resourceResolverType);
}
/**
* Initialize Sling context with default resource resolver type:
* {@link org.apache.sling.testing.mock.sling.MockSling#DEFAULT_RESOURCERESOLVER_TYPE}.
+ * @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 SlingContext(final ContextCallback<?> afterSetUpCallback) {
- this(new CallbackParams(afterSetUpCallback), null, null);
+ public <T extends OsgiContextImpl> SlingContext(final ContextCallback<T> afterSetUpCallback) {
+ this(new ContextPlugins(afterSetUpCallback), null, null);
}
/**
* Initialize Sling context with resource resolver type.
+ * @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.
* @param resourceResolverType Resource resolver type.
*/
- public SlingContext(final ContextCallback<?> afterSetUpCallback, final ResourceResolverType resourceResolverType) {
- this(new CallbackParams(afterSetUpCallback), null, resourceResolverType);
+ public <T extends OsgiContextImpl> SlingContext(final ContextCallback<T> afterSetUpCallback, final ResourceResolverType resourceResolverType) {
+ this(new ContextPlugins(afterSetUpCallback), null, resourceResolverType);
}
/**
* Initialize Sling context with default resource resolver type:
* {@link org.apache.sling.testing.mock.sling.MockSling#DEFAULT_RESOURCERESOLVER_TYPE}.
+ * @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 SlingContext(final ContextCallback<?> afterSetUpCallback, final ContextCallback<?> beforeTearDownCallback) {
- this(new CallbackParams(afterSetUpCallback, beforeTearDownCallback), null, null);
+ public <U extends OsgiContextImpl, V extends OsgiContextImpl> SlingContext(final ContextCallback<U> afterSetUpCallback, final ContextCallback<V> beforeTearDownCallback) {
+ this(new ContextPlugins(afterSetUpCallback, beforeTearDownCallback), null, null);
}
/**
* Initialize Sling context with resource resolver type.
+ * @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.
* @param resourceResolverType Resource resolver type.
*/
- public SlingContext(final ContextCallback<?> afterSetUpCallback, final ContextCallback<?> beforeTearDownCallback,
+ public <U extends OsgiContextImpl, V extends OsgiContextImpl> SlingContext(final ContextCallback<U> afterSetUpCallback, final ContextCallback<V> beforeTearDownCallback,
final ResourceResolverType resourceResolverType) {
- this(new CallbackParams(afterSetUpCallback, beforeTearDownCallback), null, resourceResolverType);
+ this(new ContextPlugins(afterSetUpCallback, beforeTearDownCallback), null, resourceResolverType);
}
/**
* Initialize Sling context with resource resolver type.
- * @param callbackParams Callback parameters
+ * @param contextPlugins Context plugins
* @param resourceResolverFactoryActivatorProps Allows to override OSGi configuration parameters for the Resource Resolver Factory Activator service.
* @param resourceResolverType Resource resolver type.
*/
- SlingContext(final CallbackParams callbackParams,
+ SlingContext(final ContextPlugins contextPlugins,
final Map<String, Object> resourceResolverFactoryActivatorProps,
final ResourceResolverType resourceResolverType) {
- this.callbackParams = callbackParams;
+ this.plugins = contextPlugins;
setResourceResolverFactoryActivatorProps(resourceResolverFactoryActivatorProps);
// set resource resolver type in parent context
@@ -113,16 +123,16 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
this.delegate = new ExternalResource() {
@Override
protected void before() {
- SlingContext.this.executeBeforeSetUpCallback();
+ plugins.executeBeforeSetUpCallback(SlingContext.this);
SlingContext.this.setUp();
- SlingContext.this.executeAfterSetUpCallback();
+ plugins.executeAfterSetUpCallback(SlingContext.this);
}
@Override
protected void after() {
- SlingContext.this.executeBeforeTearDownCallback();
+ plugins.executeBeforeTearDownCallback(SlingContext.this);
SlingContext.this.tearDown();
- SlingContext.this.executeAfterTearDownCallback();
+ plugins.executeAfterTearDownCallback(SlingContext.this);
}
};
}
@@ -132,56 +142,4 @@ public final class SlingContext extends SlingContextImpl 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/sling/junit/SlingContextBuilder.java b/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextBuilder.java
index 38adb2c..b9ca1c4 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextBuilder.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextBuilder.java
@@ -20,15 +20,20 @@ package org.apache.sling.testing.mock.sling.junit;
import java.util.Map;
-import org.apache.sling.testing.mock.osgi.junit.ContextCallback;
+import org.apache.sling.testing.mock.osgi.context.ContextCallback;
+import org.apache.sling.testing.mock.osgi.context.ContextPlugin;
+import org.apache.sling.testing.mock.osgi.context.ContextPlugins;
+import org.apache.sling.testing.mock.osgi.context.OsgiContextImpl;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.osgi.annotation.versioning.ProviderType;
/**
* Builder class for creating {@link SlingContext} instances with different sets of parameters.
*/
+@ProviderType
public final class SlingContextBuilder {
- private final CallbackParams callbackParams = new CallbackParams();
+ private final ContextPlugins plugins = new ContextPlugins();
private ResourceResolverType resourceResolverType;
private Map<String, Object> resourceResolverFactoryActivatorProps;
@@ -55,54 +60,57 @@ public final class SlingContextBuilder {
}
/**
- * @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 SlingContextBuilder setUp(ContextCallback... afterSetUpCallback) {
- return afterSetUp(afterSetUpCallback);
+ @SafeVarargs
+ public final <T extends OsgiContextImpl> SlingContextBuilder 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 SlingContextBuilder beforeSetUp(ContextCallback... beforeSetUpCallback) {
- callbackParams.beforeSetUpCallback = beforeSetUpCallback;
+ @SafeVarargs
+ public final <T extends OsgiContextImpl> SlingContextBuilder 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 SlingContextBuilder afterSetUp(ContextCallback... afterSetUpCallback) {
- callbackParams.afterSetUpCallback = afterSetUpCallback;
+ @SafeVarargs
+ public final <T extends OsgiContextImpl> SlingContextBuilder 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 SlingContextBuilder 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 SlingContextBuilder beforeTearDown(ContextCallback... beforeTearDownCallback) {
- callbackParams.beforeTearDownCallback = beforeTearDownCallback;
+ @SafeVarargs
+ public final <T extends OsgiContextImpl> SlingContextBuilder 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 SlingContextBuilder afterTearDown(ContextCallback... afterTearDownCallback) {
- callbackParams.afterTearDownCallback = afterTearDownCallback;
+ @SafeVarargs
+ public final <T extends OsgiContextImpl> SlingContextBuilder afterTearDown(ContextCallback<T>... afterTearDownCallback) {
+ plugins.addAfterTearDownCallback(afterTearDownCallback);
return this;
}
@@ -120,7 +128,7 @@ public final class SlingContextBuilder {
* @return Build {@link SlingContext} instance.
*/
public SlingContext build() {
- return new SlingContext(this.callbackParams,
+ return new SlingContext(this.plugins,
this.resourceResolverFactoryActivatorProps,
this.resourceResolverType);
}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextCallback.java b/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextCallback.java
index 4efdf44..79343c3 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextCallback.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextCallback.java
@@ -18,12 +18,14 @@
*/
package org.apache.sling.testing.mock.sling.junit;
-import org.apache.sling.testing.mock.osgi.junit.ContextCallback;
+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 SlingContext} JUnit rule.
*/
+@ConsumerType
public interface SlingContextCallback extends ContextCallback<SlingContext> {
// specialized version of ContextCallback
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-testing-sling-mock] 03/13: update to
released version
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.sling-mock-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit 843e0c8a21f10a4158c713401d3b0d501bdc6395
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Oct 31 11:53:56 2016 +0000
update to released version
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1767256 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index a6f4981..bd3ea90 100644
--- a/pom.xml
+++ b/pom.xml
@@ -150,7 +150,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.resourcebuilder</artifactId>
- <version>1.0.1-SNAPSHOT</version>
+ <version>1.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-testing-sling-mock] 12/13:
[maven-release-plugin] prepare release
org.apache.sling.testing.sling-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.sling-mock-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit 80bc84503f42bc1654ce87af419cd3b314dc12b0
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Dec 5 17:48:06 2016 +0000
[maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-2.2.0
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1772735 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 3857e6a..01c2cfd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,16 +28,16 @@
</parent>
<artifactId>org.apache.sling.testing.sling-mock</artifactId>
- <version>2.1.3-SNAPSHOT</version>
+ <version>2.2.0</version>
<packaging>bundle</packaging>
<name>Apache Sling Testing Sling Mock</name>
<description>Mock implementation of selected Sling APIs.</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock</developerConnection>
- <url>http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.sling-mock-2.2.0</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.sling-mock-2.2.0</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.testing.sling-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-sling-mock] 10/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.sling-mock-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit a7e2fa4c359d0ed15eb92bce719ae9d292252e75
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Dec 5 17:45:31 2016 +0000
fix javadoc errors
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1772729 13f79535-47bb-0310-9956-ffa450edef68
---
.../org/apache/sling/testing/mock/sling/context/SlingContextImpl.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
index 7e1776f..161cf94 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
@@ -363,7 +363,7 @@ public class SlingContextImpl extends OsgiContextImpl {
/**
* Search classpath for given java package names (and sub packages) to scan for and
* register all classes with @Model annotation.
- * @param packageNames Java package name
+ * @param packageName Java package name
*/
public final void addModelsForPackage(String packageName) {
ModelAdapterFactoryUtil.addModelsForPackages(bundleContext(), packageName);
@@ -388,7 +388,7 @@ public class SlingContextImpl extends OsgiContextImpl {
/**
* Search classpath for given class names to scan for and register all classes with @Model annotation.
- * @param classNames Java class names
+ * @param classes Java classes
*/
public final void addModelsForClasses(Class... classes) {
ModelAdapterFactoryUtil.addModelsForClasses(bundleContext(), classes);
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-testing-sling-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.sling-mock-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit df62a8eb7c76ec0d5fd49e212cc1bf1d6af28b97
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/sling-mock@1772326 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 3e62264..4b20987 100644
--- a/pom.xml
+++ b/pom.xml
@@ -45,7 +45,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.osgi-mock</artifactId>
- <version>2.1.0</version>
+ <version>2.1.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-testing-sling-mock] 02/13: update to latest
resourcebuilder snapshot
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.sling-mock-2.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit fa2b952e894b8db7be3e0bcaf7c6091bc45fcc51
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Tue Oct 11 17:01:25 2016 +0000
update to latest resourcebuilder snapshot
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1764307 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 1ac0bac..a6f4981 100644
--- a/pom.xml
+++ b/pom.xml
@@ -150,7 +150,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.resourcebuilder</artifactId>
- <version>1.0.0</version>
+ <version>1.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.