Author: davidb
Date: Thu Feb 7 11:37:33 2013
New Revision: 1443422
URL: http://svn.apache.org/viewvc?rev=1443422&view=rev
Log:
Additional unit tests for the PojoConfigurationTypeHandler.
Modified:
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
Modified:
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java?rev=1443422&r1=1443421&r2=1443422&view=diff
==============================================================================
---
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
(original)
+++
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
Thu Feb 7 11:37:33 2013
@@ -184,7 +184,7 @@ public abstract class AbstractPojoConfig
}
protected String getClientAddress(Map<String, Object> sd, Class<?> iClass)
{
- return OsgiUtils.getFirstNonEmptyStringProperty(sd,
RemoteConstants.ENDPOINT_ID, Constants.WS_ADDRESS_PROPERTY,
+ return OsgiUtils.getFirstNonEmptyStringProperty(sd,
RemoteConstants.ENDPOINT_ID,
Constants.WS_ADDRESS_PROPERTY,
Constants.WS_ADDRESS_PROPERTY_OLD,
Constants.RS_ADDRESS_PROPERTY);
@@ -201,7 +201,7 @@ public abstract class AbstractPojoConfig
return address == null ? httpServiceManager.getDefaultAddress(iClass)
: address;
}
- protected final ExportResult createServerFromFactory(ServerFactoryBean
factory, Map<String, Object> endpointProps) {
+ protected ExportResult createServerFromFactory(ServerFactoryBean factory,
Map<String, Object> endpointProps) {
ClassLoader oldClassLoader =
Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
Modified:
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java?rev=1443422&r1=1443421&r2=1443422&view=diff
==============================================================================
---
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
(original)
+++
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
Thu Feb 7 11:37:33 2013
@@ -128,7 +128,7 @@ public class PojoConfigurationTypeHandle
// If the property is not of type string this will cause an
ClassCastException which
// will be propagated to the ExportRegistration exception property.
- String port = (String) sd.get(Constants.WS_PORT_PROPERTY);
+ Object port = sd.get(Constants.WS_PORT_PROPERTY);
if (port == null)
port = "9000";
Modified:
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java?rev=1443422&r1=1443421&r2=1443422&view=diff
==============================================================================
---
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
(original)
+++
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
Thu Feb 7 11:37:33 2013
@@ -196,6 +196,82 @@ public class PojoConfigurationTypeHandle
}
+ public void testAddressing() {
+ runAddressingTest(new HashMap<String, Object>(),
"http://localhost:9000/java/lang/Runnable");
+
+ HashMap<String, Object> p1 = new HashMap<String, Object>();
+ p1.put("org.apache.cxf.ws.address", "http://somewhere");
+ runAddressingTest(p1, "http://somewhere");
+
+ HashMap<String, Object> p2 = new HashMap<String, Object>();
+ p2.put("org.apache.cxf.rs.address", "https://somewhereelse");
+ runAddressingTest(p2, "https://somewhereelse");
+
+ HashMap<String, Object> p3 = new HashMap<String, Object>();
+ p3.put("org.apache.cxf.ws.port", 65535);
+ runAddressingTest(p3, "http://localhost:65535/java/lang/Runnable");
+
+ HashMap<String, Object> p4 = new HashMap<String, Object>();
+ p4.put("org.apache.cxf.ws.port", "8181");
+ runAddressingTest(p4, "http://localhost:8181/java/lang/Runnable");
+ }
+
+ private void runAddressingTest(Map<String, Object> properties, String
expectedAddress) {
+ BundleContext dswContext =
EasyMock.createNiceMock(BundleContext.class);
+ EasyMock.replay(dswContext);
+
+ IntentManager intentManager =
EasyMock.createNiceMock(IntentManager.class);
+ EasyMock.replay(intentManager);
+
+ PojoConfigurationTypeHandler handler = new
PojoConfigurationTypeHandler(dswContext, intentManager,
dummyHttpServiceManager()) {
+ @Override
+ protected ExportResult createServerFromFactory(ServerFactoryBean
factory, Map<String, Object> endpointProps) {
+ return new ExportResult(endpointProps, (Server) null);
+ }
+ };
+
+ ServiceReference sref =
EasyMock.createNiceMock(ServiceReference.class);
+ EasyMock.replay(sref);
+
+ Runnable myService = EasyMock.createMock(Runnable.class);
+ EasyMock.replay(myService);
+ ExportResult result = handler.createServer(sref, null, null,
properties, Runnable.class, myService);
+ assertNull(result.getException());
+
+ Map<String, Object> props = result.getEndpointProps();
+ assertEquals(expectedAddress, props.get("org.apache.cxf.ws.address"));
+ assertEquals("Version of java. package is always 0", "0.0.0",
props.get("endpoint.package.version.java.lang"));
+ assertTrue(Arrays.equals(new String[] {"org.apache.cxf.ws"},
(String[]) props.get("service.imported.configs")));
+ assertTrue(Arrays.equals(new String[] {"java.lang.Runnable"},
(String[]) props.get("objectClass")));
+ assertNotNull(props.get("endpoint.framework.uuid"));
+ }
+
+ public void testCreateServerException() {
+ BundleContext dswContext =
EasyMock.createNiceMock(BundleContext.class);
+ EasyMock.replay(dswContext);
+
+ IntentManager intentManager =
EasyMock.createNiceMock(IntentManager.class);
+ EasyMock.replay(intentManager);
+
+ PojoConfigurationTypeHandler handler = new
PojoConfigurationTypeHandler(dswContext, intentManager,
dummyHttpServiceManager()) {
+ @Override
+ protected ExportResult createServerFromFactory(ServerFactoryBean
factory, Map<String, Object> endpointProps) {
+ throw new TestException();
+ }
+ };
+
+ ServiceReference sref =
EasyMock.createNiceMock(ServiceReference.class);
+ EasyMock.replay(sref);
+
+ Map<String, Object> props = new HashMap<String, Object>();
+
+ Runnable myService = EasyMock.createMock(Runnable.class);
+ EasyMock.replay(myService);
+ ExportResult result = handler.createServer(sref, null, null, props,
Runnable.class, myService);
+ Assert.assertTrue(result.getException() instanceof TestException);
+ Assert.assertEquals(props, result.getEndpointProps());
+ }
+
private ServerFactoryBean createMockServerFactoryBean() {
ReflectionServiceFactoryBean sf =
EasyMock.createNiceMock(ReflectionServiceFactoryBean.class);
EasyMock.replay(sf);
@@ -329,7 +405,6 @@ public class PojoConfigurationTypeHandle
}
public static class DummyIntentManager implements IntentManager {
-
@Override
public String[] applyIntents(List<Feature> features,
AbstractEndpointFactory factory,
@@ -341,6 +416,8 @@ public class PojoConfigurationTypeHandle
public void assertAllIntentsSupported(Map<String, Object>
serviceProperties) {
}
-
}
+
+ @SuppressWarnings("serial")
+ public static class TestException extends RuntimeException {}
}