[DOSGI-254] Unit test to show the issue
diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/proxy/MyBaseService.java b/common/src/test/java/org/apache/cxf/dosgi/common/proxy/MyBaseService.java
new file mode 100644
index 0000000..b6f9495
--- /dev/null
+++ b/common/src/test/java/org/apache/cxf/dosgi/common/proxy/MyBaseService.java
@@ -0,0 +1,25 @@
+/**
+ * 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.common.proxy;
+
+import java.io.IOException;
+
+public interface MyBaseService {
+ void throwException1() throws IOException;
+}
diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/proxy/MyServiceImpl.java b/common/src/test/java/org/apache/cxf/dosgi/common/proxy/MyServiceImpl.java
new file mode 100644
index 0000000..60007a9
--- /dev/null
+++ b/common/src/test/java/org/apache/cxf/dosgi/common/proxy/MyServiceImpl.java
@@ -0,0 +1,35 @@
+/**
+ * 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.common.proxy;
+
+import java.io.IOException;
+
+public class MyServiceImpl implements MySubService {
+
+ @Override
+ public void throwException1() throws IOException {
+ throw new IOException();
+ }
+
+ @Override
+ public void throwException2() throws IOException {
+ throw new IOException();
+ }
+
+}
diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/proxy/MySubService.java b/common/src/test/java/org/apache/cxf/dosgi/common/proxy/MySubService.java
new file mode 100644
index 0000000..5bc74cd
--- /dev/null
+++ b/common/src/test/java/org/apache/cxf/dosgi/common/proxy/MySubService.java
@@ -0,0 +1,25 @@
+/**
+ * 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.common.proxy;
+
+import java.io.IOException;
+
+public interface MySubService extends MyBaseService {
+ void throwException2() throws IOException;
+}
diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/proxy/ServiceInvocationHandlerTest.java b/common/src/test/java/org/apache/cxf/dosgi/common/proxy/ServiceInvocationHandlerTest.java
index 92cdc75..30cf5a8 100644
--- a/common/src/test/java/org/apache/cxf/dosgi/common/proxy/ServiceInvocationHandlerTest.java
+++ b/common/src/test/java/org/apache/cxf/dosgi/common/proxy/ServiceInvocationHandlerTest.java
@@ -18,6 +18,9 @@
*/
package org.apache.cxf.dosgi.common.proxy;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
@@ -26,9 +29,10 @@
import java.util.List;
import java.util.Map;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.osgi.framework.ServiceException;
-public class ServiceInvocationHandlerTest extends TestCase {
+public class ServiceInvocationHandlerTest {
private static final Map<String, Method> OBJECT_METHODS = new HashMap<String, Method>(); {
for (Method m : Object.class.getMethods()) {
@@ -36,6 +40,7 @@
}
}
+ @Test
public void testInvoke() throws Throwable {
ServiceInvocationHandler sih = new ServiceInvocationHandler("hello", String.class);
Method m = String.class.getMethod("length", new Class[] {});
@@ -72,4 +77,21 @@
sih.invoke(null, OBJECT_METHODS.get("toString"), new Object[] {}));
assertEquals(Arrays.asList("equals", "hashCode", "toString"), called);
}
+
+ @Test(expected = IOException.class)
+ public void testException() throws IOException {
+ MySubService proxy = (MySubService)ProxyFactory.create(new MyServiceImpl(), MySubService.class);
+ proxy.throwException2();
+ }
+
+ /**
+ * Shows issue https://issues.apache.org/jira/projects/DOSGI/issues/DOSGI-254
+ * We would expect an IOexcpetion here
+ */
+ @Test(expected = ServiceException.class)
+ public void testInheritedException() throws IOException {
+ MyBaseService proxy = (MyBaseService)ProxyFactory.create(new MyServiceImpl(), MySubService.class);
+ proxy.throwException1();
+ }
+
}