Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A2D77188CA for ; Fri, 11 Mar 2016 22:53:48 +0000 (UTC) Received: (qmail 51914 invoked by uid 500); 11 Mar 2016 22:53:48 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 51772 invoked by uid 500); 11 Mar 2016 22:53:48 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 51549 invoked by uid 99); 11 Mar 2016 22:53:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Mar 2016 22:53:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 22D11E00AA; Fri, 11 Mar 2016 22:53:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: cschneider@apache.org To: commits@cxf.apache.org Date: Fri, 11 Mar 2016 22:53:51 -0000 Message-Id: <1f1718873362440bb2a0e02cb37af04f@git.apache.org> In-Reply-To: <9673b940d3a84b59be413e48f997139b@git.apache.org> References: <9673b940d3a84b59be413e48f997139b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [04/15] cxf-dosgi git commit: [DOSGI-232] Remove code that moved to Aries-rsa and refer to it instead http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java deleted file mode 100644 index 31b1e42..0000000 --- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java +++ /dev/null @@ -1,86 +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.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.cxf.dosgi.dsw.Constants; -import org.apache.cxf.dosgi.dsw.util.OsgiUtils; -import org.osgi.service.remoteserviceadmin.RemoteConstants; - -public final class IntentUtils { - - private IntentUtils() { - // never constructed - } - - public static String[] mergeArrays(String[] a1, String[] a2) { - if (a1 == null) { - return a2; - } - if (a2 == null) { - return a1; - } - - List list = new ArrayList(a1.length + a2.length); - Collections.addAll(list, a1); - for (String s : a2) { - if (!list.contains(s)) { - list.add(s); - } - } - - return list.toArray(new String[list.size()]); - } - - public static Set getRequestedIntents(Map sd) { - Collection intents = OsgiUtils.getMultiValueProperty(sd.get(RemoteConstants.SERVICE_EXPORTED_INTENTS)); - Collection intents2 - = OsgiUtils.getMultiValueProperty(sd.get(RemoteConstants.SERVICE_EXPORTED_INTENTS_EXTRA)); - @SuppressWarnings("deprecation") - Collection oldIntents = OsgiUtils.getMultiValueProperty(sd.get(Constants.EXPORTED_INTENTS_OLD)); - Set allIntents = new HashSet(); - if (intents != null) { - allIntents.addAll(parseIntents(intents)); - } - if (intents2 != null) { - allIntents.addAll(parseIntents(intents2)); - } - if (oldIntents != null) { - allIntents.addAll(parseIntents(oldIntents)); - } - - return allIntents; - } - - private static Collection parseIntents(Collection intents) { - List parsed = new ArrayList(); - for (String intent : intents) { - parsed.addAll(Arrays.asList(intent.split("[ ]"))); - } - return parsed; - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java deleted file mode 100644 index 9acd0f0..0000000 --- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java +++ /dev/null @@ -1,132 +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.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.packageadmin.ExportedPackage; -import org.osgi.service.packageadmin.PackageAdmin; -import org.osgi.service.remoteserviceadmin.EndpointDescription; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@SuppressWarnings("deprecation") -public final class OsgiUtils { - - public static final Logger LOG = LoggerFactory.getLogger(OsgiUtils.class); - - private OsgiUtils() { - } - - public static boolean getBooleanProperty(Map 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 getMultiValueProperty(Object property) { - if (property == null) { - return null; - } else if (property instanceof Collection) { - return (Collection)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 dict, String name) { - Object value = dict.get(name); - return value instanceof String ? (String) value : null; - } - - public static String getFirstNonEmptyStringProperty(Map dict, String ... keys) { - for (String key : keys) { - String value = getProperty(dict, key); - if (value != null) { - return value; - } - } - return null; - } - - /** - * Tries to retrieve the version of iClass via the PackageAdmin. - * - * @param iClass tThe interface for which the version should be found - * @param bc any valid BundleContext - * @return the version of the interface or "0.0.0" if no version information could be found or an error - * occurred during the retrieval - */ - public static String getVersion(Class iClass, BundleContext bc) { - ServiceReference paRef = bc.getServiceReference(PackageAdmin.class); - if (paRef != null) { - PackageAdmin pa = bc.getService(paRef); - try { - Bundle b = pa.getBundle(iClass); - if (b == null) { - LOG.info("Unable to find interface version for interface " + iClass.getName() - + ". Falling back to 0.0.0"); - return "0.0.0"; - } - LOG.debug("Interface source bundle: {}", b.getSymbolicName()); - - ExportedPackage[] ep = pa.getExportedPackages(b); - LOG.debug("Exported Packages of the source bundle: {}", (Object)ep); - - String pack = iClass.getPackage().getName(); - LOG.debug("Looking for Package: {}", pack); - if (ep != null) { - for (ExportedPackage p : ep) { - if (p != null - && pack.equals(p.getName())) { - LOG.debug("found package -> Version: {}", p.getVersion()); - return p.getVersion().toString(); - } - } - } - } finally { - if (pa != null) { - bc.ungetService(paRef); - } - } - } else { - LOG.error("Was unable to obtain the package admin service -> can't resolve interface versions"); - } - - LOG.info("Unable to find interface version for interface " + iClass.getName() - + ". Falling back to 0.0.0"); - return "0.0.0"; - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/StringPlus.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/StringPlus.java b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/StringPlus.java deleted file mode 100644 index dbb4cda..0000000 --- a/dsw/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 list = new ArrayList(); - 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 ar = new ArrayList(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/1425743f/dsw/cxf-dsw/src/main/resources/service-decoration.xsd ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/main/resources/service-decoration.xsd b/dsw/cxf-dsw/src/main/resources/service-decoration.xsd deleted file mode 100644 index 66e8d30..0000000 --- a/dsw/cxf-dsw/src/main/resources/service-decoration.xsd +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java deleted file mode 100644 index 65e93bc..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java +++ /dev/null @@ -1,66 +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.cxf.dosgi.dsw.api.DistributionProvider; -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 ht = new Hashtable(); - 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.anyObject())).andReturn(filter); - EasyMock.expectLastCall().atLeastOnce(); - ServiceRegistration sr = control.createMock(ServiceRegistration.class); - EasyMock.expect(bc.registerService(EasyMock.eq(DistributionProvider.class.getName()), - EasyMock.anyObject(), (Dictionary)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/1425743f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java deleted file mode 100644 index b81bf3e..0000000 --- a/dsw/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 iList = new ArrayList(); -// 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/1425743f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/DecorationParserTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/DecorationParserTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/DecorationParserTest.java deleted file mode 100644 index 270c7fa..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/DecorationParserTest.java +++ /dev/null @@ -1,63 +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.decorator; - -import java.io.IOException; -import java.net.URL; -import java.util.List; - -import javax.xml.bind.JAXBException; - -import org.apache.cxf.xmlns.service_decoration._1_0.AddPropertyType; -import org.apache.cxf.xmlns.service_decoration._1_0.MatchPropertyType; -import org.apache.cxf.xmlns.service_decoration._1_0.MatchType; -import org.apache.cxf.xmlns.service_decoration._1_0.ServiceDecorationType; -import org.junit.Assert; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class DecorationParserTest { - - @Test - public void testGetDecoratorForSD() throws JAXBException, IOException { - URL resource = getClass().getResource("/test-resources/sd.xml"); - List elements = new DecorationParser().getDecorations(resource); - assertEquals(1, elements.size()); - ServiceDecorationType decoration = elements.get(0); - assertEquals(1, decoration.getMatch().size()); - MatchType match = decoration.getMatch().get(0); - assertEquals("org.acme.foo.*", match.getInterface()); - assertEquals(1, match.getMatchProperty().size()); - MatchPropertyType matchProp = match.getMatchProperty().get(0); - assertEquals("test.prop", matchProp.getName()); - assertEquals("xyz", matchProp.getValue()); - assertEquals(1, match.getAddProperty().size()); - AddPropertyType addProp = match.getAddProperty().get(0); - assertEquals("test.too", addProp.getName()); - assertEquals("ahaha", addProp.getValue()); - assertEquals("java.lang.String", addProp.getType()); - } - - @Test - public void testGetDecorationForNull() throws JAXBException, IOException { - List elements = new DecorationParser().getDecorations(null); - Assert.assertEquals(0, elements.size()); - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRuleTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRuleTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRuleTest.java deleted file mode 100644 index c66642b..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRuleTest.java +++ /dev/null @@ -1,163 +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.decorator; - -import java.util.HashMap; -import java.util.Map; - -import junit.framework.TestCase; - -import org.easymock.EasyMock; -import org.easymock.IAnswer; -import org.osgi.framework.Bundle; -import org.osgi.framework.Constants; -import org.osgi.framework.ServiceReference; - -@SuppressWarnings("rawtypes") -public class InterfaceRuleTest extends TestCase { - - public void testDUMMY() { - assertTrue(true); - } - - public void testInterfaceRuleGetBundle() { - Bundle b = EasyMock.createMock(Bundle.class); - EasyMock.replay(b); - InterfaceRule ir = new InterfaceRule(b, "org.apache.Foo"); - assertSame(b, ir.getBundle()); - } - - public void testInterfaceRule1() { - InterfaceRule ir = new InterfaceRule(null, "org.apache.Foo"); - ir.addProperty("x", "y", String.class.getName()); - - final Map serviceProps = new HashMap(); - serviceProps.put(Constants.OBJECTCLASS, new String[] {"a.b.C", "org.apache.Foo"}); - ServiceReference sref = mockServiceReference(serviceProps); - - Map m = new HashMap(); - m.put("a", "b"); - ir.apply(sref, m); - Map expected = new HashMap(); - expected.put("a", "b"); - expected.put("x", "y"); - assertEquals(expected, m); - } - - public void testInterfaceRule2() { - InterfaceRule ir = new InterfaceRule(null, "org.apache.F(.*)"); - ir.addPropMatch("boo", "baah"); - ir.addProperty("x", "1", Integer.class.getName()); - ir.addProperty("aaa.bbb", "true", Boolean.class.getName()); - - final Map serviceProps = new HashMap(); - serviceProps.put("boo", "baah"); - serviceProps.put(Constants.OBJECTCLASS, new String[] {"a.b.C", "org.apache.Foo"}); - ServiceReference sref = mockServiceReference(serviceProps); - - Map m = new HashMap(); - ir.apply(sref, m); - Map expected = new HashMap(); - expected.put("x", 1); - expected.put("aaa.bbb", Boolean.TRUE); - assertEquals(expected, m); - } - - public void testInterfaceRule3() { - InterfaceRule ir = new InterfaceRule(null, "org.apache.F(.*)"); - ir.addProperty("x", "y", String.class.getName()); - - final Map serviceProps = new HashMap(); - serviceProps.put("boo", "baah"); - serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.apache.Boo"}); - ServiceReference sref = mockServiceReference(serviceProps); - - Map m = new HashMap(); - ir.apply(sref, m); - assertEquals(0, m.size()); - } - - public void testInterfaceRule4() { - InterfaceRule ir = new InterfaceRule(null, "org.apache.F(.*)"); - ir.addPropMatch("boo", "baah"); - ir.addProperty("x", "y", String.class.getName()); - - final Map serviceProps = new HashMap(); - serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.apache.Foo"}); - ServiceReference sref = mockServiceReference(serviceProps); - - Map m = new HashMap(); - ir.apply(sref, m); - assertEquals(0, m.size()); - } - - public void testInterfaceRule5() { - InterfaceRule ir = new InterfaceRule(null, "org.apache.Foo"); - ir.addPropMatch("test.int", "42"); - ir.addProperty("x", "1", Long.class.getName()); - - final Map serviceProps = new HashMap(); - serviceProps.put("test.int", 42); - serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.apache.Foo"}); - ServiceReference sref = mockServiceReference(serviceProps); - - Map m = new HashMap(); - m.put("x", "foo"); - m.put("aaa.bbb", Boolean.TRUE); - ir.apply(sref, m); - Map expected = new HashMap(); - expected.put("x", 1L); - expected.put("aaa.bbb", Boolean.TRUE); - assertEquals(expected, m); - } - - public void testInterfaceRule6() { - InterfaceRule ir = new InterfaceRule(null, "org.apache.Foo"); - ir.addPropMatch("test.int", "42"); - ir.addProperty("x", "1", Long.class.getName()); - - final Map serviceProps = new HashMap(); - serviceProps.put("test.int", 51); - serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.apache.Foo"}); - ServiceReference sref = mockServiceReference(serviceProps); - - Map m = new HashMap(); - m.put("x", "foo"); - m.put("aaa.bbb", Boolean.TRUE); - ir.apply(sref, m); - Map expected = new HashMap(); - expected.put("x", "foo"); - expected.put("aaa.bbb", Boolean.TRUE); - assertEquals(expected, m); - } - - private ServiceReference mockServiceReference(final Map serviceProps) { - ServiceReference sref = EasyMock.createMock(ServiceReference.class); - EasyMock.expect(sref.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer() { - public Object answer() throws Throwable { - return serviceProps.get(EasyMock.getCurrentArguments()[0]); - } - }).anyTimes(); - EasyMock.expect(sref.getPropertyKeys()) - .andReturn(serviceProps.keySet().toArray(new String[] {})).anyTimes(); - - EasyMock.replay(sref); - return sref; - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListenerTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListenerTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListenerTest.java deleted file mode 100644 index 1ca33fc..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListenerTest.java +++ /dev/null @@ -1,69 +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.decorator; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.easymock.EasyMock; -import org.junit.Test; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleEvent; - -import static org.junit.Assert.assertEquals; - -public class ServiceDecoratorBundleListenerTest { - - @Test - public void testBundleListener() { - BundleContext bc = EasyMock.createMock(BundleContext.class); - EasyMock.replay(bc); - - final List called = new ArrayList(); - ServiceDecoratorImpl serviceDecorator = new ServiceDecoratorImpl() { - @Override - void addDecorations(Bundle bundle) { - called.add("addDecorations"); - } - - @Override - void removeDecorations(Bundle bundle) { - called.add("removeDecorations"); - } - }; - - Bundle b = EasyMock.createMock(Bundle.class); - EasyMock.replay(b); - - ServiceDecoratorBundleListener listener = new ServiceDecoratorBundleListener(serviceDecorator); - - assertEquals("Precondition failed", 0, called.size()); - listener.bundleChanged(new BundleEvent(BundleEvent.INSTALLED, b)); - assertEquals(0, called.size()); - - listener.bundleChanged(new BundleEvent(BundleEvent.STARTED, b)); - assertEquals(Arrays.asList("addDecorations"), called); - - listener.bundleChanged(new BundleEvent(BundleEvent.STOPPING, b)); - assertEquals(Arrays.asList("addDecorations", "removeDecorations"), called); - - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImplTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImplTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImplTest.java deleted file mode 100644 index 400d793..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImplTest.java +++ /dev/null @@ -1,187 +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.decorator; - -import java.net.URL; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import junit.framework.TestCase; - -import org.easymock.EasyMock; -import org.easymock.IAnswer; -import org.junit.Assert; -import org.osgi.framework.Bundle; -import org.osgi.framework.Constants; -import org.osgi.framework.ServiceReference; - -public class ServiceDecoratorImplTest extends TestCase { - private static final Map EMPTY = new HashMap(); - private static final URL RES_SD = getResource("/test-resources/sd.xml"); - private static final URL RES_SD1 = getResource("/test-resources/sd1.xml"); - private static final URL RES_SD2 = getResource("/test-resources/sd2.xml"); - private static final URL RES_SD0 = getResource("/test-resources/sd0.xml"); - private static final URL RES_SD_1 = getResource("/test-resources/sd-1.xml"); - - @SuppressWarnings("rawtypes") - public void testAddRemoveDecorations() { - final Map serviceProps = new HashMap(); - serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.acme.foo.Bar"}); - serviceProps.put("test.prop", "xyz"); - - Bundle b = createBundleContaining(RES_SD); - ServiceDecoratorImpl sd = new ServiceDecoratorImpl(); - assertEquals("Precondition failed", 0, sd.decorations.size()); - sd.addDecorations(b); - assertEquals(1, sd.decorations.size()); - - Map target = new HashMap(); - ServiceReference sref = EasyMock.createMock(ServiceReference.class); - EasyMock.expect(sref.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer() { - public Object answer() throws Throwable { - return serviceProps.get(EasyMock.getCurrentArguments()[0]); - } - }).anyTimes(); - EasyMock.replay(sref); - sd.decorate(sref, target); - - Map expected = new HashMap(); - expected.put("test.too", "ahaha"); - assertEquals(expected, target); - - // remove it again - sd.removeDecorations(b); - assertEquals(0, sd.decorations.size()); - Map target2 = new HashMap(); - sd.decorate(sref, target2); - assertEquals(EMPTY, target2); - } - - public void testAddDecorations() { - final Map serviceProps = new HashMap(); - serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.acme.foo.Bar"}); - serviceProps.put("test.prop", "xyz"); - - Map expected = new HashMap(); - expected.put("test.too", "ahaha"); - assertDecorate(serviceProps, expected, RES_SD); - } - - public void testAddDecorations1() { - Map serviceProps = new HashMap(); - serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.A"}); - - Map expected = new HashMap(); - expected.put("A", "B"); - expected.put("C", 2); - assertDecorate(serviceProps, expected, RES_SD1, RES_SD2); - } - - public void testAddDecorations2() { - Map serviceProps = new HashMap(); - serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.D"}); - - assertDecorate(serviceProps, EMPTY, RES_SD1, RES_SD2); - } - - public void testAddDecorations3() { - Map serviceProps = new HashMap(); - serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.B"}); - serviceProps.put("x", "y"); - - Map expected = new HashMap(); - expected.put("bool", Boolean.TRUE); - assertDecorate(serviceProps, expected, RES_SD1, RES_SD2); - } - - public void testAddDecorations4() { - Map serviceProps = new HashMap(); - serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.C"}); - serviceProps.put("x", "z"); - - Map expected = new HashMap(); - expected.put("bool", Boolean.FALSE); - assertDecorate(serviceProps, expected, RES_SD1, RES_SD2); - } - - public void testAddDecorations5() { - Map serviceProps = new HashMap(); - serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.C"}); - serviceProps.put("x", "x"); - - assertDecorate(serviceProps, EMPTY, RES_SD1, RES_SD2); - } - - public void testAddDecorations6() { - Map serviceProps = new HashMap(); - serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.D"}); - - assertDecorate(serviceProps, EMPTY, RES_SD0); - } - - public void testAddDecorations7() { - Map serviceProps = new HashMap(); - serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.D"}); - - assertDecorate(serviceProps, EMPTY, RES_SD_1); - } - - private void assertDecorate(final Map serviceProps, - Map expected, URL ... resources) { - Map actual = testDecorate(serviceProps, resources); - assertEquals(expected, actual); - } - - @SuppressWarnings("rawtypes") - private Map testDecorate(final Map serviceProps, URL ... resources) { - Bundle b = createBundleContaining(resources); - - ServiceDecoratorImpl sd = new ServiceDecoratorImpl(); - sd.addDecorations(b); - - Map target = new HashMap(); - ServiceReference sref = EasyMock.createMock(ServiceReference.class); - EasyMock.expect(sref.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer() { - public Object answer() throws Throwable { - return serviceProps.get(EasyMock.getCurrentArguments()[0]); - } - }).anyTimes(); - EasyMock.replay(sref); - sd.decorate(sref, target); - return target; - } - - private Bundle createBundleContaining(URL... resources) { - Bundle b = EasyMock.createMock(Bundle.class); - EasyMock.expect(b.findEntries("OSGI-INF/remote-service", "*.xml", false)).andReturn( - Collections.enumeration(Arrays.asList(resources))).anyTimes(); - EasyMock.expect(b.getSymbolicName()).andReturn("bundlename"); - EasyMock.replay(b); - return b; - } - - private static URL getResource(String path) { - URL resource = ServiceDecoratorImplTest.class.getResource(path); - Assert.assertNotNull("Resource " + path + " not found!", resource); - return resource; - } - -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProviderTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProviderTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProviderTest.java deleted file mode 100644 index 8f58918..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProviderTest.java +++ /dev/null @@ -1,104 +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.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.cxf.dosgi.dsw.Constants; -import org.apache.cxf.dosgi.dsw.api.DistributionProvider; -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; -import org.osgi.framework.BundleContext; -import org.osgi.service.remoteserviceadmin.RemoteConstants; - -import static org.junit.Assert.assertTrue; - -public class CXFDistributionProviderTest { - - @Test - public void testGetDefaultHandlerNoIntents() { - DistributionProvider handler = getHandlerWith(null, null); - assertTrue(handler instanceof PojoConfigurationTypeHandler); - } - - @Test - public void testGetJaxrsHandlerNoIntents() { - DistributionProvider handler = getHandlerWith(Constants.RS_CONFIG_TYPE, null); - assertTrue(handler instanceof JaxRSPojoConfigurationTypeHandler); - } - - @Test - public void testGetJaxrsHandlerHttpIntents() { - DistributionProvider handler = getHandlerWith(Constants.RS_CONFIG_TYPE, "HTTP"); - assertTrue(handler instanceof JaxRSPojoConfigurationTypeHandler); - } - - @Test - public void testJaxrsPropertyIgnored() { - DistributionProvider handler = getHandlerWith(Constants.RS_CONFIG_TYPE, "SOAP HTTP"); - assertTrue(handler instanceof PojoConfigurationTypeHandler); - assertTrue(!(handler instanceof JaxRSPojoConfigurationTypeHandler)); - } - - @Test - public void testJaxrsPropertyIgnored2() { - DistributionProvider handler = getHandlerWith(Constants.RS_CONFIG_TYPE, new String[] {"HTTP", "SOAP"}); - assertTrue(handler instanceof PojoConfigurationTypeHandler); - assertTrue(!(handler instanceof JaxRSPojoConfigurationTypeHandler)); - } - - @Test - public void testGetPojoHandler() { - DistributionProvider handler = getHandlerWith(Constants.WS_CONFIG_TYPE, null); - assertTrue(handler instanceof PojoConfigurationTypeHandler); - } - - @Test - public void testGetWSDLHandler() { - DistributionProvider handler = getHandlerWith(Constants.WSDL_CONFIG_TYPE, null); - assertTrue(handler instanceof WsdlConfigurationTypeHandler); - } - - @Test - public void testUnsupportedConfiguration() { - DistributionProvider handler = getHandlerWith("notSupportedConfig", null); - Assert.assertNull(handler); - } - - private DistributionProvider getHandlerWith(String configType, Object intents) { - BundleContext bc = EasyMock.createNiceMock(BundleContext.class); - EasyMock.replay(bc); - Map serviceProps = new HashMap(); - serviceProps.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, configType); - 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 configurationTypes = f.determineConfigurationTypes(serviceProps); - return f.getHandler(configurationTypes, serviceProps); - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtilsTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtilsTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtilsTest.java deleted file mode 100644 index a0774be..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtilsTest.java +++ /dev/null @@ -1,134 +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.ArrayList; -import java.util.Collection; -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.Provider; -import org.easymock.EasyMock; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; - -public class ClassUtilsTest extends TestCase { - - public void testGetInterfaceClass() { - assertEquals(String.class, - ClassUtils.getInterfaceClass("Hello", "java.lang.String")); - assertNull(ClassUtils.getInterfaceClass("Hello", "java.lang.Integer")); - assertEquals(List.class, ClassUtils.getInterfaceClass( - new ArrayList(), "java.util.List")); - assertEquals(Collection.class, ClassUtils.getInterfaceClass( - new ArrayList(), "java.util.Collection")); - } - - public void testGetInterfaceClassFromSubclass() { - assertEquals(Map.class, ClassUtils.getInterfaceClass( - new MySubclassFour(), "java.util.Map")); - assertNull(ClassUtils.getInterfaceClass(new MySubclassFour(), - "java.util.UnknownType")); - } - - public void testLoadProvidersAsString() throws Exception { - BundleContext bc = mockBundleContext(); - Map sd = Collections.singletonMap("providers", Provider.class.getName()); - List 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 sd = Collections.singletonMap("providers", - new String[]{Provider.class.getName()}); - List providers = ClassUtils.loadProviderClasses(bc, sd, "providers"); - assertEquals(1, providers.size()); - assertTrue(providers.get(0) instanceof Provider); - } - - public void testLoadProvidersAsObject() throws Exception { - Map sd = Collections.singletonMap("providers", new Provider()); - List providers = ClassUtils.loadProviderClasses(null, sd, "providers"); - assertEquals(1, providers.size()); - assertTrue(providers.get(0) instanceof Provider); - } - - public void testLoadProvidersAsObjectArray() throws Exception { - Map sd = Collections.singletonMap("providers", new Object[]{new Provider()}); - List providers = ClassUtils.loadProviderClasses(null, sd, "providers"); - assertEquals(1, providers.size()); - assertTrue(providers.get(0) instanceof Provider); - } - - public void testLoadProvidersAsObjectList() throws Exception { - List list = new LinkedList(); - list.add(new Provider()); - Map sd = Collections.singletonMap("providers", list); - List providers = ClassUtils.loadProviderClasses(null, sd, "providers"); - assertEquals(1, providers.size()); - assertTrue(providers.get(0) instanceof Provider); - } - - public void testLoadProvidersAsStringList() throws Exception { - List list = new LinkedList(); - list.add(Provider.class.getName()); - Map sd = Collections.singletonMap("providers", list); - List 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/1425743f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java deleted file mode 100644 index 10fba12..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/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.handlers; - -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 captured = EasyMock.newCapture(); - dswContext.addServiceListener(EasyMock.capture(captured), EasyMock.anyObject()); - expectLastCall().atLeastOnce(); - expect(dswContext.getProperty("org.apache.cxf.httpservice.requirefilter")).andReturn(null).atLeastOnce(); - ServletConfig config = c.createMock(ServletConfig.class); - expect(config.getInitParameter(EasyMock.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/1425743f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java deleted file mode 100644 index 6c8e35a..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java +++ /dev/null @@ -1,195 +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.HashMap; -import java.util.List; -import java.util.Map; - -import junit.framework.TestCase; - -import org.apache.cxf.dosgi.dsw.Constants; -import org.apache.cxf.jaxrs.provider.JAXBElementProvider; -import org.apache.cxf.jaxrs.provider.aegis.AegisElementProvider; -import org.easymock.EasyMock; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.remoteserviceadmin.RemoteConstants; - -public class JaxRSUtilsTest extends TestCase { - - private void addRequiredProps(Map props) { - props.put(RemoteConstants.ENDPOINT_ID, "http://google.de"); - props.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "myGreatConfiguration"); - props.put(org.osgi.framework.Constants.OBJECTCLASS, new String[] {"my.class"}); - } - - public void testNoGlobalProviders() { - Map props = new HashMap(); - addRequiredProps(props); - props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false"); - - assertEquals(0, JaxRSUtils.getProviders(null, props).size()); - } - - public void testAegisProvider() { - Map props = new HashMap(); - props.put(Constants.RS_DATABINDING_PROP_KEY, "aegis"); - props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false"); - - addRequiredProps(props); - - List providers = JaxRSUtils.getProviders(null, props); - assertEquals(1, providers.size()); - assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName()); - } - - @SuppressWarnings("rawtypes") - public void testServiceProviders() { - Map props = new HashMap(); - props.put(Constants.RS_PROVIDER_PROP_KEY, new Object[] { - new AegisElementProvider() - }); - props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false"); - addRequiredProps(props); - - List providers = JaxRSUtils.getProviders(null, props); - assertEquals(1, providers.size()); - assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName()); - } - - public void testServiceProviderProperty() throws Exception { - BundleContext bc = EasyMock.createMock(BundleContext.class); - Bundle bundle = EasyMock.createMock(Bundle.class); - bc.getBundle(); - EasyMock.expectLastCall().andReturn(bundle).times(2); - bundle.loadClass(AegisElementProvider.class.getName()); - EasyMock.expectLastCall().andReturn(AegisElementProvider.class); - bundle.loadClass(JAXBElementProvider.class.getName()); - EasyMock.expectLastCall().andReturn(JAXBElementProvider.class); - EasyMock.replay(bc, bundle); - - Map props = new HashMap(); - props.put(Constants.RS_PROVIDER_PROP_KEY, - "\r\n " + AegisElementProvider.class.getName() + " , \r\n" - + JAXBElementProvider.class.getName() + "\r\n"); - - props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false"); - addRequiredProps(props); - - List providers = JaxRSUtils.getProviders(bc, props); - assertEquals(2, providers.size()); - assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName()); - assertEquals(JAXBElementProvider.class.getName(), providers.get(1).getClass().getName()); - } - - public void testServiceProviderStrings() throws Exception { - BundleContext bc = EasyMock.createMock(BundleContext.class); - Bundle bundle = EasyMock.createMock(Bundle.class); - bc.getBundle(); - EasyMock.expectLastCall().andReturn(bundle).times(2); - bundle.loadClass(AegisElementProvider.class.getName()); - EasyMock.expectLastCall().andReturn(AegisElementProvider.class); - bundle.loadClass(JAXBElementProvider.class.getName()); - EasyMock.expectLastCall().andReturn(JAXBElementProvider.class); - EasyMock.replay(bc, bundle); - - Map props = new HashMap(); - props.put(Constants.RS_PROVIDER_PROP_KEY, new String[] { - "\r\n " + AegisElementProvider.class.getName(), - JAXBElementProvider.class.getName() + "\r\n" - }); - - props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false"); - addRequiredProps(props); - - List providers = JaxRSUtils.getProviders(bc, props); - assertEquals(2, providers.size()); - assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName()); - assertEquals(JAXBElementProvider.class.getName(), providers.get(1).getClass().getName()); - } - - @SuppressWarnings({ - "rawtypes", "unchecked" - }) - public void testCustomGlobalProvider() throws Exception { - ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class); - BundleContext bc = EasyMock.createNiceMock(BundleContext.class); - bc.getServiceReferences((String)null, JaxRSUtils.PROVIDERS_FILTER); - EasyMock.expectLastCall().andReturn(new ServiceReference[] {sref}); - sref.getProperty(Constants.RS_PROVIDER_EXPECTED_PROP_KEY); - EasyMock.expectLastCall().andReturn(false); - bc.getService(sref); - AegisElementProvider p = new AegisElementProvider(); - EasyMock.expectLastCall().andReturn(p); - EasyMock.replay(bc, sref); - Map props = new HashMap(); - addRequiredProps(props); - - List providers = JaxRSUtils.getProviders(bc, props); - assertEquals(1, providers.size()); - assertSame(p, providers.get(0)); - } - - @SuppressWarnings({ - "rawtypes", "unchecked" - }) - public void testNoCustomGlobalProvider() throws Exception { - ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class); - BundleContext bc = EasyMock.createNiceMock(BundleContext.class); - bc.getServiceReferences((String)null, JaxRSUtils.PROVIDERS_FILTER); - EasyMock.expectLastCall().andReturn(new ServiceReference[] {sref}); - sref.getProperty(Constants.RS_PROVIDER_PROP_KEY); - EasyMock.expectLastCall().andReturn(false); - bc.getService(sref); - AegisElementProvider p = new AegisElementProvider(); - EasyMock.expectLastCall().andReturn(p); - EasyMock.replay(bc); - Map props = new HashMap(); - props.put(Constants.RS_PROVIDER_EXPECTED_PROP_KEY, "true"); - addRequiredProps(props); - - List providers = JaxRSUtils.getProviders(bc, props); - assertEquals(0, providers.size()); - } - - @SuppressWarnings({ - "rawtypes", "unchecked" - }) - public void testCustomGlobalProviderExpected() throws Exception { - ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class); - BundleContext bc = EasyMock.createNiceMock(BundleContext.class); - bc.getServiceReferences((String)null, JaxRSUtils.PROVIDERS_FILTER); - EasyMock.expectLastCall().andReturn(new ServiceReference[] {sref}); - sref.getProperty(Constants.RS_PROVIDER_PROP_KEY); - EasyMock.expectLastCall().andReturn(true); - bc.getService(sref); - AegisElementProvider p = new AegisElementProvider(); - EasyMock.expectLastCall().andReturn(p); - EasyMock.replay(bc, sref); - Map props = new HashMap(); - props.put(Constants.RS_PROVIDER_EXPECTED_PROP_KEY, "true"); - addRequiredProps(props); - - List providers = JaxRSUtils.getProviders(bc, props); - assertEquals(1, providers.size()); - assertSame(p, providers.get(0)); - } -}