FileDocCategorySizeDatePackage
ErrorCode.javaAPI DocGlassfish v2 API8657Fri May 04 22:34:08 BST 2007com.sun.enterprise.tools.verifier.tests.web

ErrorCode

public class ErrorCode extends com.sun.enterprise.tools.verifier.tests.web.WebTest implements WebCheck
Error code element contains an HTTP error code within web application test. i.e. 404

Fields Summary
Constructors Summary
Methods Summary
public Resultcheck(WebBundleDescriptor descriptor)
Error code element contains an HTTP error code within web application test. i.e. 404

param
descriptor the Web deployment descriptor
return
Result the results for this assertion


	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;
    
public static booleanisValidErrorCode(java.lang.Integer errorCodeTypeInteger)
Determine is Error Code is valid.

param
errorCodeTypeInteger error code type
return
boolean true if error code is valid, false otherwise

	int errorCodeType = errorCodeTypeInteger.intValue();
	if ((errorCodeType == ErrorCodeTypes.CONTINUE) ||
	    (errorCodeType == ErrorCodeTypes.SWITCHING_PROTOCOLS) ||
	    (errorCodeType == ErrorCodeTypes.OK) ||
	    (errorCodeType == ErrorCodeTypes.CREATED) ||
	    (errorCodeType == ErrorCodeTypes.ACCEPTED) ||
	    (errorCodeType == ErrorCodeTypes.NON_AUTHORITATIVE_INFORMATION) ||
	    (errorCodeType == ErrorCodeTypes.NO_CONTENT) ||
	    (errorCodeType == ErrorCodeTypes.RESET_CONTENT) ||
	    (errorCodeType == ErrorCodeTypes.PARTIAL_CONTENT) ||
	    (errorCodeType == ErrorCodeTypes.MULTIPLE_CHOICES) ||
	    (errorCodeType == ErrorCodeTypes.MOVED_PERMANENTLY) ||
	    (errorCodeType == ErrorCodeTypes.FOUND) ||
	    (errorCodeType == ErrorCodeTypes.SEE_OTHER) ||
	    (errorCodeType == ErrorCodeTypes.NOT_MODIFIED) ||
	    (errorCodeType == ErrorCodeTypes.USE_PROXY) ||
	    (errorCodeType == ErrorCodeTypes.UNUSED) ||
	    (errorCodeType == ErrorCodeTypes.TEMPORARY_REDIRECT) ||
	    (errorCodeType == ErrorCodeTypes.BAD_REQUEST) ||
	    (errorCodeType == ErrorCodeTypes.UNAUTHORIZED) ||
	    (errorCodeType == ErrorCodeTypes.PAYMENT_REQUIRED) ||
	    (errorCodeType == ErrorCodeTypes.FORBIDDEN) ||
	    (errorCodeType == ErrorCodeTypes.NOT_FOUND) ||
	    (errorCodeType == ErrorCodeTypes.METHOD_NOT_ALLOWED) ||
	    (errorCodeType == ErrorCodeTypes.NOT_ACCEPTABLE) ||
	    (errorCodeType == ErrorCodeTypes.PROXY_AUTHENTICATION_REQUIRED) ||
	    (errorCodeType == ErrorCodeTypes.REQUEST_TIMEOUT) ||
	    (errorCodeType == ErrorCodeTypes.CONFLICT) ||
	    (errorCodeType == ErrorCodeTypes.GONE) ||
	    (errorCodeType == ErrorCodeTypes.LENGTH_REQUIRED) ||
	    (errorCodeType == ErrorCodeTypes.PRECONDITION_FAILED) ||
	    (errorCodeType == ErrorCodeTypes.REQUEST_ENTITY_TOO_LARGE) ||
	    (errorCodeType == ErrorCodeTypes.REQUEST_URI_TOO_LONG) ||
	    (errorCodeType == ErrorCodeTypes.UNSUPPORTED_MEDIA_TYPE) ||
	    (errorCodeType == ErrorCodeTypes.REQUESTED_RANGE_NOT_SATISFIABLE) ||
	    (errorCodeType == ErrorCodeTypes.EXPECTATION_FAILED) ||
	    (errorCodeType == ErrorCodeTypes.INTERNAL_SERVER_ERROR) ||
	    (errorCodeType == ErrorCodeTypes.NOT_IMPLEMENTED) ||
	    (errorCodeType == ErrorCodeTypes.BAD_GATEWAY) ||
	    (errorCodeType == ErrorCodeTypes.SERVICE_UNAVAILABLE) ||
	    (errorCodeType == ErrorCodeTypes.GATEWAY_TIMEOUT) ||
	    (errorCodeType == ErrorCodeTypes.HTTP_VERSION_NOT_SUPPORTED)) {
	    return true;
	} else {
	    return false;
	}