Merge branch 'master' into dynamic-reference-properties
diff --git a/README.md b/README.md
index c0fdcb1..b34861e 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,7 @@
+[<img src="http://sling.apache.org/res/logos/sling.png"/>](http://sling.apache.org)
+
+ [![Build Status](https://builds.apache.org/buildStatus/icon?job=sling-org-apache-sling-testing-osgi-mock-1.8)](https://builds.apache.org/view/S-Z/view/Sling/job/sling-org-apache-sling-testing-osgi-mock-1.8) [![Test Status](https://img.shields.io/jenkins/t/https/builds.apache.org/view/S-Z/view/Sling/job/sling-org-apache-sling-testing-osgi-mock-1.8.svg)](https://builds.apache.org/view/S-Z/view/Sling/job/sling-org-apache-sling-testing-osgi-mock-1.8/test_results_analyzer/) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.sling/org.apache.sling.testing.osgi-mock/badge.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.apache.sling%22%20a%3A%22org.apache.sling.testing.osgi-mock%22) [![JavaDocs](https://www.javadoc.io/badge/org.apache.sling/org.apache.sling.testing.osgi-mock.svg)](https://www.javadoc.io/doc/org.apache.sling/org.apache.sling.testing.osgi-mock) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) [![testing](https://sling.apache.org/badges/group-testing.svg)](https://github.com/apache/sling-aggregator/blob/master/docs/groups/testing.md)
+
# Apache Sling Testing OSGi Mock
This module is part of the [Apache Sling](https://sling.apache.org) project.
diff --git a/pom.xml b/pom.xml
index 2699f34..f9331a1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -108,6 +108,10 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>annotations</artifactId>
+ </exclusion>
</exclusions>
</dependency>
@@ -131,6 +135,12 @@
<artifactId>org.apache.felix.scr</artifactId>
<version>2.0.4</version>
<scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>animal-sniffer-annotations</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
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 cd93b0b..57b8c3b 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
@@ -61,14 +61,14 @@
else {
this.service = service;
}
-
+
+ readOsgiMetadata();
+
this.properties = properties != null ? properties : new Hashtable<String,Object>();
this.properties.put(Constants.SERVICE_ID, this.serviceId);
- this.properties.put(Constants.OBJECTCLASS, clazzes);
+ this.properties.put(Constants.OBJECTCLASS, this.clazzes.toArray(new String[this.clazzes.size()]));
this.serviceReference = new MockServiceReference<T>(bundle, this);
this.bundleContext = bundleContext;
-
- readOsgiMetadata();
}
@Override
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java b/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java
index 36fd122..d4bee18 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java
@@ -35,7 +35,10 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.util.tracker.ServiceTracker;
public class OsgiContextImplTest {
@@ -161,4 +164,34 @@
context.registerInjectActivateService(new Object());
}
+ @Test
+ public void testServiceTracker() {
+ BundleContext bundleContext = context.bundleContext();
+ ServiceTracker<MyService, MyService> tracker = new ServiceTracker<>(bundleContext, MyService.class, null);
+ tracker.open();
+
+ context.registerInjectActivateService(new MyComponent());
+
+ assertNotNull(tracker.getServiceReferences());
+ assertEquals(1, tracker.getServiceReferences().length);
+
+ tracker.close();
+ }
+
+ @Component(
+ service = MyService.class
+ )
+ public static class MyComponent implements MyService {
+
+ @Override
+ public String foo() {
+ return "bar";
+ }
+ }
+
+ public interface MyService {
+
+ String foo();
+
+ }
}
diff --git a/src/test/resources/OSGI-INF/org.apache.sling.testing.mock.osgi.context.OsgiContextImplTest.xml b/src/test/resources/OSGI-INF/org.apache.sling.testing.mock.osgi.context.OsgiContextImplTest.xml
new file mode 100644
index 0000000..d6b9d1c
--- /dev/null
+++ b/src/test/resources/OSGI-INF/org.apache.sling.testing.mock.osgi.context.OsgiContextImplTest.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0">
+ <scr:component name="org.apache.sling.testing.mock.osgi.context.OsgiContextImplTest$MyComponent">
+ <implementation class="org.apache.sling.testing.mock.osgi.context.OsgiContextImplTest$MyComponent"/>
+ <service>
+ <provide interface="org.apache.sling.testing.mock.osgi.context.OsgiContextImplTest$MyService"/>
+ </service>
+ </scr:component>
+</components>
\ No newline at end of file