Skip to content

Commit

Permalink
Add a TCK test to verify that the default ExceptionMapper can be over…
Browse files Browse the repository at this point in the history
…ridden.

Signed-off-by: Adam Anderson <[email protected]>
  • Loading branch information
WhiteCat22 committed Mar 12, 2024
1 parent e5994e3 commit c8aa779
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.extension.ExtendWith;

import jakarta.ws.rs.core.Response.Status;
import ee.jakarta.tck.ws.rs.common.JAXRSCommonClient;
import ee.jakarta.tck.ws.rs.lib.util.TestUtil;
import jakarta.ws.rs.core.Response.Status;

/*
* @class.setup_props: webServerHost;
Expand Down Expand Up @@ -312,4 +312,16 @@ public void webApplicationExceptionHasResponseWithoutEntityDoesUseMapperTest()
invoke();
}
}

/*
* @testName: overrideDefaultExceptionMapperTest
*
* @test_Strategy: The default ExceptionMapper must be able to be overridden.
*/
@Test
public void overrideDefaultExceptionMapperTest() throws Fault {
setProperty(REQUEST, buildRequest(GET, "throwable"));
setProperty(STATUS_CODE, "512");
invoke();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package ee.jakarta.tck.ws.rs.ee.resource.webappexception.mapper;

import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;

public class OverridenDefaultExceptionMapper implements ExceptionMapper<Throwable> {

/*
* 4.4. Exception Mapping Providers states:
* "A JAX-RS implementation MUST include a default exception mapping provider
* that implements ExceptionMapper<Throwable> and which SHOULD set the
* response status to 500."
*
* This class should override the default ExceptionMapper and set the
* response status to 512 to verify that the default ExceptionMapper
* was overriden.
*/
@Override
public Response toResponse(Throwable throwable) {
return Response.status(512).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ public String throwIOExecption() {
throw new ClassCastException("ERROR");
}

@GET
@Path("throwable")
public String throwThrowable() throws Throwable {
throw new Throwable("ERROR");
}

IOException getIOException() {
IOException ioe = new IOException("You should NOT see this message");
return ioe;
Expand Down

0 comments on commit c8aa779

Please sign in to comment.