Error code element contains an HTTP error code within web application test.
i.e. 404
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (descriptor.getErrorPageDescriptors().hasMoreElements()) {
boolean oneFailed = false;
boolean foundIt = false;
int oneErrorCode = 0;
int oneNA = 0;
// get the errorpage's in this .war
for (Enumeration e = descriptor.getErrorPageDescriptors() ; e.hasMoreElements() ;) {
foundIt = false;
oneErrorCode++;
ErrorPageDescriptorImpl errorpage = (ErrorPageDescriptorImpl) e.nextElement();
String exceptionType = errorpage.getExceptionType();
if (!((exceptionType != null) && (exceptionType.length() > 0))) {
Integer errorCode = new Integer( errorpage.getErrorCode() );
if (isValidErrorCode(errorCode)) {
foundIt = true;
} else {
foundIt = false;
}
if (foundIt) {
result.addGoodDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.addGoodDetails(smh.getLocalString
(getClass().getName() + ".passed",
"Error code [ {0} ] contains valid HTTP error code within web application [ {1} ]",
new Object[] {errorCode.toString(), descriptor.getName()}));
} else {
if (!oneFailed) {
oneFailed = true;
}
result.addErrorDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.addErrorDetails(smh.getLocalString
(getClass().getName() + ".failed",
"Error: error-code [ {0} ] does not contain valid HTTP error code within web application [ {1} ]",
new Object[] {errorCode.toString(), descriptor.getName()}));
}
} else {
// maybe ErrorCode is not used 'cause we are using Exception
// if that is the case, then test is N/A,
result.addNaDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.addNaDetails(smh.getLocalString
(getClass().getName() + ".notApplicable1",
"Not Applicable: Error-code is [ {0} ], using [ {1} ] instead within web application [ {2} ]",
new Object[] {new Integer(errorpage.getErrorCode()), exceptionType, descriptor.getName()}));
oneNA++;
}
}
if (oneFailed) {
result.setStatus(Result.FAILED);
} else if (oneNA == oneErrorCode) {
result.setStatus(Result.NOT_APPLICABLE);
} else {
result.setStatus(Result.PASSED);
}
} else {
result.addNaDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.notApplicable(smh.getLocalString
(getClass().getName() + ".notApplicable",
"There are no error-code elements within the web archive [ {0} ]",
new Object[] {descriptor.getName()}));
}
return result;