Repository: cxf Updated Branches: refs/heads/master d75dbf72c -> a2821b834
[CXF-7473] ExceptionMapper class hierarchies: incompatible ExceptionMapper selected - added ignored testcase Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/a2821b83 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a2821b83 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a2821b83 Branch: refs/heads/master Commit: a2821b8349b556c9e35ac8ba5a58422da20a5348 Parents: d75dbf7 Author: Dennis Kieselhorst <[email protected]> Authored: Mon Sep 4 13:12:02 2017 +0200 Committer: Dennis Kieselhorst <[email protected]> Committed: Mon Sep 4 13:12:02 2017 +0200 ---------------------------------------------------------------------- ...rFactoryHierarchicalExceptionMapperTest.java | 92 ++++++++++++++++++++ 1 file changed, 92 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/a2821b83/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryHierarchicalExceptionMapperTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryHierarchicalExceptionMapperTest.java b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryHierarchicalExceptionMapperTest.java new file mode 100644 index 0000000..6a253df --- /dev/null +++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryHierarchicalExceptionMapperTest.java @@ -0,0 +1,92 @@ +/** + * 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.jaxrs.provider; + +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; +import java.util.logging.Logger; + +import org.apache.cxf.common.logging.LogUtils; +import org.apache.cxf.message.MessageImpl; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Testcase for CXF-7473 + */ +@Ignore("To be fixed in CXF-7473") +public class ProviderFactoryHierarchicalExceptionMapperTest { + private static final Logger LOG = LogUtils.getL7dLogger(ProviderFactoryHierarchicalExceptionMapperTest.class); + + private ServerProviderFactory pf; + + @Before + public void setUp() throws Exception { + pf = ServerProviderFactory.getInstance(); + pf.registerUserProvider(new IllegalArgumentExceptionMapper()); + pf.registerUserProvider(new IllegalStateExceptionMapper()); + } + + @Test + public void testNearestSuperclassMatch() { + ExceptionMapper<?> exceptionMapper = pf.createExceptionMapper(UnmappedRuntimeException.class, + new MessageImpl()); + Assert.assertNotEquals("Wrong mapper found for UnmappedRuntimeException", + IllegalArgumentExceptionMapper.class, + exceptionMapper.getClass()); + } + + public abstract class AbstractExceptionMapper<E extends Throwable> implements ExceptionMapper<E> { + @Override + public Response toResponse(E exception) { + return toResponse0(exception); + } + + protected abstract Response toResponse0(E exception); + } + + public class IllegalArgumentExceptionMapper extends AbstractExceptionMapper<IllegalArgumentException> { + @Override + protected Response toResponse0(IllegalArgumentException exception) { + return Response + .serverError() + .entity("Processed by IllegalArgumentExceptionMapper: " + exception.getMessage()) + .build(); + } + } + + public class IllegalStateExceptionMapper implements ExceptionMapper<IllegalStateException> { + @Override + public Response toResponse(IllegalStateException exception) { + return Response + .serverError() + .entity("Processed by IllegalStateExceptionMapper: " + exception.getMessage()) + .build(); + } + } + + public class UnmappedRuntimeException extends RuntimeException { + public UnmappedRuntimeException(String message) { + super(message); + } + } +}
