cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [1/3] cxf-dosgi git commit: [DOSGI-229] Refactor api and fix some issues
Date Thu, 03 Mar 2016 14:42:13 GMT
Repository: cxf-dosgi
Updated Branches:
  refs/heads/master ea2b3dc2d -> b5f02ff5a


http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/b5f02ff5/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/EventProducerTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/EventProducerTest.java
b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/EventProducerTest.java
index eba5400..98b4cbf 100644
--- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/EventProducerTest.java
+++ b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/EventProducerTest.java
@@ -18,13 +18,13 @@
  */
 package org.apache.cxf.dosgi.dsw.service;
 
-import java.io.Closeable;
 import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.UUID;
 
+import org.apache.cxf.dosgi.dsw.handlers.ServerWrapper;
 import org.easymock.EasyMock;
 import org.easymock.IAnswer;
 import org.junit.Assert;
@@ -40,22 +40,24 @@ import org.osgi.service.remoteserviceadmin.ExportReference;
 import org.osgi.service.remoteserviceadmin.ExportRegistration;
 import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
 
+@SuppressWarnings({"rawtypes", "unchecked"})
 public class EventProducerTest {
-
+    
+    
     @Test
     public void testPublishNotification() throws Exception {
         RemoteServiceAdminCore remoteServiceAdminCore = EasyMock.createNiceMock(RemoteServiceAdminCore.class);
         EasyMock.replay(remoteServiceAdminCore);
 
-        final EndpointDescription endpoint = EasyMock.createNiceMock(EndpointDescription.class);
-        EasyMock.expect(endpoint.getServiceId()).andReturn(Long.MAX_VALUE).anyTimes();
+        final EndpointDescription epd = EasyMock.createNiceMock(EndpointDescription.class);
+        EasyMock.expect(epd.getServiceId()).andReturn(Long.MAX_VALUE).anyTimes();
         final String uuid = UUID.randomUUID().toString();
-        EasyMock.expect(endpoint.getFrameworkUUID()).andReturn(uuid).anyTimes();
-        EasyMock.expect(endpoint.getId()).andReturn("foo://bar").anyTimes();
+        EasyMock.expect(epd.getFrameworkUUID()).andReturn(uuid).anyTimes();
+        EasyMock.expect(epd.getId()).andReturn("foo://bar").anyTimes();
         final List<String> interfaces = Arrays.asList("org.foo.Bar", "org.boo.Far");
-        EasyMock.expect(endpoint.getInterfaces()).andReturn(interfaces).anyTimes();
-        EasyMock.expect(endpoint.getConfigurationTypes()).andReturn(Arrays.asList("org.apache.cxf.ws")).anyTimes();
-        EasyMock.replay(endpoint);
+        EasyMock.expect(epd.getInterfaces()).andReturn(interfaces).anyTimes();
+        EasyMock.expect(epd.getConfigurationTypes()).andReturn(Arrays.asList("org.apache.cxf.ws")).anyTimes();
+        EasyMock.replay(epd);
         final ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class);
         EasyMock.replay(sref);
 
@@ -80,7 +82,7 @@ public class EventProducerTest {
                 Assert.assertEquals("test.bundle", event.getProperty("bundle.symbolicname"));
                 Assert.assertEquals(new Version(1, 2, 3, "test"), event.getProperty("bundle.version"));
                 Assert.assertNull(event.getProperty("cause"));
-                Assert.assertEquals(endpoint, event.getProperty("export.registration"));
+                Assert.assertEquals(epd, event.getProperty("export.registration"));
 
                 Assert.assertEquals(Long.MAX_VALUE, event.getProperty("service.remote.id"));
                 Assert.assertEquals(uuid, event.getProperty("service.remote.uuid"));
@@ -95,7 +97,7 @@ public class EventProducerTest {
                 Assert.assertEquals(RemoteServiceAdminEvent.EXPORT_REGISTRATION, rsae.getType());
                 Assert.assertSame(bundle, rsae.getSource());
                 ExportReference er = rsae.getExportReference();
-                Assert.assertSame(endpoint, er.getExportedEndpoint());
+                Assert.assertSame(epd, er.getExportedEndpoint());
                 Assert.assertSame(sref, er.getExportedService());
 
                 return null;
@@ -113,9 +115,8 @@ public class EventProducerTest {
         EasyMock.expect(bc.getService(eaSref)).andReturn(ea).anyTimes();
         EasyMock.replay(bc);
         EventProducer eventProducer = new EventProducer(bc);
-
-        ExportRegistrationImpl ereg = new ExportRegistrationImpl(sref, endpoint, remoteServiceAdminCore,

-                                                                 (Closeable)null);
+        ServerWrapper endpoint = new ServerWrapper(epd, null);
+        ExportRegistrationImpl ereg = new ExportRegistrationImpl(sref, endpoint, remoteServiceAdminCore);
         eventProducer.publishNotification(ereg);
     }
 
@@ -179,7 +180,7 @@ public class EventProducerTest {
         EasyMock.replay(bc);
         EventProducer eventProducer = new EventProducer(bc);
 
-        ExportRegistrationImpl ereg = new ExportRegistrationImpl(sref, endpoint, rsaCore,
exportException);
+        ExportRegistrationImpl ereg = new ExportRegistrationImpl(rsaCore, exportException);
         eventProducer.publishNotification(Arrays.<ExportRegistration>asList(ereg));
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/b5f02ff5/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java
b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java
index f714eca..2900ce6 100644
--- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java
+++ b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java
@@ -18,7 +18,6 @@
  */
 package org.apache.cxf.dosgi.dsw.service;
 
-import java.io.Closeable;
 import java.lang.reflect.Field;
 import java.util.Arrays;
 import java.util.Collection;
@@ -28,10 +27,11 @@ import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.cxf.dosgi.dsw.api.ConfigurationTypeHandler;
-import org.apache.cxf.dosgi.dsw.api.ExportResult;
+import org.apache.cxf.dosgi.dsw.api.DistributionProvider;
+import org.apache.cxf.dosgi.dsw.api.Endpoint;
 import org.apache.cxf.dosgi.dsw.handlers.ConfigTypeHandlerFactory;
 import org.apache.cxf.dosgi.dsw.handlers.HttpServiceManager;
+import org.apache.cxf.dosgi.dsw.handlers.ServerWrapper;
 import org.apache.cxf.dosgi.dsw.qos.DefaultIntentMapFactory;
 import org.apache.cxf.dosgi.dsw.qos.IntentManager;
 import org.apache.cxf.dosgi.dsw.qos.IntentManagerImpl;
@@ -58,6 +58,9 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
+@SuppressWarnings({
+    "rawtypes", "unchecked"
+   })
 public class RemoteServiceAdminCoreTest {
 
     @Test
@@ -129,9 +132,10 @@ public class RemoteServiceAdminCoreTest {
 
         RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, configTypeHandlerFactory)
{
             @Override
-            protected void proxifyMatchingInterface(String interfaceName, ImportRegistrationImpl
imReg,
-                                                    ConfigurationTypeHandler handler,
-                                                    BundleContext requestingContext) {
+            protected ImportRegistrationImpl exposeServiceFactory(String interfaceName, 
+                                                                      EndpointDescription
epd,
+                                                                      DistributionProvider
handler) {
+                return new ImportRegistrationImpl(epd, this);
             }
         };
 
@@ -205,13 +209,10 @@ public class RemoteServiceAdminCoreTest {
         Map<String, Object> eProps = new HashMap<String, Object>(sProps);
         eProps.put("endpoint.id", "http://something");
         eProps.put("service.imported.configs", new String[] {"org.apache.cxf.ws"});
-        ExportResult er = new ExportResult(eProps, (Closeable) null);
+        Endpoint er = new ServerWrapper(new EndpointDescription(eProps), null);
 
-        ConfigurationTypeHandler handler = EasyMock.createNiceMock(ConfigurationTypeHandler.class);
-        EasyMock.expect(handler.createServer(sref,
-                                             bc,
-                                             sref.getBundle().getBundleContext(),
-                                             sProps, Runnable.class, svcObject)).andReturn(er).once();
+        DistributionProvider handler = EasyMock.createNiceMock(DistributionProvider.class);
+        EasyMock.expect(handler.createServer(sref, sProps, Runnable.class.getName())).andReturn(er).once();
         EasyMock.replay(handler);
 
         ConfigTypeHandlerFinder handlerFactory = EasyMock.createNiceMock(ConfigTypeHandlerFactory.class);
@@ -254,7 +255,6 @@ public class RemoteServiceAdminCoreTest {
         // Look at the exportedServices data structure
         Field field = RemoteServiceAdminCore.class.getDeclaredField("exportedServices");
         field.setAccessible(true);
-        @SuppressWarnings("unchecked")
         Map<Map<String, Object>, Collection<ExportRegistration>> exportedServices
=
                 (Map<Map<String, Object>, Collection<ExportRegistration>>)
field.get(rsaCore);
 
@@ -304,27 +304,23 @@ public class RemoteServiceAdminCoreTest {
         Map<String, Object> eProps = new HashMap<String, Object>(sProps);
         eProps.put("endpoint.id", "http://something");
         eProps.put("service.imported.configs", new String[] {"org.apache.cxf.ws"});
-        ExportResult er = new ExportResult(eProps, new TestException());
 
-        ConfigurationTypeHandler handler = EasyMock.createNiceMock(ConfigurationTypeHandler.class);
-        EasyMock.expect(handler.createServer(sref, bc, sref.getBundle().getBundleContext(),
-                                             sProps, Runnable.class, svcObject)).andReturn(er);
+        DistributionProvider handler = EasyMock.createMock(DistributionProvider.class);
+        EasyMock.expect(handler.createServer(sref, sProps, Runnable.class.getName())).andThrow(new
TestException());
         EasyMock.replay(handler);
 
-        ConfigTypeHandlerFinder handlerFactory = EasyMock.createNiceMock(ConfigTypeHandlerFactory.class);
+        ConfigTypeHandlerFinder handlerFactory = EasyMock.createMock(ConfigTypeHandlerFactory.class);
         EasyMock.expect(handlerFactory.getHandler(bc, sProps)).andReturn(handler).anyTimes();
         EasyMock.replay(handlerFactory);
         RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, handlerFactory);
 
-        List<ExportRegistration> ereg = rsaCore.exportService(sref, null);
+        List<ExportRegistration> ereg = rsaCore.exportService(sref, sProps);
         assertEquals(1, ereg.size());
         assertTrue(ereg.get(0).getException() instanceof TestException);
-        assertSame(sref, ereg.get(0).getExportReference().getExportedService());
 
         // Look at the exportedServices data structure
         Field field = RemoteServiceAdminCore.class.getDeclaredField("exportedServices");
         field.setAccessible(true);
-        @SuppressWarnings("unchecked")
         Map<Map<String, Object>, Collection<ExportRegistration>> exportedServices
=
                 (Map<Map<String, Object>, Collection<ExportRegistration>>)
field.get(rsaCore);
 
@@ -332,9 +328,6 @@ public class RemoteServiceAdminCoreTest {
         assertEquals("There is 1 export registration",
                 1, exportedServices.values().iterator().next().size());
 
-        // Remove all export registrations from the service bundle
-        rsaCore.removeExportRegistrations(sref.getBundle());
-        assertEquals("No more exported services", 0, exportedServices.size());
     }
 
     private ServiceReference mockServiceReference(final Map<String, Object> sProps)
{
@@ -361,6 +354,6 @@ public class RemoteServiceAdminCoreTest {
     }
 
     @SuppressWarnings("serial")
-    private static class TestException extends Exception {
+    private static class TestException extends RuntimeException {
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/b5f02ff5/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index d529f9d..2ce6c48 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -189,10 +189,10 @@
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-compiler-plugin</artifactId>
-                    <version>2.5.1</version>
+                    <version>3.5.1</version>
                     <configuration>
-                        <source>1.6</source>
-                        <target>1.6</target>
+                        <source>1.7</source>
+                        <target>1.7</target>
                         <maxmem>256M</maxmem>
                         <fork>false</fork>
                     </configuration>

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/b5f02ff5/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/MultiBundleTools.java
----------------------------------------------------------------------
diff --git a/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/MultiBundleTools.java
b/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/MultiBundleTools.java
index 48e87ac..1e4bf39 100644
--- a/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/MultiBundleTools.java
+++ b/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/MultiBundleTools.java
@@ -28,9 +28,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.TreeMap;
-import java.util.jar.Attributes;
-import java.util.jar.JarInputStream;
-import java.util.jar.Manifest;
 
 import org.ops4j.pax.exam.CoreOptions;
 import org.ops4j.pax.exam.Option;
@@ -94,18 +91,8 @@ public final class MultiBundleTools {
 
         for (Map.Entry<Integer, String> entry : bundles.entrySet()) {
             String bundleUri = entry.getValue();
-            URL bundleURL = new URL(bundleUri);
-            JarInputStream bundleJar = new JarInputStream(bundleURL.openStream());
-            Manifest manifest = bundleJar.getManifest();
-            Attributes host = manifest.getAttributes("Fragment-Host");
-            if (host != null) {
-                System.out.println(bundleUri);
-            }
-            bundleJar.close();
-            
             opts.add(CoreOptions.bundle(bundleUri));
         }
-        System.out.println(opts);
         return opts.toArray(new Option[opts.size()]);
     }
 

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/b5f02ff5/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestImportService.java
----------------------------------------------------------------------
diff --git a/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestImportService.java
b/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestImportService.java
index 0f8b0b8..efc334b 100644
--- a/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestImportService.java
+++ b/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestImportService.java
@@ -73,7 +73,7 @@ public class TestImportService extends AbstractDosgiTest {
                 provision(createServiceConsumerBundle()),
                 // increase for debugging
                 systemProperty("org.apache.cxf.dosgi.test.serviceWaitTimeout").value(
-                        System.getProperty("org.apache.cxf.dosgi.test.serviceWaitTimeout",
"20")),
+                        System.getProperty("org.apache.cxf.dosgi.test.serviceWaitTimeout",
"200")),
                 frameworkStartLevel(100),
                 //CoreOptions.vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005")
         };
@@ -110,17 +110,9 @@ public class TestImportService extends AbstractDosgiTest {
         //    a service property.
 
         // Set up a Server in the test
-        ServerFactoryBean factory = new ServerFactoryBean();
-        factory.setServiceClass(GreeterService.class);
-        factory.setAddress("http://localhost:9191/grrr");
-        factory.getServiceFactory().setDataBinding(new AegisDatabinding());
-        factory.setServiceBean(new TestGreeter());
-
         Server server = null;
-        ClassLoader cl = Thread.currentThread().getContextClassLoader();
         try {
-            Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
-            server = factory.create();
+            server = publishTestGreeter();
 
             Dictionary<String, Object> props = new Hashtable<String, Object>();
             props.put("testName", "test1");
@@ -134,6 +126,21 @@ public class TestImportService extends AbstractDosgiTest {
             if (server != null) {
                 server.stop();
             }
+            
+        }
+    }
+
+    private Server publishTestGreeter() {
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
+            ServerFactoryBean factory = new ServerFactoryBean();
+            factory.setServiceClass(GreeterService.class);
+            factory.setAddress("http://localhost:9191/grrr");
+            factory.getServiceFactory().setDataBinding(new AegisDatabinding());
+            factory.setServiceBean(new TestGreeter());
+            return factory.create();
+        } finally {
             Thread.currentThread().setContextClassLoader(cl);
         }
     }


Mime
View raw message