cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1443925 - /cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/OsgiUtilsTest.java
Date Fri, 08 Feb 2013 10:31:39 GMT
Author: davidb
Date: Fri Feb  8 10:31:39 2013
New Revision: 1443925

URL: http://svn.apache.org/r1443925
Log:
Additional unit test for OsgiUtils.

Modified:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/OsgiUtilsTest.java

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/OsgiUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/OsgiUtilsTest.java?rev=1443925&r1=1443924&r2=1443925&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/OsgiUtilsTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/OsgiUtilsTest.java
Fri Feb  8 10:31:39 2013
@@ -31,6 +31,7 @@ import org.easymock.EasyMock;
 import org.easymock.IMocksControl;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.Version;
 import org.osgi.service.packageadmin.ExportedPackage;
@@ -39,85 +40,111 @@ import org.osgi.service.remoteserviceadm
 import org.osgi.service.remoteserviceadmin.RemoteConstants;
 
 public class OsgiUtilsTest extends TestCase {
-
     public void testMultiValuePropertyAsString() {
-        assertEquals(Collections.singleton("hi"), 
-            OsgiUtils.getMultiValueProperty("hi"));            
+        assertEquals(Collections.singleton("hi"),
+            OsgiUtils.getMultiValueProperty("hi"));
     }
-    
+
     public void testMultiValuePropertyAsArray() {
-        assertEquals(Arrays.asList("a", "b"), 
+        assertEquals(Arrays.asList("a", "b"),
                 OsgiUtils.getMultiValueProperty(new String [] {"a", "b"}));
     }
-    
+
     public void testMultiValuePropertyAsCollection() {
         List<String> list = new ArrayList<String>();
         list.add("1");
         list.add("2");
         list.add("3");
-        assertEquals(list, OsgiUtils.getMultiValueProperty(list)); 
+        assertEquals(list, OsgiUtils.getMultiValueProperty(list));
     }
-    
+
     public void testMultiValuePropertyNull() {
-        assertNull(OsgiUtils.getMultiValueProperty(null));            
+        assertNull(OsgiUtils.getMultiValueProperty(null));
     }
-    
-    
+
     public void testGetUUID() {
         BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
         EasyMock.expect(bc.getProperty(EasyMock.eq("org.osgi.framework.uuid"))).andReturn(null).atLeastOnce();
         EasyMock.replay(bc);
         String uuid = OsgiUtils.getUUID(bc);
         assertNotNull(uuid);
-        
+
         assertEquals(System.getProperty("org.osgi.framework.uuid"), uuid);
-        
+
         EasyMock.verify(bc);
     }
-    
-    
-    
+
     public void testGetVersion() {
         IMocksControl c = EasyMock.createNiceControl();
         BundleContext bc = c.createMock(BundleContext.class);
         ServiceReference sref = c.createMock(ServiceReference.class);
         PackageAdmin pa = c.createMock(PackageAdmin.class);
         Bundle b = c.createMock(Bundle.class);
-        
+
         EasyMock.expect(bc.getServiceReference(EasyMock.eq(PackageAdmin.class.getName()))).andReturn(sref);
         EasyMock.expect(bc.getService(EasyMock.eq(sref))).andReturn(pa);
-        
+
         Class<?> iClass = CharSequence.class;
-            
+
         c.replay();
         // version 0.0.0 because of missing bundle
-        
+
         assertEquals("0.0.0", OsgiUtils.getVersion(iClass, bc));
-        
+
         c.verify();
         c.reset();
-        // version 1.2.3 ... 
-        
+        // version 1.2.3 ...
+
         EasyMock.expect(bc.getServiceReference(EasyMock.eq(PackageAdmin.class.getName()))).andReturn(sref);
         EasyMock.expect(bc.getService(EasyMock.eq(sref))).andReturn(pa);
         EasyMock.expect(pa.getBundle(EasyMock.eq(iClass))).andReturn(b);
-        
+
         ExportedPackage[] exP = new ExportedPackage[] {new MyExportedPackage(iClass.getPackage(),
"1.2.3"),
-                                                       new MyExportedPackage(String.class.getPackage(),
"4.5.6") }; 
-        
+                                                       new MyExportedPackage(String.class.getPackage(),
"4.5.6") };
+
         EasyMock.expect(pa.getExportedPackages(EasyMock.eq(b))).andReturn(exP).atLeastOnce();
-        
+
         c.replay();
         assertEquals("1.2.3", OsgiUtils.getVersion(iClass, bc));
         c.verify();
     }
-    
-    
+
+    public void testOverlayProperties() {
+        Map<String, Object> sProps = new HashMap<String, Object>();
+        Map<String, Object> aProps = new HashMap<String, Object>();
+
+        OsgiUtils.overlayProperties(sProps, aProps);
+        assertEquals(0, sProps.size());
+
+        sProps.put("aaa", "aval");
+        sProps.put("bbb", "bval");
+        sProps.put(Constants.OBJECTCLASS, new String[] {"X"});
+        sProps.put(Constants.SERVICE_ID, 17L);
+
+        aProps.put("AAA", "achanged");
+        aProps.put("CCC", "CVAL");
+        aProps.put(Constants.OBJECTCLASS, new String[] {"Y"});
+        aProps.put(Constants.SERVICE_ID.toUpperCase(), 51L);
+
+        Map<String, Object> aPropsOrg = new HashMap<String, Object>(aProps);
+        OsgiUtils.overlayProperties(sProps, aProps);
+        assertEquals("The additional properties should not be modified", aPropsOrg, aProps);
+
+        assertEquals(5, sProps.size());
+        assertEquals("achanged", sProps.get("aaa"));
+        assertEquals("bval", sProps.get("bbb"));
+        assertEquals("CVAL", sProps.get("CCC"));
+        assertTrue("Should not be possible to override the objectClass property",
+                Arrays.equals(new String[] {"X"}, (Object[]) sProps.get(Constants.OBJECTCLASS)));
+        assertEquals("Should not be possible to override the service.id property",
+                17L, sProps.get(Constants.SERVICE_ID));
+    }
+
     private static class MyExportedPackage implements ExportedPackage {
 
         Package package1;
         String version;
-        
+
         public MyExportedPackage(Package package1, String version) {
             this.package1 = package1;
             this.version = version;
@@ -146,20 +173,20 @@ public class OsgiUtilsTest extends TestC
         public boolean isRemovalPending() {
             return false;
         }
-        
+
     }
-    
-    
+
+
     public void testGetProperty() {
-        
+
         Map<String, Object> p = new HashMap<String, Object>();
         p.put(RemoteConstants.ENDPOINT_ID, "http://google.de");
         p.put("notAString", new Object());
         p.put(org.osgi.framework.Constants.OBJECTCLASS, new String[]{"my.class"});
         p.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, new String[]{"my.config"});
-        
+
         EndpointDescription ep = new EndpointDescription(p);
-        
+
         assertNull(OsgiUtils.getProperty(ep, "unkownProp"));
         assertEquals(p.get(RemoteConstants.ENDPOINT_ID), OsgiUtils.getProperty(ep, RemoteConstants.ENDPOINT_ID));
         assertEquals(null, OsgiUtils.getProperty(ep, "notAString"));



Mime
View raw message