in wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java [2304:2370]
protected void verifyWagonExceptionMessage( Exception e, int forStatusCode, String forUrl, String forReasonPhrase )
{
// TODO: handle AuthenticationException for Wagon.connect() calls
assertNotNull( e );
try
{
assertTrue( "only verify instances of WagonException", e instanceof WagonException );
String reasonPhrase;
String assertMessageForBadMessage = "exception message not described properly";
switch ( forStatusCode )
{
case HttpServletResponse.SC_NOT_FOUND:
// TODO: add test for 410: Gone?
assertTrue( "404 not found response should throw ResourceDoesNotExistException",
e instanceof ResourceDoesNotExistException );
reasonPhrase = StringUtils.isEmpty( forReasonPhrase ) ? " Not Found" : ( " " + forReasonPhrase );
assertEquals( assertMessageForBadMessage, "resource missing at " + forUrl + ", status: 404"
+ reasonPhrase, e.getMessage() );
break;
case HttpServletResponse.SC_UNAUTHORIZED:
// FIXME assumes Wagon.get()/put() returning 401 instead of Wagon.connect()
assertTrue( "401 Unauthorized should throw AuthorizationException since "
+ " AuthenticationException is not explicitly declared as thrown from wagon "
+ "methods",
e instanceof AuthorizationException );
reasonPhrase = StringUtils.isEmpty( forReasonPhrase ) ? " Unauthorized" : ( " " + forReasonPhrase );
assertEquals( assertMessageForBadMessage, "authentication failed for " + forUrl + ", status: 401"
+ reasonPhrase, e.getMessage() );
break;
case HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED:
assertTrue( "407 Proxy authentication required should throw AuthorizationException",
e instanceof AuthorizationException );
reasonPhrase = StringUtils.isEmpty( forReasonPhrase ) ? " Proxy Authentication Required"
: ( " " + forReasonPhrase );
assertEquals( assertMessageForBadMessage, "proxy authentication failed for "
+ forUrl + ", status: 407" + reasonPhrase, e.getMessage() );
break;
case HttpServletResponse.SC_FORBIDDEN:
assertTrue( "403 Forbidden should throw AuthorizationException",
e instanceof AuthorizationException );
reasonPhrase = StringUtils.isEmpty( forReasonPhrase ) ? " Forbidden" : ( " " + forReasonPhrase );
assertEquals( assertMessageForBadMessage, "authorization failed for " + forUrl + ", status: 403"
+ reasonPhrase, e.getMessage() );
break;
default:
assertTrue( "transfer failures should at least be wrapped in a TransferFailedException", e
instanceof TransferFailedException );
assertTrue( "expected status code for transfer failures should be >= 400",
forStatusCode >= HttpServletResponse.SC_BAD_REQUEST );
reasonPhrase = forReasonPhrase == null ? "" : " " + forReasonPhrase;
assertEquals( assertMessageForBadMessage, "transfer failed for " + forUrl + ", status: "
+ forStatusCode + reasonPhrase, e.getMessage() );
break;
}
}
catch ( AssertionError assertionError )
{
logger.error( "Exception which failed assertions: ", e );
throw assertionError;
}
}