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 2010/01/04 15:25:16 UTC
svn commit: r895639 - in /cxf/dosgi/trunk/discovery/local/src:
main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscovery.java
test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryTest.java
test/resources/ed3.xml test/resources/ed4.xml
Author: davidb
Date: Mon Jan 4 14:25:16 2010
New Revision: 895639
URL: http://svn.apache.org/viewvc?rev=895639&view=rev
Log:
Tests for local discovery
Added:
cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryTest.java (with props)
cxf/dosgi/trunk/discovery/local/src/test/resources/ed3.xml (with props)
cxf/dosgi/trunk/discovery/local/src/test/resources/ed4.xml (with props)
Modified:
cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscovery.java
Modified: cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscovery.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscovery.java?rev=895639&r1=895638&r2=895639&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscovery.java (original)
+++ cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscovery.java Mon Jan 4 14:25:16 2010
@@ -50,9 +50,9 @@
new HashMap<EndpointListener, Collection<String>>();
Map<String, Collection<EndpointListener>> filterToListeners =
new HashMap<String, Collection<EndpointListener>>();
- private final BundleContext bundleContext;
+ final BundleContext bundleContext;
- private ServiceTracker listenerTracker;
+ ServiceTracker listenerTracker;
public LocalDiscovery(BundleContext bc) {
bundleContext = bc;
Added: cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryTest.java?rev=895639&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryTest.java (added)
+++ cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryTest.java Mon Jan 4 14:25:16 2010
@@ -0,0 +1,119 @@
+/**
+ * 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.
+ */
+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.HashSet;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceListener;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+
+public class LocalDiscoveryTest extends TestCase {
+ public void testLocalDiscovery() throws Exception {
+ Filter filter = EasyMock.createMock(Filter.class);
+ EasyMock.replay(filter);
+
+ BundleContext bc = EasyMock.createMock(BundleContext.class);
+ EasyMock.expect(bc.createFilter("(objectClass=org.osgi.service.remoteserviceadmin.EndpointListener)")).andReturn(filter);
+ bc.addServiceListener((ServiceListener) EasyMock.anyObject(),
+ EasyMock.eq("(objectClass=org.osgi.service.remoteserviceadmin.EndpointListener)"));
+ EasyMock.expectLastCall();
+ EasyMock.expect(bc.getServiceReferences("org.osgi.service.remoteserviceadmin.EndpointListener", null)).andReturn(null);
+ bc.addBundleListener((BundleListener) EasyMock.anyObject());
+ EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ assertEquals(LocalDiscovery.class, EasyMock.getCurrentArguments()[0].getClass());
+ return null;
+ }
+ });
+ EasyMock.expect(bc.getBundles()).andReturn(null);
+ EasyMock.replay(bc);
+
+ LocalDiscovery ld = new LocalDiscovery(bc);
+ assertSame(bc, ld.bundleContext);
+ assertNotNull(ld.listenerTracker);
+
+ EasyMock.verify(bc);
+ }
+
+ public void testPreExistingBundles() throws Exception {
+ Filter filter = EasyMock.createMock(Filter.class);
+ EasyMock.replay(filter);
+
+ BundleContext bc = EasyMock.createMock(BundleContext.class);
+ EasyMock.expect(bc.createFilter("(objectClass=org.osgi.service.remoteserviceadmin.EndpointListener)")).andReturn(filter);
+ bc.addServiceListener((ServiceListener) EasyMock.anyObject(),
+ EasyMock.eq("(objectClass=org.osgi.service.remoteserviceadmin.EndpointListener)"));
+ EasyMock.expectLastCall();
+ EasyMock.expect(bc.getServiceReferences("org.osgi.service.remoteserviceadmin.EndpointListener", null)).andReturn(null);
+ bc.addBundleListener((BundleListener) EasyMock.anyObject());
+ EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ assertEquals(LocalDiscovery.class, EasyMock.getCurrentArguments()[0].getClass());
+ return null;
+ }
+ });
+
+ Bundle b1 = EasyMock.createMock(Bundle.class);
+ EasyMock.expect(b1.getState()).andReturn(Bundle.RESOLVED);
+ EasyMock.replay(b1);
+ Bundle b2 = EasyMock.createMock(Bundle.class);
+ EasyMock.expect(b2.getState()).andReturn(Bundle.ACTIVE);
+ Dictionary<String, Object> headers = new Hashtable<String, Object>();
+ headers.put("Remote-Service", "OSGI-INF/remote-service");
+ EasyMock.expect(b2.getHeaders()).andReturn(headers);
+
+ URL rs3URL = getClass().getResource("/ed3.xml");
+ URL rs4URL = getClass().getResource("/ed4.xml");
+ List<URL> urls = Arrays.asList(rs3URL, rs4URL);
+ EasyMock.expect(b2.findEntries("OSGI-INF/remote-service", "*.xml", false))
+ .andReturn(Collections.enumeration(urls));
+ EasyMock.replay(b2);
+
+ EasyMock.expect(bc.getBundles()).andReturn(new Bundle [] {b1, b2});
+ EasyMock.replay(bc);
+
+ LocalDiscovery ld = new LocalDiscovery(bc);
+
+ assertEquals(3, ld.endpointDescriptions.size());
+ Set<String> expected = new HashSet<String>(
+ Arrays.asList("http://somewhere:12345", "http://somewhere:1", "http://somewhere"));
+ Set<String> actual = new HashSet<String>();
+ for (Map.Entry<EndpointDescription, Bundle> entry : ld.endpointDescriptions.entrySet()) {
+ assertSame(b2, entry.getValue());
+ actual.add(entry.getKey().getRemoteURI());
+ }
+ assertEquals(expected, actual);
+ }
+}
Propchange: cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/dosgi/trunk/discovery/local/src/test/resources/ed3.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/resources/ed3.xml?rev=895639&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/test/resources/ed3.xml (added)
+++ cxf/dosgi/trunk/discovery/local/src/test/resources/ed3.xml Mon Jan 4 14:25:16 2010
@@ -0,0 +1,33 @@
+<?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.
+-->
+
+<rsa:endpoint-descriptions xmlns:rsa="http://www.osgi.org/xmlns/rsa/v1.0.0"
+ xmlns:other="http://www.acme.org/xmlns/other/v1.0.0">
+ <endpoint-description>
+ <property name="objectClass">
+ <array>
+ <value>SomeService</value>
+ </array>
+ </property>
+ <property name="endpoint.uri">http://somewhere:12345</property>
+ </endpoint-description>
+</rsa:endpoint-descriptions>
+
Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/ed3.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/ed3.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/ed3.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: cxf/dosgi/trunk/discovery/local/src/test/resources/ed4.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/resources/ed4.xml?rev=895639&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/test/resources/ed4.xml (added)
+++ cxf/dosgi/trunk/discovery/local/src/test/resources/ed4.xml Mon Jan 4 14:25:16 2010
@@ -0,0 +1,42 @@
+<?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.
+-->
+
+<rsa:endpoint-descriptions xmlns:rsa="http://www.osgi.org/xmlns/rsa/v1.0.0"
+ xmlns:other="http://www.acme.org/xmlns/other/v1.0.0">
+ <endpoint-description>
+ <property name="objectClass">
+ <array>
+ <value>org.example.ClassA</value>
+ </array>
+ </property>
+ <property name="endpoint.uri">http://somewhere</property>
+ </endpoint-description>
+
+ <endpoint-description>
+ <property name="objectClass">
+ <array>
+ <value>org.example.ClassB</value>
+ </array>
+ </property>
+ <property name="endpoint.uri">http://somewhere:1</property>
+ </endpoint-description>
+</rsa:endpoint-descriptions>
+
Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/ed4.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/ed4.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/ed4.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml