Upgrade tests to junit 4
diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/httpservice/HttpServiceManagerTest.java b/common/src/test/java/org/apache/cxf/dosgi/common/httpservice/HttpServiceManagerTest.java
index cc7dfa9..29acce1 100644
--- a/common/src/test/java/org/apache/cxf/dosgi/common/httpservice/HttpServiceManagerTest.java
+++ b/common/src/test/java/org/apache/cxf/dosgi/common/httpservice/HttpServiceManagerTest.java
@@ -20,6 +20,7 @@
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
+import static org.junit.Assert.assertEquals;
import java.util.Dictionary;
@@ -33,7 +34,7 @@
import org.easymock.Capture;
import org.easymock.EasyMock;
import org.easymock.IMocksControl;
-import org.junit.Assert;
+import org.junit.Test;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.ServiceEvent;
@@ -42,10 +43,9 @@
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
-import junit.framework.TestCase;
+public class HttpServiceManagerTest {
-public class HttpServiceManagerTest extends TestCase {
-
+ @Test
public void testGetAbsoluteAddress() {
HttpServiceManager manager = new HttpServiceManager();
manager.initFromConfig(null);
@@ -57,6 +57,7 @@
assertEquals("http://localhost:8181/mycontext/myservice", address2);
}
+ @Test
public void testRegisterAndUnregisterServlet() throws Exception {
IMocksControl c = EasyMock.createControl();
BundleContext dswContext = c.createMock(BundleContext.class);
@@ -99,7 +100,7 @@
@SuppressWarnings("rawtypes")
public void registerServlet(String alias, Servlet servlet, Dictionary initparams, HttpContext context)
throws ServletException {
- Assert.assertEquals("/myService", alias);
+ assertEquals("/myService", alias);
servlet.init(config);
}
diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/httpservice/SecurityDelegatingHttpContextTest.java b/common/src/test/java/org/apache/cxf/dosgi/common/httpservice/SecurityDelegatingHttpContextTest.java
index aceff54..068de12 100644
--- a/common/src/test/java/org/apache/cxf/dosgi/common/httpservice/SecurityDelegatingHttpContextTest.java
+++ b/common/src/test/java/org/apache/cxf/dosgi/common/httpservice/SecurityDelegatingHttpContextTest.java
@@ -30,17 +30,20 @@
import javax.servlet.http.HttpServletResponse;
import org.easymock.EasyMock;
-import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpContext;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
@SuppressWarnings({
"unchecked", "rawtypes"
})
-public class SecurityDelegatingHttpContextTest extends TestCase {
+public class SecurityDelegatingHttpContextTest {
protected HttpContext defaultHttpContext;
protected SecurityDelegatingHttpContext httpContext;
@@ -50,7 +53,7 @@
protected String mimeType;
protected URL url; // does not need to exist
- @Override
+ @Before
public void setUp() throws Exception {
mimeType = "text/xml";
url = new URL("file:test.xml"); // does not need to exist
@@ -67,6 +70,7 @@
EasyMock.replay(defaultHttpContext);
}
+ @Test
public void testFilterRequired() throws Exception {
// Mock up the service references
ServiceReference[] serviceReferences = {};
@@ -89,14 +93,15 @@
HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
EasyMock.replay(response);
boolean requestAllowed = httpContext.handleSecurity(request, response);
- Assert.assertFalse(requestAllowed);
+ assertFalse(requestAllowed);
// Ensure that the httpContext returns true if there is no requirement for registered servlet filters
httpContext.requireFilter = false;
requestAllowed = httpContext.handleSecurity(request, response);
- Assert.assertTrue(requestAllowed);
+ assertTrue(requestAllowed);
}
+ @Test
public void testSingleCommitFilter() throws Exception {
// Mock up the service references
ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class);
@@ -123,14 +128,15 @@
// return value
EasyMock.expect(response.getWriter()).andReturn(new PrintWriter(System.out));
EasyMock.replay(response);
- Assert.assertFalse(httpContext.handleSecurity(request, response));
+ assertFalse(httpContext.handleSecurity(request, response));
// Ensure that the appropriate filters were called
- Assert.assertTrue(commitFilter.called);
- Assert.assertFalse(doNothingFilter.called);
- Assert.assertFalse(accessDeniedFilter.called);
+ assertTrue(commitFilter.called);
+ assertFalse(doNothingFilter.called);
+ assertFalse(accessDeniedFilter.called);
}
+ @Test
public void testFilterChain() throws Exception {
// Mock up the service references
ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class);
@@ -158,14 +164,15 @@
EasyMock.expect(response.isCommitted()).andReturn(true); // the commit filter indicating that it committed the
// response
EasyMock.replay(response);
- Assert.assertFalse(httpContext.handleSecurity(request, response));
+ assertFalse(httpContext.handleSecurity(request, response));
// Ensure that the appropriate filters were called
- Assert.assertTrue(doNothingFilter.called);
- Assert.assertTrue(commitFilter.called);
- Assert.assertFalse(accessDeniedFilter.called);
+ assertTrue(doNothingFilter.called);
+ assertTrue(commitFilter.called);
+ assertFalse(accessDeniedFilter.called);
}
+ @Test
public void testAllowRequest() throws Exception {
// Mock up the service references
ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class);
@@ -188,14 +195,15 @@
HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
EasyMock.expect(response.isCommitted()).andReturn(false);
EasyMock.replay(response);
- Assert.assertTrue(httpContext.handleSecurity(request, response));
+ assertTrue(httpContext.handleSecurity(request, response));
// Ensure that the appropriate filters were called
- Assert.assertTrue(doNothingFilter.called);
- Assert.assertFalse(commitFilter.called);
- Assert.assertFalse(accessDeniedFilter.called);
+ assertTrue(doNothingFilter.called);
+ assertFalse(commitFilter.called);
+ assertFalse(accessDeniedFilter.called);
}
+ @Test
public void testDelegation() {
BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
EasyMock.replay(bundleContext);
@@ -204,8 +212,8 @@
httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
// Ensure that it delegates non-security calls to the wrapped implementation (in this case, the mock)
- Assert.assertEquals(mimeType, httpContext.getMimeType(""));
- Assert.assertEquals(url, httpContext.getResource(""));
+ assertEquals(mimeType, httpContext.getMimeType(""));
+ assertEquals(url, httpContext.getResource(""));
}
}
diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/util/PropertyHelperTest.java b/common/src/test/java/org/apache/cxf/dosgi/common/util/PropertyHelperTest.java
index f842caf..aaefb46 100644
--- a/common/src/test/java/org/apache/cxf/dosgi/common/util/PropertyHelperTest.java
+++ b/common/src/test/java/org/apache/cxf/dosgi/common/util/PropertyHelperTest.java
@@ -25,23 +25,29 @@
import java.util.List;
import java.util.Map;
+import org.junit.Test;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
import org.osgi.service.remoteserviceadmin.RemoteConstants;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
-public class PropertyHelperTest extends TestCase {
+public class PropertyHelperTest {
+ @Test
public void testMultiValuePropertyAsString() {
assertEquals(Collections.singleton("hi"),
- PropertyHelper.getMultiValueProperty("hi"));
+ PropertyHelper.getMultiValueProperty("hi"));
}
+ @Test
public void testMultiValuePropertyAsArray() {
assertEquals(Arrays.asList("a", "b"),
- PropertyHelper.getMultiValueProperty(new String[] {"a", "b"}));
+ PropertyHelper.getMultiValueProperty(new String[]{"a", "b"}));
}
+ @Test
public void testMultiValuePropertyAsCollection() {
List<String> list = new ArrayList<>();
list.add("1");
@@ -50,10 +56,12 @@
assertEquals(list, PropertyHelper.getMultiValueProperty(list));
}
+ @Test
public void testMultiValuePropertyNull() {
assertTrue(PropertyHelper.getMultiValueProperty(null).isEmpty());
}
+ @Test
public void testGetProperty() {
Map<String, Object> p = new HashMap<>();
p.put(RemoteConstants.ENDPOINT_ID, "http://google.de");
@@ -64,8 +72,8 @@
EndpointDescription endpoint = new EndpointDescription(p);
assertNull(PropertyHelper.getProperty(endpoint.getProperties(), "unknownProp"));
- assertEquals(p.get(RemoteConstants.ENDPOINT_ID),
+ assertEquals(p.get(RemoteConstants.ENDPOINT_ID),
PropertyHelper.getProperty(endpoint.getProperties(), RemoteConstants.ENDPOINT_ID));
- assertEquals(null, PropertyHelper.getProperty(endpoint.getProperties(), "notAString"));
+ assertNull(PropertyHelper.getProperty(endpoint.getProperties(), "notAString"));
}
}
diff --git a/decorator/src/test/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRuleTest.java b/decorator/src/test/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRuleTest.java
index fed8706..42c1282 100644
--- a/decorator/src/test/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRuleTest.java
+++ b/decorator/src/test/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRuleTest.java
@@ -21,21 +21,26 @@
import java.util.HashMap;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.easymock.EasyMock;
import org.easymock.IAnswer;
+import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
-@SuppressWarnings("rawtypes")
-public class InterfaceRuleTest extends TestCase {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+@SuppressWarnings("rawtypes")
+public class InterfaceRuleTest {
+
+ @Test
public void testDUMMY() {
assertTrue(true);
}
+ @Test
public void testInterfaceRuleGetBundle() {
Bundle b = EasyMock.createMock(Bundle.class);
EasyMock.replay(b);
@@ -43,6 +48,7 @@
assertSame(b, ir.getBundle());
}
+ @Test
public void testInterfaceRule1() {
InterfaceRule ir = new InterfaceRule(null, "org.apache.Foo");
ir.addProperty("x", "y", String.class.getName());
@@ -60,6 +66,7 @@
assertEquals(expected, m);
}
+ @Test
public void testInterfaceRule2() {
InterfaceRule ir = new InterfaceRule(null, "org.apache.F(.*)");
ir.addPropMatch("boo", "baah");
@@ -79,6 +86,7 @@
assertEquals(expected, m);
}
+ @Test
public void testInterfaceRule3() {
InterfaceRule ir = new InterfaceRule(null, "org.apache.F(.*)");
ir.addProperty("x", "y", String.class.getName());
@@ -93,6 +101,7 @@
assertEquals(0, m.size());
}
+ @Test
public void testInterfaceRule4() {
InterfaceRule ir = new InterfaceRule(null, "org.apache.F(.*)");
ir.addPropMatch("boo", "baah");
@@ -107,6 +116,7 @@
assertEquals(0, m.size());
}
+ @Test
public void testInterfaceRule5() {
InterfaceRule ir = new InterfaceRule(null, "org.apache.Foo");
ir.addPropMatch("test.int", "42");
@@ -127,6 +137,7 @@
assertEquals(expected, m);
}
+ @Test
public void testInterfaceRule6() {
InterfaceRule ir = new InterfaceRule(null, "org.apache.Foo");
ir.addPropMatch("test.int", "42");
diff --git a/decorator/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImplTest.java b/decorator/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImplTest.java
index 4e870e5..c50997e 100644
--- a/decorator/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImplTest.java
+++ b/decorator/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImplTest.java
@@ -24,16 +24,17 @@
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.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
-public class ServiceDecoratorImplTest extends TestCase {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class ServiceDecoratorImplTest {
private static final Map<String, Object> 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");
@@ -41,6 +42,7 @@
private static final URL RES_SD0 = getResource("/test-resources/sd0.xml");
private static final URL RES_SD_1 = getResource("/test-resources/sd-1.xml");
+ @Test
@SuppressWarnings("rawtypes")
public void testAddRemoveDecorations() {
final Map<String, Object> serviceProps = new HashMap<>();
@@ -76,6 +78,7 @@
assertEquals(EMPTY, target2);
}
+ @Test
public void testAddDecorations() {
final Map<String, Object> serviceProps = new HashMap<>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.acme.foo.Bar"});
@@ -86,6 +89,7 @@
assertDecorate(serviceProps, expected, RES_SD);
}
+ @Test
public void testAddDecorations1() {
Map<String, Object> serviceProps = new HashMap<>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.A"});
@@ -96,6 +100,7 @@
assertDecorate(serviceProps, expected, RES_SD1, RES_SD2);
}
+ @Test
public void testAddDecorations2() {
Map<String, Object> serviceProps = new HashMap<>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.D"});
@@ -103,6 +108,7 @@
assertDecorate(serviceProps, EMPTY, RES_SD1, RES_SD2);
}
+ @Test
public void testAddDecorations3() {
Map<String, Object> serviceProps = new HashMap<>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.B"});
@@ -113,6 +119,7 @@
assertDecorate(serviceProps, expected, RES_SD1, RES_SD2);
}
+ @Test
public void testAddDecorations4() {
Map<String, Object> serviceProps = new HashMap<>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.C"});
@@ -123,6 +130,7 @@
assertDecorate(serviceProps, expected, RES_SD1, RES_SD2);
}
+ @Test
public void testAddDecorations5() {
Map<String, Object> serviceProps = new HashMap<>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.C"});
@@ -131,6 +139,7 @@
assertDecorate(serviceProps, EMPTY, RES_SD1, RES_SD2);
}
+ @Test
public void testAddDecorations6() {
Map<String, Object> serviceProps = new HashMap<>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.D"});
@@ -138,6 +147,7 @@
assertDecorate(serviceProps, EMPTY, RES_SD0);
}
+ @Test
public void testAddDecorations7() {
Map<String, Object> serviceProps = new HashMap<>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.D"});
@@ -182,7 +192,7 @@
private static URL getResource(String path) {
URL resource = ServiceDecoratorImplTest.class.getResource(path);
- Assert.assertNotNull("Resource " + path + " not found!", resource);
+ assertNotNull("Resource " + path + " not found!", resource);
return resource;
}
diff --git a/provider-ws/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ws/PojoConfigurationTypeHandlerTest.java b/provider-ws/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ws/PojoConfigurationTypeHandlerTest.java
index 306d8be..3308093 100644
--- a/provider-ws/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ws/PojoConfigurationTypeHandlerTest.java
+++ b/provider-ws/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ws/PojoConfigurationTypeHandlerTest.java
@@ -48,17 +48,22 @@
import org.easymock.EasyMock;
import org.easymock.IAnswer;
import org.easymock.IMocksControl;
-import org.junit.Assert;
+import org.junit.Test;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
import org.osgi.service.remoteserviceadmin.RemoteConstants;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-public class PojoConfigurationTypeHandlerTest extends TestCase {
+public class PojoConfigurationTypeHandlerTest {
+ @Test
public void testGetPojoAddressEndpointURI() {
IntentManager intentManager = new IntentManagerImpl();
WsProvider handler = new WsProvider();
@@ -74,6 +79,7 @@
return new HttpServiceManager();
}
+ @Test
public void testGetPojoAddressEndpointCxf() {
IntentManager intentManager = new IntentManagerImpl();
WsProvider handler = new WsProvider();
@@ -85,6 +91,7 @@
assertEquals(url, handler.getServerAddress(sd, String.class));
}
+ @Test
public void testGetDefaultPojoAddress() {
IntentManager intentManager = new IntentManagerImpl();
WsProvider handler = new WsProvider();
@@ -95,6 +102,7 @@
}
// todo: add test for data bindings
+ @Test
public void testCreateProxy() {
IMocksControl c = EasyMock.createNiceControl();
BundleContext bc1 = c.createMock(BundleContext.class);
@@ -139,6 +147,7 @@
c.verify();
}
+ @Test
public void testCreateServerWithAddressProperty() {
BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
EasyMock.replay(dswContext);
@@ -175,6 +184,7 @@
assertEquals("http://alternate_host:80/myString", edProps.get(RemoteConstants.ENDPOINT_ID));
}
+ @Test
public void testAddressing() {
runAddressingTest(new HashMap<String, Object>(), "http://localhost:9000/java/lang/Runnable");
@@ -223,12 +233,13 @@
Endpoint result = handler.exportService(myService, bundleContext, properties, exportedInterface);
Map<String, Object> props = result.description().getProperties();
assertEquals(expectedAddress, props.get("org.apache.cxf.ws.address"));
- Assert.assertArrayEquals(new String[] {"org.apache.cxf.ws"},
+ assertArrayEquals(new String[] {"org.apache.cxf.ws"},
(String[])props.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS));
- Assert.assertArrayEquals(new String[] {"java.lang.Runnable"},
+ assertArrayEquals(new String[] {"java.lang.Runnable"},
(String[])props.get(org.osgi.framework.Constants.OBJECTCLASS));
}
+ @Test
public void testCreateServerException() {
BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
EasyMock.replay(dswContext);
@@ -317,6 +328,7 @@
return server;
}
+ @Test
public void testCreateEndpointProps() {
BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
EasyMock.expect(bc.getProperty("org.osgi.framework.uuid")).andReturn("some_uuid1");
@@ -344,6 +356,7 @@
assertEquals(new Version("0.0.0"), epd.getPackageVersion("java.lang"));
}
+ @Test
public void testCreateJaxWsEndpointWithoutIntents() {
IMocksControl c = EasyMock.createNiceControl();
BundleContext dswBC = c.createMock(BundleContext.class);
@@ -368,12 +381,13 @@
org.apache.cxf.endpoint.Endpoint ep = serverWrapper.getServer().getEndpoint();
QName bindingName = ep.getEndpointInfo().getBinding().getName();
- Assert.assertEquals(JaxWsEndpointImpl.class, ep.getClass());
- Assert.assertEquals(new QName("http://jaxws.handlers.dsw.dosgi.cxf.apache.org/",
+ assertEquals(JaxWsEndpointImpl.class, ep.getClass());
+ assertEquals(new QName("http://jaxws.handlers.dsw.dosgi.cxf.apache.org/",
"MyJaxWsEchoServiceServiceSoapBinding"),
bindingName);
}
+ @Test
public void testCreateSimpleEndpointWithoutIntents() {
IMocksControl c = EasyMock.createNiceControl();
BundleContext dswBC = c.createMock(BundleContext.class);
@@ -395,8 +409,8 @@
org.apache.cxf.endpoint.Endpoint ep = serverWrapper.getServer().getEndpoint();
QName bindingName = ep.getEndpointInfo().getBinding().getName();
- Assert.assertEquals(EndpointImpl.class, ep.getClass());
- Assert.assertEquals(new QName("http://simple.handlers.dsw.dosgi.cxf.apache.org/",
+ assertEquals(EndpointImpl.class, ep.getClass());
+ assertEquals(new QName("http://simple.handlers.dsw.dosgi.cxf.apache.org/",
"MySimpleEchoServiceSoapBinding"),
bindingName);
}