You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by da...@apache.org on 2009/03/08 22:54:06 UTC

svn commit: r751540 - in /cxf/dosgi/trunk/discovery/local/src: main/java/org/apache/cxf/dosgi/discovery/local/ test/java/org/apache/cxf/dosgi/discovery/local/ test/resources/

Author: davidb
Date: Sun Mar  8 21:54:06 2009
New Revision: 751540

URL: http://svn.apache.org/viewvc?rev=751540&view=rev
Log:
Additional tests for the local discovery utils.

Added:
    cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java   (with props)
    cxf/dosgi/trunk/discovery/local/src/test/resources/rs1.xml   (with props)
    cxf/dosgi/trunk/discovery/local/src/test/resources/rs2.xml   (with props)
Modified:
    cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java

Modified: cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java?rev=751540&r1=751539&r2=751540&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java (original)
+++ cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java Sun Mar  8 21:54:06 2009
@@ -79,7 +79,7 @@
     }
     
     @SuppressWarnings("unchecked")
-    public static List<Element> getAllDescriptionElements(Bundle b) {
+    static List<Element> getAllDescriptionElements(Bundle b) {
         Object directory = null;
         
         Dictionary headers = b.getHeaders();

Added: cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java?rev=751540&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java (added)
+++ cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java Sun Mar  8 21:54:06 2009
@@ -0,0 +1,107 @@
+package org.apache.cxf.dosgi.discovery.local;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.easymock.EasyMock;
+import org.jdom.Element;
+import org.jdom.Namespace;
+import org.osgi.framework.Bundle;
+import org.osgi.service.discovery.ServiceEndpointDescription;
+
+public class LocalDiscoveryUtilsTest extends TestCase {
+    public void testNoRemoteServicesXMLFiles() {
+        Bundle b = EasyMock.createNiceMock(Bundle.class);
+        EasyMock.replay(b);
+        
+        List<Element> rsElements = LocalDiscoveryUtils.getAllDescriptionElements(b);
+        assertEquals(0, rsElements.size());        
+    }
+    
+    public void testRemoteServicesXMLFiles() {
+        URL rs1URL = getClass().getResource("/rs1.xml");
+        
+        Bundle b = EasyMock.createNiceMock(Bundle.class);
+        EasyMock.expect(b.findEntries(
+            EasyMock.eq("OSGI-INF/remote-service"), 
+            EasyMock.eq("*.xml"), EasyMock.anyBoolean())).andReturn(
+                Collections.enumeration(Arrays.asList(rs1URL))).anyTimes();
+        EasyMock.replay(b);
+        
+        List<Element> rsElements = LocalDiscoveryUtils.getAllDescriptionElements(b);
+        assertEquals(2, rsElements.size());
+        Namespace ns = Namespace.getNamespace("http://www.osgi.org/xmlns/sd/v1.0.0");
+        assertEquals("SomeService", rsElements.get(0).getChild("provide", ns).getAttributeValue("interface"));
+        assertEquals("SomeOtherService", rsElements.get(1).getChild("provide", ns).getAttributeValue("interface"));
+    }
+    
+    public void testMultiRemoteServicesXMLFiles() {
+        URL rs1URL = getClass().getResource("/rs1.xml");
+        URL rs2URL = getClass().getResource("/rs2.xml");
+        
+        Bundle b = EasyMock.createNiceMock(Bundle.class);
+        EasyMock.expect(b.findEntries(
+            EasyMock.eq("OSGI-INF/remote-service"), 
+            EasyMock.eq("*.xml"), EasyMock.anyBoolean())).andReturn(
+                Collections.enumeration(Arrays.asList(rs1URL, rs2URL))).anyTimes();
+        EasyMock.replay(b);
+        
+        List<Element> rsElements = LocalDiscoveryUtils.getAllDescriptionElements(b);
+        assertEquals(3, rsElements.size());
+        Namespace ns = Namespace.getNamespace("http://www.osgi.org/xmlns/sd/v1.0.0");
+        assertEquals("SomeService", rsElements.get(0).getChild("provide", ns).getAttributeValue("interface"));
+        assertEquals("SomeOtherService", rsElements.get(1).getChild("provide", ns).getAttributeValue("interface"));
+        assertEquals("org.example.Service", rsElements.get(2).getChild("provide", ns).getAttributeValue("interface"));
+    }
+    
+    @SuppressWarnings("unchecked")
+    public void testRemoteServicesXMLFileAlternateLocation() {
+        URL rs1URL = getClass().getResource("/rs1.xml");
+        Dictionary headers = new Hashtable();        
+        headers.put("Remote-Service", "META-INF/osgi");
+        headers.put("Bundle-Name", "testing bundle");
+        
+        Bundle b = EasyMock.createNiceMock(Bundle.class);
+        EasyMock.expect(b.getHeaders()).andReturn(headers).anyTimes();
+        EasyMock.expect(b.findEntries(
+            EasyMock.eq("META-INF/osgi"), 
+            EasyMock.eq("*.xml"), EasyMock.anyBoolean())).andReturn(
+                Collections.enumeration(Arrays.asList(rs1URL))).anyTimes();
+        EasyMock.replay(b);
+        
+        List<Element> rsElements = LocalDiscoveryUtils.getAllDescriptionElements(b);
+        assertEquals(2, rsElements.size());
+        Namespace ns = Namespace.getNamespace("http://www.osgi.org/xmlns/sd/v1.0.0");
+        assertEquals("SomeService", rsElements.get(0).getChild("provide", ns).getAttributeValue("interface"));
+        assertEquals("SomeOtherService", rsElements.get(1).getChild("provide", ns).getAttributeValue("interface"));
+    }
+    
+    public void testAllRemoteReferences() {
+        URL rs1URL = getClass().getResource("/rs1.xml");
+        
+        Bundle b = EasyMock.createNiceMock(Bundle.class);
+        EasyMock.expect(b.findEntries("OSGI-INF/remote-service", "*.xml", false)).
+                andReturn(Collections.enumeration(Arrays.asList(rs1URL)));
+        EasyMock.replay(b);
+        
+        List<ServiceEndpointDescription> seds = LocalDiscoveryUtils.getAllRemoteReferences(b);
+        assertEquals(2, seds.size());
+        
+        Map<String, Object> sed1Props = new HashMap<String, Object>();
+        sed1Props.put("osgi.remote.requires.intents", "confidentiality");
+        ServiceEndpointDescription sed1 = new ServiceEndpointDescriptionImpl(
+                Arrays.asList("SomeService"), sed1Props);
+        ServiceEndpointDescription sed2 = new ServiceEndpointDescriptionImpl(
+                Arrays.asList("SomeOtherService", "WithSomeSecondInterface"));
+        assertTrue(seds.contains(sed1));
+        assertTrue(seds.contains(sed2));
+    }
+}

Propchange: cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/dosgi/trunk/discovery/local/src/test/resources/rs1.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/resources/rs1.xml?rev=751540&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/test/resources/rs1.xml (added)
+++ cxf/dosgi/trunk/discovery/local/src/test/resources/rs1.xml Sun Mar  8 21:54:06 2009
@@ -0,0 +1,31 @@
+<?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.
+-->
+
+<service-descriptions xmlns="http://www.osgi.org/xmlns/sd/v1.0.0">
+  <service-description>
+    <provide interface="SomeService" />
+    <property name="osgi.remote.requires.intents">confidentiality</property>
+  </service-description>
+  <service-description>
+    <provide interface="SomeOtherService" />
+    <provide interface="WithSomeSecondInterface" />
+  </service-description>
+</service-descriptions>

Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/rs1.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/rs1.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/rs1.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cxf/dosgi/trunk/discovery/local/src/test/resources/rs2.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/resources/rs2.xml?rev=751540&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/test/resources/rs2.xml (added)
+++ cxf/dosgi/trunk/discovery/local/src/test/resources/rs2.xml Sun Mar  8 21:54:06 2009
@@ -0,0 +1,28 @@
+<?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.
+-->
+
+<service-descriptions xmlns="http://www.osgi.org/xmlns/sd/v1.0.0">
+  <service-description>
+    <provide interface="org.example.Service" />
+    <property name="service.intents">confidentiality.message integrity</property>
+    <property name="osgi.remote.interfaces">*</property>
+  </service-description>
+</service-descriptions>

Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/rs2.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/rs2.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/rs2.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml