You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by cs...@apache.org on 2012/11/22 16:51:49 UTC
svn commit: r1412593 - in /cxf/dosgi/trunk:
dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/
dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/
dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/
dsw/cxf-dsw/src/test/java/org/apache/cxf/dos...
Author: cschneider
Date: Thu Nov 22 15:51:46 2012
New Revision: 1412593
URL: http://svn.apache.org/viewvc?rev=1412593&view=rev
Log:
DOSGI-146 Add unit and integration test for custom intents
Added:
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImplTest.java
- copied, changed from r1412162, cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/IntentManagerTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java (with props)
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/AddGreetingPhraseInterceptor.java (with props)
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomFeature.java (with props)
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomIntentActivator.java (with props)
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/TestCustomIntent.java (with props)
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/service/
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/service/EmptyGreeterService.java (with props)
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/service/GreeterServiceWithCustomIntentActivator.java (with props)
Removed:
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiService.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/IntentManagerTest.java
Modified:
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java?rev=1412593&r1=1412592&r2=1412593&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java Thu Nov 22 15:51:46 2012
@@ -107,5 +107,7 @@ public class Constants {
//DSW Identification - TODO do we really need this one?
public static final String DSW_CLIENT_ID = PROVIDER_PREFIX + ".remote.dsw.client";
+
+ public static final String INTENT_NAME_PROP = "org.apache.cxf.dosgi.IntentName";
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java?rev=1412593&r1=1412592&r2=1412593&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java Thu Nov 22 15:51:46 2012
@@ -28,6 +28,7 @@ import java.util.Properties;
import java.util.Set;
import org.apache.cxf.binding.BindingConfiguration;
+import org.apache.cxf.dosgi.dsw.Constants;
import org.apache.cxf.endpoint.AbstractEndpointFactory;
import org.apache.cxf.feature.Feature;
import org.osgi.framework.BundleContext;
@@ -41,7 +42,6 @@ import org.slf4j.LoggerFactory;
public class IntentManagerImpl implements IntentManager {
private static final String PROVIDED_INTENT_VALUE = "PROVIDED";
private static final Logger LOG = LoggerFactory.getLogger(IntentManagerImpl.class);
- private static final String INTENT_NAME_PROP = "org.apache.cxf.dosgi.IntentName";
private final IntentMap intentMap;
private final ServiceTracker intentTracker;
@@ -55,7 +55,7 @@ public class IntentManagerImpl implement
this.intentMap = intentMap;
Filter filter;
try {
- filter = bc.createFilter("(" + INTENT_NAME_PROP + "=*)");
+ filter = bc.createFilter("(" + Constants.INTENT_NAME_PROP + "=*)");
} catch (InvalidSyntaxException e) {
throw new RuntimeException(e.getMessage(), e);
}
@@ -63,16 +63,16 @@ public class IntentManagerImpl implement
@Override
public Object addingService(ServiceReference reference) {
- String intentName = (String) reference.getProperty(INTENT_NAME_PROP);
+ String intentName = (String) reference.getProperty(Constants.INTENT_NAME_PROP);
Object intent = bc.getService(reference);
- LOG.info("Adding custom intent " + intentName + " defined in bundle " + reference.getBundle().getSymbolicName());
+ LOG.info("Adding custom intent " + intentName);
intentMap.put(intentName, intent);
return super.addingService(reference);
}
@Override
public void removedService(ServiceReference reference, Object service) {
- String intentName = (String) reference.getProperty(INTENT_NAME_PROP);
+ String intentName = (String) reference.getProperty(Constants.INTENT_NAME_PROP);
intentMap.remove(intentName);
super.removedService(reference, service);
}
Copied: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImplTest.java (from r1412162, cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/IntentManagerTest.java)
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImplTest.java?p2=cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImplTest.java&p1=cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/IntentManagerTest.java&r1=1412162&r2=1412593&rev=1412593&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/IntentManagerTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImplTest.java Thu Nov 22 15:51:46 2012
@@ -16,10 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.cxf.dosgi.dsw.service;
+package org.apache.cxf.dosgi.dsw.qos;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
+import static org.easymock.EasyMock.expect;
import java.util.ArrayList;
import java.util.Arrays;
@@ -33,21 +34,23 @@ import junit.framework.Assert;
import org.apache.cxf.binding.BindingConfiguration;
import org.apache.cxf.dosgi.dsw.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.apache.cxf.dosgi.dsw.qos.IntentUnsatifiedException;
import org.apache.cxf.endpoint.AbstractEndpointFactory;
import org.apache.cxf.feature.AbstractFeature;
import org.apache.cxf.feature.Feature;
+import org.easymock.Capture;
import org.easymock.classextension.EasyMock;
import org.easymock.classextension.IMocksControl;
import org.junit.Before;
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;
-public class IntentManagerTest {
+public class IntentManagerImplTest {
+ private static final String MY_INTENT_NAME = "myIntent";
private Map<String, Object> handlerProps;
@Before
@@ -284,7 +287,43 @@ public class IntentManagerTest {
assertEquals(expectedIntents, effectiveIntents);
}
-
+ @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);
+ expect(bc.getProperty(org.osgi.framework.Constants.FRAMEWORK_VERSION)).andReturn("1.6.0");
+ final Capture<ServiceListener> capturedListener = new Capture<ServiceListener>();
+ 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
+ ServiceReference reference = c.createMock(ServiceReference.class);
+ expect(reference.getProperty(Constants.INTENT_NAME_PROP)).andReturn(MY_INTENT_NAME);
+ TestFeature testIntent = new TestFeature(MY_INTENT_NAME);
+ expect(bc.getService(reference)).andReturn(testIntent).atLeastOnce();
+
+ c.replay();
+
+ new IntentManagerImpl(bc, intentMap);
+ 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();
+
+ }
+
private static class TestFeature extends AbstractFeature {
private final String name;
Added: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java?rev=1412593&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java Thu Nov 22 15:51:46 2012
@@ -0,0 +1,42 @@
+/**
+ * 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.Test;
+
+import junit.framework.Assert;
+
+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"));
+ }
+}
Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/AddGreetingPhraseInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/AddGreetingPhraseInterceptor.java?rev=1412593&view=auto
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/AddGreetingPhraseInterceptor.java (added)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/AddGreetingPhraseInterceptor.java Thu Nov 22 15:51:46 2012
@@ -0,0 +1,42 @@
+/**
+ * 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.systests2.multi.customintent;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.dosgi.samples.greeter.GreetingPhrase;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageContentsList;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+
+public final class AddGreetingPhraseInterceptor extends AbstractPhaseInterceptor<Message> {
+ AddGreetingPhraseInterceptor(String phase) {
+ super(phase);
+ }
+
+ public void handleMessage(Message message) throws Fault {
+ MessageContentsList contents = (MessageContentsList) message.getContent(List.class);
+ Map<GreetingPhrase, String> result = (Map<GreetingPhrase, String>) contents.get(0);
+ result.put(new GreetingPhrase("Hi from custom intent"), "customintent");
+ //Object content1 = contents.iterator().next();
+ System.out.println(message);
+ }
+}
\ No newline at end of file
Propchange: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/AddGreetingPhraseInterceptor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomFeature.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomFeature.java?rev=1412593&view=auto
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomFeature.java (added)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomFeature.java Thu Nov 22 15:51:46 2012
@@ -0,0 +1,32 @@
+/**
+ * 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.systests2.multi.customintent;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.interceptor.InterceptorProvider;
+import org.apache.cxf.phase.Phase;
+
+public final class CustomFeature extends AbstractFeature {
+ @Override
+ protected void initializeProvider(InterceptorProvider provider, Bus bus) {
+ provider.getOutInterceptors().add(0, new AddGreetingPhraseInterceptor(Phase.USER_LOGICAL));
+ super.initializeProvider(provider, bus);
+ }
+}
\ No newline at end of file
Propchange: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomFeature.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomIntentActivator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomIntentActivator.java?rev=1412593&view=auto
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomIntentActivator.java (added)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomIntentActivator.java Thu Nov 22 15:51:46 2012
@@ -0,0 +1,38 @@
+/**
+ * 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.systests2.multi.customintent;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class CustomIntentActivator implements BundleActivator {
+
+ public void start(BundleContext context) throws Exception {
+ Dictionary<String, String> props = new Hashtable<String, String>();
+ props.put("org.apache.cxf.dosgi.IntentName", "myIntent");
+ context.registerService(Object.class.getName(), new CustomFeature(), props);
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ }
+
+}
Propchange: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomIntentActivator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/TestCustomIntent.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/TestCustomIntent.java?rev=1412593&view=auto
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/TestCustomIntent.java (added)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/TestCustomIntent.java Thu Nov 22 15:51:46 2012
@@ -0,0 +1,133 @@
+/**
+ * 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.systests2.multi.customintent;
+
+import static org.ops4j.pax.exam.CoreOptions.frameworkStartLevel;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.Socket;
+import java.util.Map;
+import java.util.concurrent.TimeoutException;
+
+import javax.inject.Inject;
+
+import junit.framework.Assert;
+
+import org.apache.cxf.aegis.databinding.AegisDatabinding;
+import org.apache.cxf.dosgi.samples.greeter.GreeterService;
+import org.apache.cxf.dosgi.samples.greeter.GreetingPhrase;
+import org.apache.cxf.dosgi.systests2.common.AbstractTestExportService;
+import org.apache.cxf.dosgi.systests2.multi.MultiBundleTools;
+import org.apache.cxf.dosgi.systests2.multi.customintent.service.EmptyGreeterService;
+import org.apache.cxf.dosgi.systests2.multi.customintent.service.GreeterServiceWithCustomIntentActivator;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.swissbox.tinybundles.core.TinyBundles;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+
+@RunWith(JUnit4TestRunner.class)
+public class TestCustomIntent extends AbstractTestExportService {
+ @Inject
+ BundleContext bundleContext;
+
+ protected static InputStream getCustomIntentBundle() {
+ return TinyBundles.newBundle()
+ .add(CustomIntentActivator.class)
+ .add(CustomFeature.class)
+ .add(AddGreetingPhraseInterceptor.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "CustomIntent")
+ .set(Constants.BUNDLE_ACTIVATOR, CustomIntentActivator.class.getName()).build(TinyBundles.withBnd());
+ }
+
+ protected static InputStream getServiceBundle() {
+ return TinyBundles.newBundle()
+ .add(GreeterServiceWithCustomIntentActivator.class)
+ .add(EmptyGreeterService.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "EmptyGreeterService")
+ .set(Constants.BUNDLE_ACTIVATOR, GreeterServiceWithCustomIntentActivator.class.getName())
+ .build(TinyBundles.withBnd());
+ }
+
+ @Configuration
+ public static Option[] configure() throws Exception {
+ return new Option[] {
+ MultiBundleTools.getDistro(),
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+ mavenBundle().groupId("org.apache.servicemix.bundles")
+ .artifactId("org.apache.servicemix.bundles.junit").version("4.9_2"),
+ mavenBundle().groupId("org.apache.cxf.dosgi.samples")
+ .artifactId("cxf-dosgi-ri-samples-greeter-interface").versionAsInProject(),
+ mavenBundle().groupId("org.apache.cxf.dosgi.systests").artifactId("cxf-dosgi-ri-systests2-common")
+ .versionAsInProject(), provision(getCustomIntentBundle()), provision(getServiceBundle()),
+ frameworkStartLevel(100) };
+ }
+
+ @Test
+ public void testAccessEndpoint() throws Exception {
+ waitPort(9090);
+ ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
+ factory.setServiceClass(GreeterService.class);
+ factory.setAddress("http://localhost:9090/greeter");
+ factory.getServiceFactory().setDataBinding(new AegisDatabinding());
+ factory.setServiceClass(GreeterService.class);
+
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(ClientProxyFactoryBean.class.getClassLoader());
+ try {
+ GreeterService greeterService = (GreeterService) factory.create();
+ Map<GreetingPhrase, String> result = greeterService.greetMe("Chris");
+ Assert.assertEquals(1, result.size());
+ GreetingPhrase phrase = result.keySet().iterator().next();
+ Assert.assertEquals("Hi from custom intent", phrase.getPhrase());
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
+ }
+ }
+
+ private void waitPort(int port) throws Exception {
+ for (int i = 0; i < 20; i++) {
+ Socket s = null;
+ try {
+ s = new Socket((String) null, port);
+ // yep, its available
+ return;
+ } catch (IOException e) {
+ // wait
+ } finally {
+ if (s != null) {
+ try {
+ s.close();
+ } catch (IOException e) {}
+ }
+ }
+ System.out.println("Waiting for server to appear on port: " + port);
+ Thread.sleep(10000);
+ }
+ throw new TimeoutException();
+ }
+}
Propchange: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/TestCustomIntent.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/service/EmptyGreeterService.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/service/EmptyGreeterService.java?rev=1412593&view=auto
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/service/EmptyGreeterService.java (added)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/service/EmptyGreeterService.java Thu Nov 22 15:51:46 2012
@@ -0,0 +1,41 @@
+/**
+ * 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.systests2.multi.customintent.service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.cxf.dosgi.samples.greeter.GreeterData;
+import org.apache.cxf.dosgi.samples.greeter.GreeterException;
+import org.apache.cxf.dosgi.samples.greeter.GreeterService;
+import org.apache.cxf.dosgi.samples.greeter.GreetingPhrase;
+
+public final class EmptyGreeterService implements GreeterService {
+ /**
+ * Return an empty array. Our custom intent should add a GreetingPhrase
+ */
+ public GreetingPhrase[] greetMe(GreeterData name) throws GreeterException {
+ return new GreetingPhrase[]{};
+ }
+
+ public Map<GreetingPhrase, String> greetMe(String name) {
+ HashMap<GreetingPhrase, String> result = new HashMap<GreetingPhrase, String>();
+ return result;
+ }
+}
\ No newline at end of file
Propchange: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/service/EmptyGreeterService.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/service/GreeterServiceWithCustomIntentActivator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/service/GreeterServiceWithCustomIntentActivator.java?rev=1412593&view=auto
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/service/GreeterServiceWithCustomIntentActivator.java (added)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/service/GreeterServiceWithCustomIntentActivator.java Thu Nov 22 15:51:46 2012
@@ -0,0 +1,43 @@
+/**
+ * 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.systests2.multi.customintent.service;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.cxf.dosgi.samples.greeter.GreeterService;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+
+public class GreeterServiceWithCustomIntentActivator implements BundleActivator{
+
+ public void start(BundleContext context) throws Exception {
+ Dictionary<String, String> props = new Hashtable<String, String>();
+ props.put(RemoteConstants.SERVICE_EXPORTED_INTERFACES, "*");
+ props.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, "org.apache.cxf.ws");
+ props.put("org.apache.cxf.ws.address", "http://localhost:9090/greeter");
+ props.put(RemoteConstants.SERVICE_EXPORTED_INTENTS, "myIntent");
+ context.registerService(GreeterService.class.getName(), new EmptyGreeterService(), props);
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ }
+
+}
Propchange: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/service/GreeterServiceWithCustomIntentActivator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain