You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2014/01/30 22:19:30 UTC
svn commit: r1562968 -
/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryExceptionMapperTest.java
Author: sergeyb
Date: Thu Jan 30 21:19:29 2014
New Revision: 1562968
URL: http://svn.apache.org/r1562968
Log:
[CXF-5534] Adding the tests provided by Hans Weisheimer
Added:
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryExceptionMapperTest.java (with props)
Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryExceptionMapperTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryExceptionMapperTest.java?rev=1562968&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryExceptionMapperTest.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryExceptionMapperTest.java Thu Jan 30 21:19:29 2014
@@ -0,0 +1,97 @@
+/**
+ * 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 org.apache.cxf.message.MessageImpl;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class ProviderFactoryExceptionMapperTest {
+
+ private ServerProviderFactory pf;
+
+ @Before
+ public void setUp() throws Exception {
+ pf = ServerProviderFactory.getInstance();
+ pf.registerUserProvider(new RuntimeExceptionMapper2());
+ pf.registerUserProvider(new RuntimeExceptionMapper1());
+ pf.registerUserProvider(new RuntimeExceptionMapper());
+ }
+
+ @Test
+ public void testExactMatchInFirstPosition() {
+ ExceptionMapper<?> exceptionMapper = pf.createExceptionMapper(RuntimeException2.class,
+ new MessageImpl());
+ assertEquals("Wrong mapper found for RuntimeException2", RuntimeExceptionMapper2.class,
+ exceptionMapper.getClass());
+ }
+
+ @Test
+ public void testExactMatchInSecondPosition() {
+ ExceptionMapper<?> exceptionMapper = pf.createExceptionMapper(RuntimeException1.class,
+ new MessageImpl());
+ assertEquals("Wrong mapper found for RuntimeException1", RuntimeExceptionMapper1.class,
+ exceptionMapper.getClass());
+ }
+
+ @Test
+ public void testNearestSuperclassMatch() {
+ ExceptionMapper<?> exceptionMapper = pf.createExceptionMapper(NullPointerException.class,
+ new MessageImpl());
+ assertEquals("Wrong mapper found for NullPointerException", RuntimeExceptionMapper.class,
+ exceptionMapper.getClass());
+ }
+
+ private static class RuntimeExceptionMapper implements ExceptionMapper<RuntimeException> {
+ @Override
+ public Response toResponse(RuntimeException ex) {
+ return null;
+ }
+ }
+
+ private static class RuntimeExceptionMapper1 implements ExceptionMapper<RuntimeException1> {
+ @Override
+ public Response toResponse(RuntimeException1 ex) {
+ return null;
+ }
+ }
+
+ private static class RuntimeExceptionMapper2 implements ExceptionMapper<RuntimeException2> {
+ @Override
+ public Response toResponse(RuntimeException2 ex) {
+ return null;
+ }
+ }
+
+ @SuppressWarnings("serial")
+ private static class RuntimeException1 extends RuntimeException {
+
+ }
+
+ @SuppressWarnings("serial")
+ private static class RuntimeException2 extends RuntimeException1 {
+
+ }
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryExceptionMapperTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryExceptionMapperTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date