You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2020/09/11 16:17:05 UTC
[aries-jax-rs-whiteboard] 01/06: [ARIES-2001] Add test to assert
the service is released just after introspection
This is an automated email from the ASF dual-hosted git repository.
csierra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-jax-rs-whiteboard.git
commit eafb9443f6651c9c57f5e10aa3d7a4e84c119289
Author: Carlos Sierra Andrés <ca...@liferay.com>
AuthorDate: Fri Sep 11 13:49:03 2020 +0200
[ARIES-2001] Add test to assert the service is released just after introspection
---
jax-rs.itests/src/main/java/test/JaxrsTest.java | 53 +++++++++++++++++++++++--
1 file changed, 50 insertions(+), 3 deletions(-)
diff --git a/jax-rs.itests/src/main/java/test/JaxrsTest.java b/jax-rs.itests/src/main/java/test/JaxrsTest.java
index 13d621f..32688b8 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -49,9 +49,7 @@ import org.apache.cxf.jaxrs.ext.ContextProvider;
import org.apache.cxf.message.Message;
import org.junit.Ignore;
import org.junit.Test;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.*;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
@@ -1941,6 +1939,55 @@ public class JaxrsTest extends TestHelper {
}
@Test
+ public void testPrototypeScopedAddonIsReleasedAsSoonAsItIsRegistered() {
+ assertEquals(0, getRuntimeDTO().applicationDTOs.length);
+ assertEquals(0, getRuntimeDTO().failedApplicationDTOs.length);
+
+ final AtomicInteger getServiceInvocations = new AtomicInteger();
+ final AtomicInteger ungetServiceInvocations = new AtomicInteger();
+
+ PrototypeServiceFactory<Object> prototypeServiceFactory =
+ new PrototypeServiceFactory<Object>() {
+ @Override
+ public Object getService(
+ Bundle bundle,
+ ServiceRegistration<Object> registration) {
+
+ getServiceInvocations.incrementAndGet();
+
+ return new TestAddon();
+ }
+
+ @Override
+ public void ungetService(
+ Bundle bundle, ServiceRegistration<Object> registration,
+ Object service) {
+
+ ungetServiceInvocations.incrementAndGet();
+ }
+ };
+
+ Dictionary<String, Object> properties = new Hashtable<>();
+
+ properties.put(JAX_RS_RESOURCE, "true");
+
+ ServiceRegistration<?> serviceRegistration =
+ bundleContext.registerService(
+ Object.class, (ServiceFactory<?>) prototypeServiceFactory,
+ properties);
+
+ try {
+ assertEquals(1, getServiceInvocations.get());
+ assertEquals(1, ungetServiceInvocations.get());
+ } finally {
+ serviceRegistration.unregister();
+ }
+
+ assertEquals(1, getServiceInvocations.get());
+ assertEquals(1, ungetServiceInvocations.get());
+ }
+
+ @Test
public void testRegisterApplicationWithOnlyExtensions() {
ServiceRegistration<Application> serviceRegistration =
registerApplication(new Application() {