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 74207195F3 for ; Mon, 7 Mar 2016 23:49:04 +0000 (UTC) Received: (qmail 11911 invoked by uid 500); 7 Mar 2016 23:49:04 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 11824 invoked by uid 500); 7 Mar 2016 23:49:04 -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 11813 invoked by uid 99); 7 Mar 2016 23:49:04 -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; Mon, 07 Mar 2016 23:49:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 233BFDFBD7; Mon, 7 Mar 2016 23:49:04 +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: Mon, 07 Mar 2016 23:49:04 -0000 Message-Id: <3a73dc44faf542f19e4b545f86b34647@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/4] cxf-dosgi git commit: [DOSGI-229] Use separate bundles for API and RSA impl. Remove dynamic import Repository: cxf-dosgi Updated Branches: refs/heads/master 84f6be48a -> 4ed2614db http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4ed2614d/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java deleted file mode 100644 index c9eae7b..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java +++ /dev/null @@ -1,491 +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.service; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.Collection; -import java.util.Dictionary; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; - -import org.apache.cxf.dosgi.dsw.api.DistributionProvider; -import org.apache.cxf.dosgi.dsw.api.Endpoint; -import org.easymock.EasyMock; -import org.easymock.IAnswer; -import org.easymock.IMocksControl; -import org.junit.Test; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Constants; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceListener; -import org.osgi.framework.ServiceReference; -import org.osgi.service.remoteserviceadmin.EndpointDescription; -import org.osgi.service.remoteserviceadmin.ExportRegistration; -import org.osgi.service.remoteserviceadmin.ImportRegistration; -import org.osgi.service.remoteserviceadmin.RemoteConstants; - -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.isA; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -@SuppressWarnings({ - "rawtypes", "unchecked" - }) -public class RemoteServiceAdminCoreTest { - - private static final String MYCONFIG = "myconfig"; - - @Test - public void testDontExportOwnServiceProxies() throws InvalidSyntaxException { - IMocksControl c = EasyMock.createControl(); - Bundle b = c.createMock(Bundle.class); - BundleContext bc = c.createMock(BundleContext.class); - - EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes(); - bc.addServiceListener(EasyMock.anyObject(), EasyMock.anyObject()); - EasyMock.expectLastCall().anyTimes(); - bc.removeServiceListener(EasyMock.anyObject()); - EasyMock.expectLastCall().anyTimes(); - - Dictionary d = new Hashtable(); - EasyMock.expect(b.getHeaders()).andReturn(d).anyTimes(); - - ServiceReference sref = c.createMock(ServiceReference.class); - EasyMock.expect(sref.getBundle()).andReturn(b).anyTimes(); - EasyMock.expect(sref.getPropertyKeys()) - .andReturn(new String[]{"objectClass", "service.exported.interfaces"}).anyTimes(); - EasyMock.expect(sref.getProperty("objectClass")).andReturn(new String[] {"a.b.C"}).anyTimes(); - EasyMock.expect(sref.getProperty(RemoteConstants.SERVICE_IMPORTED)).andReturn(true).anyTimes(); - EasyMock.expect(sref.getProperty("service.exported.interfaces")).andReturn("*").anyTimes(); - - DistributionProvider provider = c.createMock(DistributionProvider.class); - - c.replay(); - - RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, provider); - - // must return an empty List as sref if from the same bundle - List exRefs = rsaCore.exportService(sref, null); - - assertNotNull(exRefs); - assertEquals(0, exRefs.size()); - - // must be empty - assertEquals(rsaCore.getExportedServices().size(), 0); - - c.verify(); - } - - @Test - public void testImport() { - IMocksControl c = EasyMock.createNiceControl(); - Bundle b = c.createMock(Bundle.class); - BundleContext bc = c.createMock(BundleContext.class); - - Dictionary d = new Hashtable(); - EasyMock.expect(b.getHeaders()).andReturn(d).anyTimes(); - - EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes(); - EasyMock.expect(b.getSymbolicName()).andReturn("BundleName").anyTimes(); - - EndpointDescription endpoint = creatEndpointDesc("unsupportedConfiguration"); - - DistributionProvider provider = c.createMock(DistributionProvider.class); - EasyMock.expect(provider.getSupportedTypes()) - .andReturn(new String[]{MYCONFIG}).atLeastOnce(); - c.replay(); - - RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, provider); - - // must be null as the endpoint doesn't contain any usable configurations - assertNull(rsaCore.importService(endpoint)); - // must be empty - assertEquals(0, rsaCore.getImportedEndpoints().size()); - - EndpointDescription endpoint2 = creatEndpointDesc(MYCONFIG); - - ImportRegistration ireg = rsaCore.importService(endpoint2); - assertNotNull(ireg); - - assertEquals(1, rsaCore.getImportedEndpoints().size()); - - // lets import the same endpoint once more -> should get a copy of the ImportRegistration - ImportRegistration ireg2 = rsaCore.importService(endpoint2); - assertNotNull(ireg2); - assertEquals(2, rsaCore.getImportedEndpoints().size()); - - assertEquals(ireg.getImportReference(), (rsaCore.getImportedEndpoints().toArray())[0]); - - assertEquals(ireg.getImportReference().getImportedEndpoint(), ireg2.getImportReference() - .getImportedEndpoint()); - - // remove the registration - - // first call shouldn't remove the import - ireg2.close(); - assertEquals(1, rsaCore.getImportedEndpoints().size()); - - // second call should really close and remove the import - ireg.close(); - assertEquals(0, rsaCore.getImportedEndpoints().size()); - - c.verify(); - } - - private EndpointDescription creatEndpointDesc(String configType) { - Map p = new HashMap(); - p.put(RemoteConstants.ENDPOINT_ID, "http://google.de"); - p.put(Constants.OBJECTCLASS, new String[] { - "es.schaaf.my.class" - }); - p.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, configType); - EndpointDescription endpoint = new EndpointDescription(p); - return endpoint; - } - - @Test - public void testExport() throws Exception { - BundleContext bc = EasyMock.createMock(BundleContext.class); - EasyMock.expect(bc.getProperty(Constants.FRAMEWORK_VERSION)).andReturn(null).anyTimes(); - bc.addServiceListener(EasyMock.anyObject(), EasyMock.anyObject()); - EasyMock.expectLastCall().anyTimes(); - bc.removeServiceListener(EasyMock.anyObject()); - EasyMock.expectLastCall().anyTimes(); - EasyMock.expect(bc.getServiceReferences(EasyMock.anyObject(), - EasyMock.anyObject())).andReturn(null).anyTimes(); - EasyMock.expect(bc.getAllServiceReferences(EasyMock.anyObject(), - EasyMock.anyObject())).andReturn(null).anyTimes(); - - Bundle b = createDummyRsaBundle(bc); - - final Map sProps = new HashMap(); - sProps.put("objectClass", new String[] {"java.lang.Runnable"}); - sProps.put("service.id", 51L); - sProps.put("myProp", "myVal"); - sProps.put("service.exported.interfaces", "*"); - ServiceReference sref = mockServiceReference(sProps); - - Runnable svcObject = EasyMock.createNiceMock(Runnable.class); - EasyMock.replay(svcObject); - - EasyMock.expect(bc.getService(sref)).andReturn(svcObject).anyTimes(); - EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes(); - EasyMock.expect(bc.createFilter("(service.id=51)")) - .andReturn(FrameworkUtil.createFilter("(service.id=51)")).anyTimes(); - EasyMock.replay(bc); - - Map eProps = new HashMap(sProps); - eProps.put("endpoint.id", "http://something"); - eProps.put("service.imported.configs", new String[] {"org.apache.cxf.ws"}); - final EndpointDescription epd = new EndpointDescription(eProps); - Endpoint er = new Endpoint() { - - @Override - public void close() throws IOException { - } - - @Override - public EndpointDescription description() { - return epd; - } - }; - - DistributionProvider handler = EasyMock.createMock(DistributionProvider.class); - EasyMock.expect(handler.exportService(anyObject(ServiceReference.class), - anyObject(Map.class), isA(Class[].class))).andReturn(er); - EasyMock.replay(handler); - - RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, handler); - - // Export the service for the first time - List ereg = rsaCore.exportService(sref, null); - assertEquals(1, ereg.size()); - assertNull(ereg.get(0).getException()); - assertSame(sref, ereg.get(0).getExportReference().getExportedService()); - EndpointDescription endpoint = ereg.get(0).getExportReference().getExportedEndpoint(); - - Map edProps = endpoint.getProperties(); - assertEquals("http://something", edProps.get("endpoint.id")); - assertNotNull(edProps.get("service.imported")); - assertTrue(Arrays.equals(new String[] {"java.lang.Runnable"}, - (Object[]) edProps.get("objectClass"))); - assertTrue(Arrays.equals(new String[] {"org.apache.cxf.ws"}, - (Object[]) edProps.get("service.imported.configs"))); - - // Ask to export the same service again, this should not go through the whole process again but simply return - // a copy of the first instance. - final Map sProps2 = new HashMap(); - sProps2.put("objectClass", new String[] {"java.lang.Runnable"}); - sProps2.put("service.id", 51L); - sProps2.put("service.exported.interfaces", "*"); - ServiceReference sref2 = mockServiceReference(sProps2); - Map props2 = new HashMap(); - props2.put("myProp", "myVal"); - List ereg2 = rsaCore.exportService(sref2, props2); - - assertEquals(1, ereg2.size()); - assertNull(ereg2.get(0).getException()); - assertEquals(ereg.get(0).getExportReference().getExportedEndpoint().getProperties(), - ereg2.get(0).getExportReference().getExportedEndpoint().getProperties()); - - // Look at the exportedServices data structure - Field field = RemoteServiceAdminCore.class.getDeclaredField("exportedServices"); - field.setAccessible(true); - Map, Collection> exportedServices = - (Map, Collection>) field.get(rsaCore); - - assertEquals("One service was exported", 1, exportedServices.size()); - assertEquals("There are 2 export registrations (identical copies)", - 2, exportedServices.values().iterator().next().size()); - - // Unregister one of the exports - rsaCore.removeExportRegistration((ExportRegistrationImpl) ereg.get(0)); - assertEquals("One service was exported", 1, exportedServices.size()); - assertEquals("There 1 export registrations left", - 1, exportedServices.values().iterator().next().size()); - - // Unregister the other export - rsaCore.removeExportRegistration((ExportRegistrationImpl) ereg2.get(0)); - assertEquals("No more exported services", 0, exportedServices.size()); - } - - private Bundle createDummyRsaBundle(BundleContext bc) { - Bundle b = EasyMock.createNiceMock(Bundle.class); - EasyMock.expect(b.getBundleContext()).andReturn(bc).anyTimes(); - EasyMock.expect(b.getSymbolicName()).andReturn("rsabundle").anyTimes(); - EasyMock.expect(b.getHeaders()).andReturn(new Hashtable()).anyTimes(); - EasyMock.replay(b); - return b; - } - - @Test - public void testExportException() throws Exception { - BundleContext bc = EasyMock.createNiceMock(BundleContext.class); - - Bundle b = createDummyRsaBundle(bc); - - final Map sProps = new HashMap(); - sProps.put("objectClass", new String[] {"java.lang.Runnable"}); - sProps.put("service.id", 51L); - sProps.put("service.exported.interfaces", "*"); - ServiceReference sref = mockServiceReference(sProps); - - Runnable svcObject = EasyMock.createNiceMock(Runnable.class); - EasyMock.replay(svcObject); - - EasyMock.expect(bc.getService(sref)).andReturn(svcObject).anyTimes(); - EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes(); - EasyMock.replay(bc); - - Map eProps = new HashMap(sProps); - eProps.put("endpoint.id", "http://something"); - eProps.put("service.imported.configs", new String[] {"org.apache.cxf.ws"}); - - DistributionProvider handler = EasyMock.createMock(DistributionProvider.class); - EasyMock.expect(handler.exportService(anyObject(ServiceReference.class), - anyObject(Map.class), isA(Class[].class))).andThrow(new TestException()); - EasyMock.replay(handler); - - RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, handler); - - List ereg = rsaCore.exportService(sref, sProps); - assertEquals(1, ereg.size()); - assertTrue(ereg.get(0).getException() instanceof TestException); - - // Look at the exportedServices data structure - Field field = RemoteServiceAdminCore.class.getDeclaredField("exportedServices"); - field.setAccessible(true); - Map, Collection> exportedServices = - (Map, Collection>) field.get(rsaCore); - - assertEquals("One service was exported", 1, exportedServices.size()); - assertEquals("There is 1 export registration", - 1, exportedServices.values().iterator().next().size()); - - } - - private ServiceReference mockServiceReference(final Map sProps) throws ClassNotFoundException { - BundleContext bc = EasyMock.createNiceMock(BundleContext.class); - - Bundle b = EasyMock.createNiceMock(Bundle.class); - EasyMock.expect(b.getBundleContext()).andReturn(bc).anyTimes(); - EasyMock.expect((Class)b.loadClass(Runnable.class.getName())).andReturn(Runnable.class); - EasyMock.replay(b); - - EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes(); - EasyMock.replay(bc); - - ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class); - EasyMock.expect(sref.getBundle()).andReturn(b).anyTimes(); - EasyMock.expect(sref.getPropertyKeys()).andReturn(sProps.keySet().toArray(new String[] {})).anyTimes(); - EasyMock.expect(sref.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer() { - @Override - public Object answer() throws Throwable { - return sProps.get(EasyMock.getCurrentArguments()[0]); - } - }).anyTimes(); - EasyMock.replay(sref); - return sref; - } - - @SuppressWarnings("serial") - private static class TestException extends RuntimeException { - } - - @Test - public void testOverlayProperties() { - Map sProps = new HashMap(); - Map aProps = new HashMap(); - - RemoteServiceAdminCore.overlayProperties(sProps, aProps); - assertEquals(0, sProps.size()); - - sProps.put("aaa", "aval"); - sProps.put("bbb", "bval"); - sProps.put(Constants.OBJECTCLASS, new String[] {"X"}); - sProps.put(Constants.SERVICE_ID, 17L); - - aProps.put("AAA", "achanged"); - aProps.put("CCC", "CVAL"); - aProps.put(Constants.OBJECTCLASS, new String[] {"Y"}); - aProps.put(Constants.SERVICE_ID.toUpperCase(), 51L); - - Map aPropsOrg = new HashMap(aProps); - RemoteServiceAdminCore.overlayProperties(sProps, aProps); - assertEquals("The additional properties should not be modified", aPropsOrg, aProps); - - assertEquals(5, sProps.size()); - assertEquals("achanged", sProps.get("aaa")); - assertEquals("bval", sProps.get("bbb")); - assertEquals("CVAL", sProps.get("CCC")); - assertTrue("Should not be possible to override the objectClass property", - Arrays.equals(new String[] {"X"}, (Object[]) sProps.get(Constants.OBJECTCLASS))); - assertEquals("Should not be possible to override the service.id property", - 17L, sProps.get(Constants.SERVICE_ID)); - } - - @Test - public void testOverlayProperties2() { - Map original = new HashMap(); - - original.put("MyProp", "my value"); - original.put(Constants.OBJECTCLASS, "myClass"); - - Map copy = new HashMap(); - copy.putAll(original); - - // nothing should change here - Map overload = new HashMap(); - RemoteServiceAdminCore.overlayProperties(copy, overload); - - assertEquals(original.size(), copy.size()); - for (Object key : original.keySet()) { - assertEquals(original.get(key), copy.get(key)); - } - - copy.clear(); - copy.putAll(original); - - // a property should be added - overload = new HashMap(); - overload.put("new", "prop"); - - RemoteServiceAdminCore.overlayProperties(copy, overload); - - assertEquals(original.size() + 1, copy.size()); - for (Object key : original.keySet()) { - assertEquals(original.get(key), copy.get(key)); - } - assertNotNull(overload.get("new")); - assertEquals("prop", overload.get("new")); - - copy.clear(); - copy.putAll(original); - - // only one property should be added - overload = new HashMap(); - overload.put("new", "prop"); - overload.put("NEW", "prop"); - - RemoteServiceAdminCore.overlayProperties(copy, overload); - - assertEquals(original.size() + 1, copy.size()); - for (Object key : original.keySet()) { - assertEquals(original.get(key), copy.get(key)); - } - assertNotNull(overload.get("new")); - assertEquals("prop", overload.get("new")); - - copy.clear(); - copy.putAll(original); - - // nothing should change here - overload = new HashMap(); - overload.put(Constants.OBJECTCLASS, "assd"); - overload.put(Constants.SERVICE_ID, "asasdasd"); - RemoteServiceAdminCore.overlayProperties(copy, overload); - - assertEquals(original.size(), copy.size()); - for (Object key : original.keySet()) { - assertEquals(original.get(key), copy.get(key)); - } - - copy.clear(); - copy.putAll(original); - - // overwrite own prop - overload = new HashMap(); - overload.put("MyProp", "newValue"); - RemoteServiceAdminCore.overlayProperties(copy, overload); - - assertEquals(original.size(), copy.size()); - for (Object key : original.keySet()) { - if (!"MyProp".equals(key)) { - assertEquals(original.get(key), copy.get(key)); - } - } - assertEquals("newValue", copy.get("MyProp")); - - copy.clear(); - copy.putAll(original); - - // overwrite own prop in different case - overload = new HashMap(); - overload.put("MYPROP", "newValue"); - RemoteServiceAdminCore.overlayProperties(copy, overload); - - assertEquals(original.size(), copy.size()); - for (Object key : original.keySet()) { - if (!"MyProp".equals(key)) { - assertEquals(original.get(key), copy.get(key)); - } - } - assertEquals("newValue", copy.get("MyProp")); - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4ed2614d/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/StringPlusTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/StringPlusTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/StringPlusTest.java deleted file mode 100644 index 5447966..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/StringPlusTest.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.service; - -import java.util.ArrayList; -import java.util.Collection; - -import org.junit.Test; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; - -public class StringPlusTest { - - @Test - public void testSplitString() { - String[] values = StringPlus.normalize("1, 2"); - assertEquals(2, values.length); - assertEquals(values[0], "1"); - assertEquals(values[1], "2"); - } - - @Test - public void testNormalizeStringPlus() { - String s1 = "s1"; - String s2 = "s2"; - String s3 = "s3"; - - String[] sa = new String[] { - s1, s2, s3 - }; - - Collection sl = new ArrayList(4); - sl.add(s1); - sl.add(s2); - sl.add(s3); - sl.add(new Object()); // must be skipped - - assertArrayEquals(null, StringPlus.normalize(new Object())); - assertArrayEquals(new String[] { - s1 - }, StringPlus.normalize(s1)); - assertArrayEquals(sa, StringPlus.normalize(sa)); - assertArrayEquals(sa, StringPlus.normalize(sl)); - } - -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4ed2614d/dsw/pom.xml ---------------------------------------------------------------------- diff --git a/dsw/pom.xml b/dsw/pom.xml index 121a7c3..becd4ea 100644 --- a/dsw/pom.xml +++ b/dsw/pom.xml @@ -41,5 +41,7 @@ cxf-dsw cxf-topology-manager + cxf-dosgi-provider-api + cxf-dosgi-rsa