Repository: cxf-dosgi Updated Branches: refs/heads/master 79bb9a437 -> d2a3c75f3
http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java deleted file mode 100644 index be1cba0..0000000 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * 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.dsw.util; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -import org.osgi.service.remoteserviceadmin.EndpointDescription; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class OsgiUtils { - - public static final Logger LOG = LoggerFactory.getLogger(OsgiUtils.class); - - private OsgiUtils() { - } - - public static boolean getBooleanProperty(Map<String, Object> sd, String name) { - return toBoolean(sd.get(name)); - } - - public static boolean toBoolean(Object value) { - return value instanceof Boolean && (Boolean) value - || value instanceof String && Boolean.parseBoolean((String)value); - } - - @SuppressWarnings("unchecked") - public static Collection<String> getMultiValueProperty(Object property) { - if (property == null) { - return null; - } else if (property instanceof Collection) { - return (Collection<String>)property; - } else if (property instanceof String[]) { - return Arrays.asList((String[])property); - } else { - return Collections.singleton(property.toString()); - } - } - - public static String getProperty(EndpointDescription endpoint, String name) { - return getProperty(endpoint.getProperties(), name); - } - - public static String getProperty(Map<String, Object> dict, String name) { - Object value = dict.get(name); - return value instanceof String ? (String) value : null; - } - - public static String getFirstNonEmptyStringProperty(Map<String, Object> dict, String ... keys) { - for (String key : keys) { - String value = getProperty(dict, key); - if (value != null) { - return value; - } - } - return null; - } - -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ServerWrapper.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ServerWrapper.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ServerWrapper.java deleted file mode 100644 index d04db75..0000000 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ServerWrapper.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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.dsw.util; - -import java.io.IOException; - -import org.apache.aries.rsa.spi.Endpoint; -import org.apache.cxf.endpoint.Server; -import org.osgi.service.remoteserviceadmin.EndpointDescription; - -public class ServerWrapper implements Endpoint { - private EndpointDescription desc; - private Server server; - - public ServerWrapper(EndpointDescription desc, Server server) { - this.desc = desc; - this.server = server; - } - - public Server getServer() { - return this.server; - } - - @Override - public void close() throws IOException { - this.server.destroy(); - } - - @Override - public EndpointDescription description() { - return this.desc; - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/StringPlus.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/StringPlus.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/StringPlus.java deleted file mode 100644 index dbb4cda..0000000 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/StringPlus.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * 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.dsw.util; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class StringPlus { - - private static final Logger LOG = LoggerFactory.getLogger(StringPlus.class); - - private StringPlus() { - // never constructed - } - - @SuppressWarnings("rawtypes") - public static String[] normalize(Object object) { - if (object instanceof String) { - String s = (String)object; - String[] values = s.split(","); - List<String> list = new ArrayList<String>(); - for (String val : values) { - String actualValue = val.trim(); - if (!actualValue.isEmpty()) { - list.add(actualValue); - } - } - return list.toArray(new String[list.size()]); - } - - if (object instanceof String[]) { - return (String[])object; - } - - if (object instanceof Collection) { - Collection col = (Collection)object; - List<String> ar = new ArrayList<String>(col.size()); - for (Object o : col) { - if (o instanceof String) { - String s = (String)o; - ar.add(s); - } else { - LOG.warn("stringPlus contained non string element in list! Element was skipped"); - } - } - return ar.toArray(new String[ar.size()]); - } - - return null; - } - -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java deleted file mode 100644 index ac3ae51..0000000 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * 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.dsw; - -import java.util.Dictionary; -import java.util.Hashtable; - -import junit.framework.TestCase; - -import org.apache.aries.rsa.spi.DistributionProvider; -import org.apache.cxf.dosgi.dsw.osgi.Activator; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.ServiceRegistration; - -public class ActivatorTest extends TestCase { - - private BundleContext getMockBundleContext(IMocksControl control) { - Bundle b = control.createMock(Bundle.class); - Dictionary<String, String> ht = new Hashtable<String, String>(); - EasyMock.expect(b.getHeaders()).andReturn(ht).anyTimes(); - BundleContext bc = control.createMock(BundleContext.class); - - EasyMock.expect(b.getBundleContext()).andReturn(bc).anyTimes(); - EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes(); - return bc; - } - - @SuppressWarnings({ - "rawtypes", "unchecked" - }) - public void testCreateAndShutdownRemoteServiceAdminService() throws Exception { - IMocksControl control = EasyMock.createNiceControl(); - BundleContext bc = getMockBundleContext(control); - Filter filter = control.createMock(Filter.class); - EasyMock.expect(bc.createFilter(EasyMock.<String>anyObject())).andReturn(filter); - EasyMock.expectLastCall().atLeastOnce(); - ServiceRegistration sr = control.createMock(ServiceRegistration.class); - EasyMock.expect(bc.registerService(EasyMock.eq(DistributionProvider.class.getName()), - EasyMock.anyObject(), (Dictionary<String, String>)EasyMock.anyObject())) - .andReturn(sr).atLeastOnce(); - - control.replay(); - Activator a = new Activator(); - a.start(bc); - control.verify(); - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java deleted file mode 100644 index b81bf3e..0000000 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * 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.dsw; - -public final class TestUtils { - -// private TestUtils() { -// } -// -// public static ServiceEndpointDescription mockServiceDescription(String... interfaceNames) { -// List<String> iList = new ArrayList<String>(); -// for (String iName : interfaceNames) { -// iList.add(iName); -// } -// -// ServiceEndpointDescription sd = EasyMock.createNiceMock(ServiceEndpointDescription.class); -// sd.getProvidedInterfaces(); -// EasyMock.expectLastCall().andReturn(iList); -// return sd; -// } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProviderTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProviderTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProviderTest.java index 6215f10..38db72d 100644 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProviderTest.java +++ b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProviderTest.java @@ -23,15 +23,15 @@ import java.util.List; import java.util.Map; import org.apache.aries.rsa.spi.DistributionProvider; +import org.apache.cxf.dosgi.common.httpservice.HttpServiceManager; +import org.apache.cxf.dosgi.common.intent.DefaultIntentMapFactory; +import org.apache.cxf.dosgi.common.intent.IntentManager; +import org.apache.cxf.dosgi.common.intent.IntentManagerImpl; +import org.apache.cxf.dosgi.common.intent.IntentMap; import org.apache.cxf.dosgi.dsw.handlers.pojo.PojoConfigurationTypeHandler; import org.apache.cxf.dosgi.dsw.handlers.pojo.WsdlConfigurationTypeHandler; import org.apache.cxf.dosgi.dsw.handlers.rest.JaxRSPojoConfigurationTypeHandler; -import org.apache.cxf.dosgi.dsw.httpservice.HttpServiceManager; import org.apache.cxf.dosgi.dsw.osgi.Constants; -import org.apache.cxf.dosgi.dsw.qos.DefaultIntentMapFactory; -import org.apache.cxf.dosgi.dsw.qos.IntentManager; -import org.apache.cxf.dosgi.dsw.qos.IntentManagerImpl; -import org.apache.cxf.dosgi.dsw.qos.IntentMap; import org.easymock.EasyMock; import org.junit.Assert; import org.junit.Test; @@ -100,9 +100,13 @@ public class CXFDistributionProviderTest { serviceProps.put(RemoteConstants.SERVICE_EXPORTED_INTENTS, intents); IntentMap intentMap = new IntentMap(new DefaultIntentMapFactory().create()); IntentManager intentManager = new IntentManagerImpl(intentMap); - HttpServiceManager httpServiceManager = new HttpServiceManager(bc, null, null); - CXFDistributionProvider f = new CXFDistributionProvider(bc, intentManager, httpServiceManager); - List<String> configurationTypes = f.determineConfigurationTypes(serviceProps); - return f.getHandler(configurationTypes, serviceProps); + HttpServiceManager httpServiceManager = new HttpServiceManager(); + httpServiceManager.setContext(bc); + CXFDistributionProvider provider = new CXFDistributionProvider(); + provider.setHttpServiceManager(httpServiceManager); + provider.setIntentManager(intentManager); + provider.init(bc, null); + List<String> configurationTypes = provider.determineConfigurationTypes(serviceProps); + return provider.getHandler(configurationTypes, serviceProps); } } http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtilsTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtilsTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtilsTest.java deleted file mode 100644 index a38fea7..0000000 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtilsTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/** - * 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.dsw.handlers; - -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import junit.framework.TestCase; - -import org.apache.cxf.dosgi.dsw.util.ClassUtils; -import org.apache.cxf.dosgi.dsw.util.Provider; -import org.easymock.EasyMock; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; - -public class ClassUtilsTest extends TestCase { - - public void testLoadProvidersAsString() throws Exception { - BundleContext bc = mockBundleContext(); - Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", Provider.class.getName()); - List<Object> providers = ClassUtils.loadProviderClasses(bc, sd, "providers"); - assertEquals(1, providers.size()); - assertTrue(providers.get(0) instanceof Provider); - } - - public void testLoadProvidersAsStringArray() throws Exception { - BundleContext bc = mockBundleContext(); - Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", - new String[]{Provider.class.getName()}); - List<Object> providers = ClassUtils.loadProviderClasses(bc, sd, "providers"); - assertEquals(1, providers.size()); - assertTrue(providers.get(0) instanceof Provider); - } - - public void testLoadProvidersAsObject() throws Exception { - Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", new Provider()); - List<Object> providers = ClassUtils.loadProviderClasses(null, sd, "providers"); - assertEquals(1, providers.size()); - assertTrue(providers.get(0) instanceof Provider); - } - - public void testLoadProvidersAsObjectArray() throws Exception { - Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", new Object[]{new Provider()}); - List<Object> providers = ClassUtils.loadProviderClasses(null, sd, "providers"); - assertEquals(1, providers.size()); - assertTrue(providers.get(0) instanceof Provider); - } - - public void testLoadProvidersAsObjectList() throws Exception { - List<Object> list = new LinkedList<Object>(); - list.add(new Provider()); - Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", list); - List<Object> providers = ClassUtils.loadProviderClasses(null, sd, "providers"); - assertEquals(1, providers.size()); - assertTrue(providers.get(0) instanceof Provider); - } - - public void testLoadProvidersAsStringList() throws Exception { - List<Object> list = new LinkedList<Object>(); - list.add(Provider.class.getName()); - Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", list); - List<Object> providers = ClassUtils.loadProviderClasses(mockBundleContext(), sd, "providers"); - assertEquals(1, providers.size()); - assertTrue(providers.get(0) instanceof Provider); - } - - private BundleContext mockBundleContext() throws Exception { - BundleContext bc = EasyMock.createMock(BundleContext.class); - Bundle bundle = EasyMock.createMock(Bundle.class); - bc.getBundle(); - EasyMock.expectLastCall().andReturn(bundle); - bundle.loadClass(Provider.class.getName()); - EasyMock.expectLastCall().andReturn(Provider.class); - EasyMock.replay(bc, bundle); - return bc; - } - - @SuppressWarnings({ "serial", "rawtypes" }) - private static class MyMapSubclass extends HashMap { - } - - @SuppressWarnings("serial") - static class MySubclassOne extends MyMapSubclass { - } - - @SuppressWarnings("serial") - static class MySubclassTwo extends MySubclassOne { - } - - @SuppressWarnings("serial") - static class MySubclassThree extends MySubclassTwo { - } - - @SuppressWarnings("serial") - static class MySubclassFour extends MySubclassThree { - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/pojo/PojoConfigurationTypeHandlerTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/pojo/PojoConfigurationTypeHandlerTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/pojo/PojoConfigurationTypeHandlerTest.java index 678a495..d02008c 100644 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/pojo/PojoConfigurationTypeHandlerTest.java +++ b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/pojo/PojoConfigurationTypeHandlerTest.java @@ -20,24 +20,23 @@ package org.apache.cxf.dosgi.dsw.handlers.pojo; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.UUID; import javax.xml.namespace.QName; -import junit.framework.TestCase; - import org.apache.aries.rsa.spi.Endpoint; import org.apache.aries.rsa.util.EndpointHelper; +import org.apache.cxf.dosgi.common.httpservice.HttpServiceManager; +import org.apache.cxf.dosgi.common.intent.IntentManager; +import org.apache.cxf.dosgi.common.intent.IntentManagerImpl; +import org.apache.cxf.dosgi.common.intent.IntentMap; +import org.apache.cxf.dosgi.common.util.ServerWrapper; import org.apache.cxf.dosgi.dsw.handlers.jaxws.MyJaxWsEchoService; import org.apache.cxf.dosgi.dsw.handlers.simple.MySimpleEchoService; -import org.apache.cxf.dosgi.dsw.httpservice.HttpServiceManager; import org.apache.cxf.dosgi.dsw.osgi.Constants; -import org.apache.cxf.dosgi.dsw.qos.IntentManager; -import org.apache.cxf.dosgi.dsw.qos.IntentManagerImpl; -import org.apache.cxf.dosgi.dsw.qos.IntentMap; -import org.apache.cxf.dosgi.dsw.util.ServerWrapper; import org.apache.cxf.endpoint.AbstractEndpointFactory; import org.apache.cxf.endpoint.EndpointImpl; import org.apache.cxf.endpoint.Server; @@ -53,12 +52,32 @@ import org.easymock.EasyMock; import org.easymock.IAnswer; import org.easymock.IMocksControl; import org.junit.Assert; +import org.junit.Test; import org.osgi.framework.BundleContext; import org.osgi.framework.Version; import org.osgi.service.remoteserviceadmin.EndpointDescription; import org.osgi.service.remoteserviceadmin.RemoteConstants; +import junit.framework.TestCase; + public class PojoConfigurationTypeHandlerTest extends TestCase { + @Test + public void testMergeArrays() { + Assert.assertNull(AbstractPojoConfigurationTypeHandler.mergeArrays(null, null)); + + String[] sa1 = {}; + Assert.assertEquals(0, AbstractPojoConfigurationTypeHandler.mergeArrays(sa1, null).length); + + String[] sa2 = {"X"}; + Assert.assertEquals(1, AbstractPojoConfigurationTypeHandler.mergeArrays(null, sa2).length); + Assert.assertEquals("X", AbstractPojoConfigurationTypeHandler.mergeArrays(null, sa2)[0]); + + String[] sa3 = {"Y", "Z"}; + String[] sa4 = {"A", "Z"}; + Assert.assertEquals(3, AbstractPojoConfigurationTypeHandler.mergeArrays(sa3, sa4).length); + Assert.assertEquals(new HashSet<String>(Arrays.asList("A", "Y", "Z")), + new HashSet<String>(Arrays.asList(AbstractPojoConfigurationTypeHandler.mergeArrays(sa3, sa4)))); + } public void testGetPojoAddressEndpointURI() { IntentManager intentManager = new IntentManagerImpl(new IntentMap()); @@ -72,7 +91,7 @@ public class PojoConfigurationTypeHandlerTest extends TestCase { } private HttpServiceManager dummyHttpServiceManager() { - return new HttpServiceManager(null, null, null, null); + return new HttpServiceManager(); } public void testGetPojoAddressEndpointCxf() { http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/httpservice/HttpServiceManagerTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/httpservice/HttpServiceManagerTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/httpservice/HttpServiceManagerTest.java deleted file mode 100644 index 593a06d..0000000 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/httpservice/HttpServiceManagerTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * 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.dsw.httpservice; - -import java.util.Dictionary; - -import javax.servlet.Servlet; -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; - -import junit.framework.TestCase; - -import org.apache.cxf.Bus; -import org.apache.cxf.BusFactory; -import org.easymock.Capture; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.Assert; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.ServiceEvent; -import org.osgi.framework.ServiceListener; -import org.osgi.framework.ServiceReference; -import org.osgi.service.http.HttpContext; -import org.osgi.service.http.HttpService; -import org.osgi.service.http.NamespaceException; - -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.expectLastCall; - -public class HttpServiceManagerTest extends TestCase { - - public void testGetAbsoluteAddress() { - IMocksControl c = EasyMock.createControl(); - BundleContext bundleContext = c.createMock(BundleContext.class); - c.replay(); - HttpServiceManager manager = new HttpServiceManager(bundleContext, null, null, null); - String localIp = LocalHostUtil.getLocalIp(); - - String address1 = manager.getAbsoluteAddress(null, "/myservice"); - assertEquals("http://" + localIp + ":8181/cxf/myservice", address1); - - String address2 = manager.getAbsoluteAddress("/mycontext", "/myservice"); - assertEquals("http://" + localIp + ":8181/mycontext/myservice", address2); - - c.verify(); - } - - public void testRegisterAndUnregisterServlet() throws Exception { - IMocksControl c = EasyMock.createControl(); - BundleContext dswContext = c.createMock(BundleContext.class); - Filter filter = c.createMock(Filter.class); - expect(dswContext.createFilter(EasyMock.eq("(service.id=12345)"))).andReturn(filter).once(); - Capture<ServiceListener> captured = EasyMock.newCapture(); - dswContext.addServiceListener(EasyMock.capture(captured), EasyMock.<String>anyObject()); - expectLastCall().atLeastOnce(); - expect(dswContext.getProperty("org.apache.cxf.httpservice.requirefilter")).andReturn(null).atLeastOnce(); - ServletConfig config = c.createMock(ServletConfig.class); - expect(config.getInitParameter(EasyMock.<String>anyObject())).andReturn(null).atLeastOnce(); - ServletContext servletContext = c.createMock(ServletContext.class); - expect(config.getServletContext()).andReturn(servletContext); - final HttpService httpService = new DummyHttpService(config); - ServiceReference<?> sr = c.createMock(ServiceReference.class); - expect(sr.getProperty(EasyMock.eq("service.id"))).andReturn(12345L).atLeastOnce(); - expect(servletContext.getResourceAsStream((String)EasyMock.anyObject())).andReturn(null).anyTimes(); - c.replay(); - - HttpServiceManager h = new HttpServiceManager(dswContext, null, null, null) { - @Override - protected HttpService getHttpService() { - return httpService; - } - }; - Bus bus = BusFactory.newInstance().createBus(); - h.registerServlet(bus, "/myService", dswContext, 12345L); - - ServiceEvent event = new ServiceEvent(ServiceEvent.UNREGISTERING, sr); - captured.getValue().serviceChanged(event); - c.verify(); - } - - static class DummyHttpService implements HttpService { - - private ServletConfig config; - - DummyHttpService(ServletConfig config) { - this.config = config; - } - - @SuppressWarnings("rawtypes") - public void registerServlet(String alias, Servlet servlet, Dictionary initparams, HttpContext context) - throws ServletException, NamespaceException { - Assert.assertEquals("/myService", alias); - servlet.init(config); - } - - public void registerResources(String alias, String name, HttpContext context) throws NamespaceException { - throw new RuntimeException("This method should not be called"); - } - - public void unregister(String alias) { - } - - public HttpContext createDefaultHttpContext() { - return EasyMock.createNiceMock(HttpContext.class); - } - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/httpservice/SecurityDelegatingHttpContextTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/httpservice/SecurityDelegatingHttpContextTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/httpservice/SecurityDelegatingHttpContextTest.java deleted file mode 100644 index 84718ad..0000000 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/httpservice/SecurityDelegatingHttpContextTest.java +++ /dev/null @@ -1,267 +0,0 @@ -/** - * 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.dsw.httpservice; - -import java.io.PrintWriter; -import java.net.URL; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import junit.framework.TestCase; - -import org.easymock.EasyMock; -import org.junit.Assert; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.http.HttpContext; - -@SuppressWarnings({ - "unchecked", "rawtypes" - }) -public class SecurityDelegatingHttpContextTest extends TestCase { - - protected HttpContext defaultHttpContext; - protected SecurityDelegatingHttpContext httpContext; - protected CommitResponseFilter commitFilter; - protected DoNothingFilter doNothingFilter; - protected AccessDeniedFilter accessDeniedFilter; - protected String mimeType; - protected URL url; // does not need to exist - - public void setUp() throws Exception { - mimeType = "text/xml"; - url = new URL("file:test.xml"); // does not need to exist - - // Sample filters - commitFilter = new CommitResponseFilter(); - doNothingFilter = new DoNothingFilter(); - accessDeniedFilter = new AccessDeniedFilter(); - - // Mock up the default http context - defaultHttpContext = EasyMock.createNiceMock(HttpContext.class); - EasyMock.expect(defaultHttpContext.getMimeType((String)EasyMock.anyObject())).andReturn(mimeType); - EasyMock.expect(defaultHttpContext.getResource((String)EasyMock.anyObject())).andReturn(url); - EasyMock.replay(defaultHttpContext); - } - - public void testFilterRequired() throws Exception { - // Mock up the service references - ServiceReference[] serviceReferences = new ServiceReference[] {}; - - // Mock up the bundle context - BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class); - EasyMock.expect(bundleContext.getServiceReferences(Filter.class.getName(), - "(org.apache.cxf.httpservice.filter=true)")) - .andReturn(serviceReferences); - EasyMock.replay(bundleContext); - - // Set up the secure http context - httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext); - httpContext.requireFilter = true; - - // Ensure that the httpContext doesn't allow the request to be processed, since there are no registered servlet - // filters - HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); - EasyMock.replay(request); - HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class); - EasyMock.replay(response); - boolean requestAllowed = httpContext.handleSecurity(request, response); - Assert.assertFalse(requestAllowed); - - // Ensure that the httpContext returns true if there is no requirement for registered servlet filters - httpContext.requireFilter = false; - requestAllowed = httpContext.handleSecurity(request, response); - Assert.assertTrue(requestAllowed); - } - - public void testSingleCommitFilter() throws Exception { - // Mock up the service references - ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class); - EasyMock.replay(filterReference); - ServiceReference[] serviceReferences = new ServiceReference[] { - filterReference - }; - - // Mock up the bundle context - BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class); - EasyMock.expect(bundleContext.getServiceReferences((String)EasyMock.anyObject(), (String)EasyMock.anyObject())) - .andReturn(serviceReferences); - EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(commitFilter); - EasyMock.replay(bundleContext); - - // Set up the secure http context - httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext); - - // Ensure that the httpContext returns false, since the filter has committed the response - HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); - EasyMock.replay(request); - HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class); - EasyMock.expect(response.isCommitted()).andReturn(false); // the first call checks to see whether to invoke the - // filter - EasyMock.expect(response.isCommitted()).andReturn(true); // the second is called to determine the handleSecurity - // return value - EasyMock.expect(response.getWriter()).andReturn(new PrintWriter(System.out)); - EasyMock.replay(response); - Assert.assertFalse(httpContext.handleSecurity(request, response)); - - // Ensure that the appropriate filters were called - Assert.assertTrue(commitFilter.called); - Assert.assertFalse(doNothingFilter.called); - Assert.assertFalse(accessDeniedFilter.called); - } - - public void testFilterChain() throws Exception { - // Mock up the service references - ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class); - EasyMock.replay(filterReference); - ServiceReference[] serviceReferences = new ServiceReference[] { - filterReference, filterReference - }; - - // Mock up the bundle context - BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class); - EasyMock.expect(bundleContext.getServiceReferences((String)EasyMock.anyObject(), (String)EasyMock.anyObject())) - .andReturn(serviceReferences); - EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(doNothingFilter); - EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(commitFilter); - EasyMock.replay(bundleContext); - - // Set up the secure http context - httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext); - - // Ensure that the httpContext returns false, since the filter has committed the response - HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); - EasyMock.replay(request); - HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class); - EasyMock.expect(response.isCommitted()).andReturn(false); // doNothingFilter should not commit the response - EasyMock.expect(response.getWriter()).andReturn(new PrintWriter(System.out)); - EasyMock.expect(response.isCommitted()).andReturn(false); - EasyMock.expect(response.isCommitted()).andReturn(true); // the commit filter indicating that it committed the - // response - EasyMock.replay(response); - Assert.assertFalse(httpContext.handleSecurity(request, response)); - - // Ensure that the appropriate filters were called - Assert.assertTrue(doNothingFilter.called); - Assert.assertTrue(commitFilter.called); - Assert.assertFalse(accessDeniedFilter.called); - } - - public void testAllowRequest() throws Exception { - // Mock up the service references - ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class); - EasyMock.replay(filterReference); - ServiceReference[] serviceReferences = new ServiceReference[] { - filterReference - }; - - // Mock up the bundle context - BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class); - EasyMock.expect(bundleContext.getServiceReferences((String)EasyMock.anyObject(), (String)EasyMock.anyObject())) - .andReturn(serviceReferences); - EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(doNothingFilter); - EasyMock.replay(bundleContext); - - // Set up the secure http context - httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext); - - // Ensure that the httpContext returns true, since the filter has not committed the response - HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); - EasyMock.replay(request); - HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class); - EasyMock.expect(response.isCommitted()).andReturn(false); - EasyMock.replay(response); - Assert.assertTrue(httpContext.handleSecurity(request, response)); - - // Ensure that the appropriate filters were called - Assert.assertTrue(doNothingFilter.called); - Assert.assertFalse(commitFilter.called); - Assert.assertFalse(accessDeniedFilter.called); - } - - public void testDelegation() throws Exception { - BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class); - EasyMock.replay(bundleContext); - - // Set up the secure http context - httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext); - - // Ensure that it delegates non-security calls to the wrapped implementation (in this case, the mock) - Assert.assertEquals(mimeType, httpContext.getMimeType("")); - Assert.assertEquals(url, httpContext.getResource("")); - } -} - -class CommitResponseFilter implements Filter { - - boolean called; - - public void init(FilterConfig filterConfig) throws ServletException { - } - - public void destroy() { - } - - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws java.io.IOException, javax.servlet.ServletException { - called = true; - response.getWriter().write("committing the response"); - } -} - -class DoNothingFilter implements Filter { - - boolean called; - - public void init(FilterConfig filterConfig) throws ServletException { - } - - public void destroy() { - } - - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws java.io.IOException, javax.servlet.ServletException { - called = true; - chain.doFilter(request, response); - } -} - -class AccessDeniedFilter implements Filter { - - boolean called; - - public void init(FilterConfig filterConfig) throws ServletException { - } - - public void destroy() { - } - - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws java.io.IOException, javax.servlet.ServletException { - called = true; - ((HttpServletResponse)response).sendError(HttpServletResponse.SC_FORBIDDEN); - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImplTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImplTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImplTest.java deleted file mode 100644 index d90136c..0000000 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImplTest.java +++ /dev/null @@ -1,278 +0,0 @@ -/** - * 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.dsw.qos; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.aries.rsa.spi.IntentUnsatisfiedException; -import org.apache.cxf.binding.BindingConfiguration; -import org.apache.cxf.endpoint.AbstractEndpointFactory; -import org.apache.cxf.feature.AbstractFeature; -import org.apache.cxf.feature.Feature; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.Assert; -import org.junit.Test; - -public class IntentManagerImplTest extends Assert { - - @Test - public void testIntents() throws Exception { - Map<String, Object> intents = new HashMap<String, Object>(); - intents.put("A", new TestFeature("A")); - intents.put("SOAP", new TestFeature("SOAP")); - final IntentMap intentMap = new IntentMap(intents); - - IMocksControl control = EasyMock.createNiceControl(); - List<Feature> features = new ArrayList<Feature>(); - AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class); - control.replay(); - - IntentManager intentManager = new IntentManagerImpl(intentMap, 10000); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put("osgi.remote.requires.intents", "A"); - - List<String> effectiveIntents = Arrays.asList(intentManager.applyIntents(features, factory, props)); - assertEquals(Arrays.asList("A", "SOAP"), effectiveIntents); - } - - @Test - public void testMultiIntents() { - final IntentMap intentMap = new IntentMap(new DefaultIntentMapFactory().create()); - intentMap.put("confidentiality.message", new TestFeature("confidentiality.message")); - intentMap.put("transactionality", new TestFeature("transactionality")); - - IMocksControl control = EasyMock.createNiceControl(); - List<Feature> features = new ArrayList<Feature>(); - AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class); - control.replay(); - - IntentManager intentManager = new IntentManagerImpl(intentMap); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put("osgi.remote.requires.intents", "transactionality confidentiality.message"); - - List<String> effectiveIntents = Arrays.asList(intentManager.applyIntents(features, factory, props)); - assertTrue(effectiveIntents.contains("transactionality")); - assertTrue(effectiveIntents.contains("confidentiality.message")); - } - - @Test - public void testFailedIntent() { - Map<String, Object> intents = new HashMap<String, Object>(); - intents.put("A", new TestFeature("A")); - final IntentMap intentMap = new IntentMap(intents); - - IMocksControl control = EasyMock.createNiceControl(); - List<Feature> features = new ArrayList<Feature>(); - AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class); - control.replay(); - - IntentManager intentManager = new IntentManagerImpl(intentMap); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put("osgi.remote.requires.intents", "A B"); - // ServiceEndpointDescription sd = - // new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()), props); - - try { - intentManager.applyIntents(features, factory, props); - Assert.fail("applyIntents() should have thrown an exception as there was an unsatisfiable intent"); - } catch (IntentUnsatisfiedException iue) { - assertEquals("B", iue.getIntent()); - } - } - - @Test - public void testInferIntents() { - Map<String, Object> intents = new HashMap<String, Object>(); - intents.put("SOAP", new TestFeature("SOAP")); - intents.put("Prov", "PROVIDED"); - AbstractFeature feat1 = new TestFeature("feat1"); - intents.put("A", feat1); - intents.put("A_alt", feat1); - intents.put("B", new TestFeature("B")); - final IntentMap intentMap = new IntentMap(intents); - - IMocksControl control = EasyMock.createNiceControl(); - List<Feature> features = new ArrayList<Feature>(); - AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class); - control.replay(); - - IntentManager intentManager = new IntentManagerImpl(intentMap); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put("osgi.remote.requires.intents", "A"); - // ServiceEndpointDescription sd = - // new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()), props); - - List<String> effectiveIntents = Arrays.asList(intentManager.applyIntents(features, factory, props)); - assertEquals(4, effectiveIntents.size()); - assertTrue(effectiveIntents.contains("Prov")); - assertTrue(effectiveIntents.contains("A")); - assertTrue(effectiveIntents.contains("A_alt")); - } - - @Test - public void testDefaultBindingIntent() { - IMocksControl control = EasyMock.createNiceControl(); - - Map<String, Object> intents = new HashMap<String, Object>(); - BindingConfiguration feat1 = control.createMock(BindingConfiguration.class); - intents.put("A", new AbstractFeature() { - }); - intents.put("SOAP", feat1); - intents.put("SOAP.1_1", feat1); - intents.put("SOAP.1_2", control.createMock(BindingConfiguration.class)); - final IntentMap intentMap = new IntentMap(intents); - - List<Feature> features = new ArrayList<Feature>(); - AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class); - control.replay(); - IntentManager intentManager = new IntentManagerImpl(intentMap); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put("osgi.remote.requires.intents", "A"); - // ServiceEndpointDescription sd = - // new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()), props); - - List<String> effectiveIntents = Arrays.asList(intentManager.applyIntents(features, factory, props)); - assertEquals(3, effectiveIntents.size()); - assertTrue(effectiveIntents.contains("A")); - assertTrue(effectiveIntents.contains("SOAP")); - assertTrue(effectiveIntents.contains("SOAP.1_1")); - } - - @Test - public void testExplicitBindingIntent() { - IMocksControl control = EasyMock.createNiceControl(); - - Map<String, Object> intents = new HashMap<String, Object>(); - BindingConfiguration feat1 = control.createMock(BindingConfiguration.class); - intents.put("A", new AbstractFeature() { - }); - intents.put("SOAP", feat1); - intents.put("SOAP.1_1", feat1); - intents.put("SOAP.1_2", control.createMock(BindingConfiguration.class)); - final IntentMap intentMap = new IntentMap(intents); - - List<Feature> features = new ArrayList<Feature>(); - AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class); - control.replay(); - - IntentManager intentManager = new IntentManagerImpl(intentMap); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put("osgi.remote.requires.intents", "A SOAP.1_2"); - // ServiceEndpointDescription sd = - // new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()), props); - - List<String> effectiveIntents = Arrays.asList(intentManager.applyIntents(features, factory, props)); - assertEquals(2, effectiveIntents.size()); - assertTrue(effectiveIntents.contains("A")); - assertTrue(effectiveIntents.contains("SOAP.1_2")); - } - - public void testInheritMasterIntentMapDefault() { - List<String> features = runTestInheritMasterIntentMap("A B"); - - assertEquals(2, features.size()); - assertTrue(features.contains("appFeatureA")); - assertTrue(features.contains("masterFeatureB")); - } - - public void testInheritMasterIntentMap() { - List<String> features = runTestInheritMasterIntentMap("A B"); - - assertEquals(2, features.size()); - assertTrue(features.contains("appFeatureA")); - assertTrue(features.contains("masterFeatureB")); - } - - private List<String> runTestInheritMasterIntentMap(String requestedIntents) { - Map<String, Object> masterIntents = new HashMap<String, Object>(); - masterIntents.put("A", new TestFeature("masterFeatureA")); - masterIntents.put("B", new TestFeature("masterFeatureB")); - final IntentMap intentMap = new IntentMap(masterIntents); - intentMap.put("A", new TestFeature("appFeatureA")); - - IMocksControl control = EasyMock.createNiceControl(); - List<Feature> features = new ArrayList<Feature>(); - AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class); - control.replay(); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put("osgi.remote.requires.intents", requestedIntents); - - IntentManagerImpl intentManager = new IntentManagerImpl(intentMap); - intentManager.applyIntents(features, factory, props); - - List<String> featureNames = new ArrayList<String>(); - for (Feature f : features) { - featureNames.add(f.toString()); - } - return featureNames; - } - - @Test - public void testProvidedIntents() { - Map<String, Object> masterIntents = new HashMap<String, Object>(); - masterIntents.put("SOAP", "SOAP"); - masterIntents.put("A", "Provided"); - masterIntents.put("B", "PROVIDED"); - final IntentMap intentMap = new IntentMap(masterIntents); - - IMocksControl control = EasyMock.createNiceControl(); - List<Feature> features = new ArrayList<Feature>(); - AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class); - control.replay(); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put("osgi.remote.requires.intents", "B A"); - - IntentManager intentManager = new IntentManagerImpl(intentMap); - - Set<String> effectiveIntents = new HashSet<String>(Arrays.asList(intentManager.applyIntents(features, - factory, - props))); - Set<String> expectedIntents = new HashSet<String>(Arrays.asList(new String[] {"A", "B", "SOAP"})); - assertEquals(expectedIntents, effectiveIntents); - } - - private static final class TestFeature extends AbstractFeature { - - private final String name; - - private TestFeature(String n) { - name = n; - } - - @Override - public String toString() { - return name; - } - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java deleted file mode 100644 index 748da85..0000000 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * 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.dsw.qos; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Assert; -import org.junit.Test; - -public class IntentMapTest { - - @Test - public void inheritanceTest() { - Map<String, Object> defaultMap = new HashMap<String, Object>(); - defaultMap.put("key1", "defaultValue"); - IntentMap intentMap = new IntentMap(defaultMap); - Assert.assertEquals("defaultValue", intentMap.get("key1")); - intentMap.put("key1", "overridden"); - Assert.assertEquals("overridden", intentMap.get("key1")); - Object curValue = intentMap.remove("key1"); - Assert.assertEquals("overridden", curValue); - Assert.assertEquals("defaultValue", intentMap.get("key1")); - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentTrackerTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentTrackerTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentTrackerTest.java deleted file mode 100644 index 380478c..0000000 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentTrackerTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * 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.dsw.qos; - -import org.apache.cxf.dosgi.dsw.osgi.Constants; -import org.apache.cxf.feature.AbstractFeature; -import org.easymock.Capture; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.Assert; -import org.junit.Test; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceEvent; -import org.osgi.framework.ServiceListener; -import org.osgi.framework.ServiceReference; - -import static org.easymock.EasyMock.expect; - -public class IntentTrackerTest { - - private static final String MY_INTENT_NAME = "myIntent"; - - @Test - public void testIntentAsService() throws InvalidSyntaxException { - IMocksControl c = EasyMock.createControl(); - BundleContext bc = c.createMock(BundleContext.class); - Filter filter = c.createMock(Filter.class); - expect(bc.createFilter(EasyMock.<String>anyObject())).andReturn(filter); - final Capture<ServiceListener> capturedListener = EasyMock.newCapture(); - bc.addServiceListener(EasyMock.capture(capturedListener), EasyMock.<String>anyObject()); - EasyMock.expectLastCall().atLeastOnce(); - expect(bc.getServiceReferences(EasyMock.<String>anyObject(), - EasyMock.<String>anyObject())).andReturn(new ServiceReference[]{}); - IntentMap intentMap = new IntentMap(); - - // Create a custom intent - @SuppressWarnings("unchecked") - ServiceReference<AbstractFeature> reference = c.createMock(ServiceReference.class); - expect(reference.getProperty(Constants.INTENT_NAME_PROP)).andReturn(MY_INTENT_NAME); - AbstractFeature testIntent = new AbstractFeature() { - }; - expect(bc.getService(reference)).andReturn(testIntent).atLeastOnce(); - - c.replay(); - - IntentTracker tracker = new IntentTracker(bc, intentMap); - tracker.open(); - - Assert.assertFalse("IntentMap should not contain " + MY_INTENT_NAME, intentMap.containsKey(MY_INTENT_NAME)); - ServiceListener listener = capturedListener.getValue(); - - // Simulate adding custom intent service - ServiceEvent event = new ServiceEvent(ServiceEvent.REGISTERED, reference); - listener.serviceChanged(event); - - // our custom intent should now be available - Assert.assertTrue("IntentMap should contain " + MY_INTENT_NAME, intentMap.containsKey(MY_INTENT_NAME)); - Assert.assertEquals(testIntent, intentMap.get(MY_INTENT_NAME)); - - c.verify(); - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java deleted file mode 100644 index ad04be0..0000000 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * 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.dsw.qos; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.apache.cxf.dosgi.dsw.osgi.Constants; -import org.junit.Assert; -import org.junit.Test; -import org.osgi.service.remoteserviceadmin.RemoteConstants; - -public class IntentUtilsTest { - - @Test - public void testMergeArrays() { - Assert.assertNull(IntentUtils.mergeArrays(null, null)); - - String[] sa1 = {}; - Assert.assertEquals(0, IntentUtils.mergeArrays(sa1, null).length); - - String[] sa2 = {"X"}; - Assert.assertEquals(1, IntentUtils.mergeArrays(null, sa2).length); - Assert.assertEquals("X", IntentUtils.mergeArrays(null, sa2)[0]); - - String[] sa3 = {"Y", "Z"}; - String[] sa4 = {"A", "Z"}; - Assert.assertEquals(3, IntentUtils.mergeArrays(sa3, sa4).length); - Assert.assertEquals(new HashSet<String>(Arrays.asList("A", "Y", "Z")), - new HashSet<String>(Arrays.asList(IntentUtils.mergeArrays(sa3, sa4)))); - } - - @SuppressWarnings("deprecation") - @Test - public void testRequestedIntents() { - Map<String, Object> props = new HashMap<String, Object>(); - Assert.assertEquals(0, IntentUtils.getRequestedIntents(props).size()); - - props.put(RemoteConstants.SERVICE_EXPORTED_INTENTS, "one"); - Assert.assertEquals(Collections.singleton("one"), IntentUtils.getRequestedIntents(props)); - - props.put(RemoteConstants.SERVICE_EXPORTED_INTENTS_EXTRA, new String[] {"two", "three"}); - Set<String> expected1 = new HashSet<String>(Arrays.asList("one", "two", "three")); - Assert.assertEquals(expected1, IntentUtils.getRequestedIntents(props)); - - props.put(Constants.EXPORTED_INTENTS_OLD, "A B C"); - Set<String> expected2 = new HashSet<String>(Arrays.asList("one", "two", "three", "A", "B", "C")); - Assert.assertEquals(expected2, IntentUtils.getRequestedIntents(props)); - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/OsgiUtilsTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/OsgiUtilsTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/OsgiUtilsTest.java deleted file mode 100644 index f20f878..0000000 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/OsgiUtilsTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * 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.dsw.util; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.osgi.service.remoteserviceadmin.EndpointDescription; -import org.osgi.service.remoteserviceadmin.RemoteConstants; - -import junit.framework.TestCase; - -public class OsgiUtilsTest extends TestCase { - - public void testMultiValuePropertyAsString() { - assertEquals(Collections.singleton("hi"), - OsgiUtils.getMultiValueProperty("hi")); - } - - public void testMultiValuePropertyAsArray() { - 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)); - } - - public void testMultiValuePropertyNull() { - assertNull(OsgiUtils.getMultiValueProperty(null)); - } - - 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 endpoint = new EndpointDescription(p); - - assertNull(OsgiUtils.getProperty(endpoint, "unknownProp")); - assertEquals(p.get(RemoteConstants.ENDPOINT_ID), OsgiUtils.getProperty(endpoint, RemoteConstants.ENDPOINT_ID)); - assertEquals(null, OsgiUtils.getProperty(endpoint, "notAString")); - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/Provider.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/Provider.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/Provider.java deleted file mode 100644 index ecd7c78..0000000 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/Provider.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * 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.dsw.util; - - -public class Provider { -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/distribution/features/src/main/resources/features.xml ---------------------------------------------------------------------- diff --git a/distribution/features/src/main/resources/features.xml b/distribution/features/src/main/resources/features.xml index b5f3b9f..9e2a22e 100644 --- a/distribution/features/src/main/resources/features.xml +++ b/distribution/features/src/main/resources/features.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<features xmlns="http://karaf.apache.org/xmlns/features/v1.0.0" name="cxf-dosgi-${project.version}"> +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="cxf-dosgi-${project.version}"> <repository>mvn:org.apache.cxf.karaf/apache-cxf/${cxf.version}/xml/features</repository> <repository>mvn:org.apache.aries.rsa/rsa-features/${aries.rsa.version}/xml/features</repository> @@ -10,7 +10,7 @@ <bundle start-level="11">mvn:org.apache.felix/org.apache.felix.fileinstall/3.5.0</bundle> <bundle start-level="20">mvn:org.apache.aries/org.apache.aries.util/1.1.1</bundle> <bundle start-level="20">mvn:org.apache.aries.proxy/org.apache.aries.proxy.api/1.0.1</bundle> - <bundle>mvn:org.apache.felix/org.apache.felix.scr/2.0.2</bundle> + </feature> <feature name="cxf-dosgi-provider-cxf" version="${project.version}"> @@ -22,6 +22,8 @@ <feature>cxf-http-jetty</feature> <feature>cxf-http</feature> <feature>http</feature> + <bundle dependency="true">mvn:org.apache.felix/org.apache.felix.scr/2.0.2</bundle> + <bundle>mvn:${project.groupId}/cxf-dosgi-ri-common/${project.version}</bundle> <bundle>mvn:${project.groupId}/cxf-dosgi-ri-dsw-cxf/${project.version}</bundle> <bundle>mvn:${project.groupId}/cxf-dosgi-ri-decorator/${project.version}</bundle> </feature> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 703b65e..095346f 100644 --- a/pom.xml +++ b/pom.xml @@ -103,6 +103,7 @@ <modules> <module>parent</module> <module>decorator</module> + <module>common</module> <module>cxf-dsw</module> <module>samples</module> <module>distribution</module>
