Skip to content
Permalink
Browse files
[DOSGI-254] Unit test to show the issue
  • Loading branch information
cschneider committed Jul 11, 2017
1 parent 2ce3ed1 commit 7a5315cbdc8ac751b43e6d5d1f94db24f6fdb2b0
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 2 deletions.
@@ -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;
}
@@ -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();
}

}
@@ -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;
}
@@ -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,16 +29,18 @@
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()) {
OBJECT_METHODS.put(m.getName(), m);
}
}

@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 @@ public String toString() {
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();
}

}

0 comments on commit 7a5315c

Please sign in to comment.