Skip to content

Commit

Permalink
#28325 adjusting our test to run with the new quarkus platf ver
Browse files Browse the repository at this point in the history
  • Loading branch information
fabrizzio-dotCMS committed Apr 30, 2024
1 parent 34a7450 commit 4ae0158
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import org.jboss.resteasy.specimpl.BuiltResponse;
import picocli.CommandLine;
import picocli.CommandLine.Help.ColorScheme;
import picocli.CommandLine.Model.CommandSpec;
Expand Down Expand Up @@ -279,8 +282,12 @@ public int handleCommandException(final Exception ex, final String message,
*/
private String getMessage(final Exception originalException, final Exception handledEx) {

var message = abbreviate(handledEx.getMessage(), "...", 200);

var message = abbreviate(handledEx.getMessage(), "...", 200);

if(handledEx instanceof WebApplicationException){
message = getWebApplicationExceptionMessage((WebApplicationException) handledEx);
}

if (originalException instanceof PushException ||
originalException instanceof PullException ||
originalException instanceof TraversalTaskException) {
Expand All @@ -300,6 +307,18 @@ private String getMessage(final Exception originalException, final Exception han
+ " Occurred With no error message provided.";
}


String getWebApplicationExceptionMessage(final WebApplicationException ex) {
final Response response = ex.getResponse();
if (response instanceof BuiltResponse) {
final String reasonPhrase = ((BuiltResponse) response).getReasonPhrase();
if (null != reasonPhrase) {
return reasonPhrase;
}
}
return ex.getMessage();
}

@Override
public String toString() {
return "OutputOptions [testMode=" + cliTestMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void Test_Command_Login_With_Params_Expect_Login_Reject() {
final String output = writer.toString();
Assertions.assertTrue(output.contains("[ERROR]"));
Assertions.assertTrue(output.contains(
"HTTP 401 Forbidden: You don't have permission to access this resource."));
"Forbidden: You don't have permission to access this resource."));
}
}

Expand All @@ -165,7 +165,7 @@ void Test_Command_Login_With_Invalid_Token() {
final String output = writer.toString();
Assertions.assertTrue(output.contains("[ERROR]"));
Assertions.assertTrue(output.contains(
"HTTP 401 Forbidden: You don't have permission to access this resource."));
"Forbidden: You don't have permission to access this resource."));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import javax.ws.rs.NotAllowedException;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.WebApplicationException;
import org.jboss.resteasy.specimpl.BuiltResponse;
import org.junit.Ignore;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -44,32 +46,44 @@ void Test_Handle_WebApplication_Exception() {
NotFoundException noise = new NotFoundException("No pineapple Flavor today");
Exception handled = exceptionHandler.handle(noise);
Assertions.assertTrue(handled instanceof WebApplicationException);
Assertions.assertTrue(handled.getMessage().contains(config.messages().get(404)));
BuiltResponse response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
Assertions.assertTrue(response.getReasonPhrase().contains(config.messages().get(404)));
//Assertions.assertTrue(handled.getMessage().contains(config.messages().get(404)));

BadRequestException badRequestException = new BadRequestException("LOL");
handled = exceptionHandler.handle(badRequestException);
Assertions.assertTrue(handled instanceof WebApplicationException);
Assertions.assertTrue(handled.getMessage().contains(config.messages().get(400)));
response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
Assertions.assertTrue(response.getReasonPhrase().contains(config.messages().get(400)));
//Assertions.assertTrue(handled.getMessage().contains(config.messages().get(400)));

ForbiddenException forbiddenException = new ForbiddenException("LOL");
handled = exceptionHandler.handle(forbiddenException);
Assertions.assertTrue(handled instanceof WebApplicationException);
Assertions.assertTrue(handled.getMessage().contains(config.messages().get(403)));
response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
Assertions.assertTrue(response.getReasonPhrase().contains(config.messages().get(403)));
//Assertions.assertTrue(handled.getMessage().contains(config.messages().get(403)));

WebApplicationException unauthorized = new WebApplicationException(401);
handled = exceptionHandler.handle(unauthorized);
Assertions.assertTrue(handled instanceof WebApplicationException);
Assertions.assertTrue(handled.getMessage().contains(config.messages().get(401)));
response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
Assertions.assertTrue(response.getReasonPhrase().contains(config.messages().get(401)));
//Assertions.assertTrue(handled.getMessage().contains(config.messages().get(401)));

WebApplicationException internalServerError = new WebApplicationException(500);
handled = exceptionHandler.handle(internalServerError);
Assertions.assertTrue(handled instanceof WebApplicationException);
Assertions.assertTrue(handled.getMessage().contains(config.messages().get(500)));
response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
Assertions.assertTrue(response.getReasonPhrase().contains(config.messages().get(500)));
//Assertions.assertTrue(handled.getMessage().contains(config.messages().get(500)));

NotAllowedException moreNoise = new NotAllowedException("Not Allowed");
handled = exceptionHandler.handle(moreNoise);
Assertions.assertTrue(handled instanceof WebApplicationException);
Assertions.assertTrue(handled.getMessage().contains(config.fallback()));
response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
Assertions.assertTrue(response.getReasonPhrase().contains(config.fallback()));
//Assertions.assertTrue(handled.getMessage().contains(config.fallback()));

}

Expand Down

0 comments on commit 4ae0158

Please sign in to comment.