[ 
https://issues.apache.org/jira/browse/SLING-7550?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16406043#comment-16406043
 ] 

ASF GitHub Bot commented on SLING-7550:
---------------------------------------

stefanseifert closed pull request #2: SLING-7550 Return services even when 
class param is null in
URL: https://github.com/apache/sling-org-apache-sling-testing-osgi-mock/pull/2
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java 
b/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
index 7a2e87d..095d3dc 100644
--- 
a/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
+++ 
b/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
@@ -93,7 +93,7 @@ public void unregister() {
 
     boolean matches(final String clazz, final String filter) throws 
InvalidSyntaxException {
         // ignore filter for now
-        return this.clazzes.contains(clazz)
+        return (clazz == null || this.clazzes.contains(clazz))
                 && (filter == null || new 
FilterImpl(filter).match(properties));
     }
     
diff --git 
a/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java 
b/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
index 1760ced..e031f72 100644
--- 
a/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
+++ 
b/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
@@ -297,6 +297,18 @@ public void testGetServiceOrderWithoutRanking() {
         
         bundleContext.ungetService(ref);
     }
+    
+    @Test
+    public void testGetServicesWithNoClassOnlyFilter() throws 
InvalidSyntaxException {
+        bundleContext.registerService(String.class, "service1", 
testProperty());
+        bundleContext.registerService(Long.class, new Long(2), testProperty());
+        bundleContext.registerService(Integer.class, new Integer(9), 
testProperty());
+        
+        // should return service with lowest service id = which was registered 
first
+        ServiceReference[] refs = 
bundleContext.getServiceReferences((String)null, "(prop1=value1)");
+        assertNotNull(refs);
+        assertEquals(3, refs.length);
+    }
 
     private static Dictionary<String, Object> ranking(final Integer 
serviceRanking) {
         Dictionary<String, Object> props = new Hashtable<String, Object>();
@@ -305,5 +317,11 @@ public void testGetServiceOrderWithoutRanking() {
         }
         return props;
     }
+    
+    private static Dictionary<String, Object> testProperty() {
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("prop1", "value1");
+        return props;
+    }
 
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> MockBundleContext does not get service references when class is null and 
> filter is non-null
> -------------------------------------------------------------------------------------------
>
>                 Key: SLING-7550
>                 URL: https://issues.apache.org/jira/browse/SLING-7550
>             Project: Sling
>          Issue Type: Bug
>          Components: Testing
>    Affects Versions: Testing OSGi Mock 2.3.6
>            Reporter: Sufyan Haroon
>            Assignee: Stefan Seifert
>            Priority: Major
>             Fix For: Testing OSGi Mock 2.3.8
>
>
> When invoking BundleContext 
> [api|https://osgi.org/javadoc/r4v43/core/org/osgi/framework/BundleContext.html#getServiceReferences(java.lang.String,
>  java.lang.String)], when the class parameter is specified as null and filter 
> param is non-null, it is expected to return reference of all services which 
> satisfy the filter regardless of their class. 
> When the same api is invoked in MockBundleContext, it does not returns any 
> service references when class param is null and filter param is non-null. 
> MockBundleContextshould behave is a way which is similar to original 
> implementation



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to