FileDocCategorySizeDatePackage
WebTest.javaAPI DocGlassfish v2 API8363Fri May 04 22:34:10 BST 2007com.sun.enterprise.tools.verifier.tests.web

WebTest

public abstract class WebTest extends com.sun.enterprise.tools.verifier.tests.VerifierTest implements WebCheck, VerifierCheck
Common code and helper methods and properties for all tests in the web-app space (jsp and servlets).
author
Jerome Dochez
version
1.0

Fields Summary
private boolean
addedError
private boolean
addedGood
private boolean
addedNa
private boolean
addedWarning
final String
separator
com.sun.enterprise.tools.verifier.Context
context
Constructors Summary
Methods Summary
public com.sun.enterprise.tools.verifier.Resultcheck(com.sun.enterprise.deployment.Descriptor descriptor)

run an individual test against the deployment descriptor for the archive the verifier is performing compliance tests against.

param
descriptor deployment descriptor for the archive
return
result object containing the result of the individual test performed

 

                                                    
        
        return check((WebBundleDescriptor) descriptor);
    
public abstract com.sun.enterprise.tools.verifier.Resultcheck(com.sun.enterprise.deployment.WebBundleDescriptor descriptor)

all connector tests should implement this method. it run an individual test against the resource adapter deployment descriptor.

param
descriptor deployment descriptor for the archive file
return
result object containing the result of the individual test performed

protected voiddeleteDirectory(java.lang.String oneDir)
Method for recursively deleting all temporary directories

        
        File[] listOfFiles;
        File cleanDir;
	
        cleanDir = new File(oneDir);
        if (!cleanDir.exists())  {// Nothing to do.  Return; 
	    return;
	}
        listOfFiles = cleanDir.listFiles();
        if(listOfFiles != null) {       
            for(int countFiles = 0; countFiles < listOfFiles.length; countFiles++) {                    
                if (listOfFiles[countFiles].isFile()) {
                    listOfFiles[countFiles].delete();
                } else { // It is a directory
                    String nextCleanDir =  cleanDir + separator + listOfFiles[countFiles].getName();
		    File newCleanDir = new File(nextCleanDir);
                    deleteDirectory(newCleanDir.getAbsolutePath());
                }                    
            }// End for loop
        } // End if statement            
        cleanDir.delete();
    
protected java.lang.StringgetAbstractArchiveUri(com.sun.enterprise.deployment.WebBundleDescriptor desc)

        String archBase = getVerifierContext().getAbstractArchive().
                getArchiveUri();
        final ModuleDescriptor moduleDescriptor = desc.getModuleDescriptor();
        if (moduleDescriptor.isStandalone()) {
            return archBase; // it must be a stand-alone module; no such physical dir exists
        } else {
            return archBase + File.separator +
                    FileUtils.makeFriendlyFileName(moduleDescriptor.getArchiveUri());
        }
    
public java.lang.ClassloadClass(com.sun.enterprise.tools.verifier.Result result, java.lang.String className)

load a class from the web bundle archive file

param
result to put error if necessary
param
className the class to load
return
the loaded class or null is cannot be loaded from the archive

	
        try {
            WebTestsUtil webTestsUtil = WebTestsUtil.getUtil(context.getClassLoader());
	    //webTestsUtil.appendCLWithWebInfContents();
	    return webTestsUtil.loadClass(className);
        } catch (Throwable e) {

            // @see preVerify Method of Verifier.java
            try {
                ClassLoader cl = getVerifierContext().getAlternateClassLoader();
              if (cl == null) {
                  throw e;
               }
                Class c = cl.loadClass(className);
                return c;
             }catch(Throwable ex) {
               /*
               result.addErrorDetails(smh.getLocalString
               ("com.sun.enterprise.tools.verifier.tests.web.WebTest.Exception",
                "Error: Unexpected exception occurred [ {0} ]",
                new Object[] {ex.toString()}));
               */
            }
        } 
        return null;
    
public com.sun.enterprise.tools.verifier.ResultloadWarFile(com.sun.enterprise.deployment.WebBundleDescriptor descriptor)
load the war file

param
descriptor the Enumeration
return
Result the results for this assertion

        
        Result result = getInitializedResult();
	ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
	context = getVerifierContext();
        try {
            // TODO : check whether this method is required?
            WebTestsUtil webTestsUtil = WebTestsUtil.getUtil(context.getClassLoader());
//            File f = Verifier.getArchiveFile(descriptor.getModuleDescriptor().
//                     getArchiveUri());
//            if (f != null) {
//	         webTestsUtil.extractJarFile(f);
//             }
//             else {
//               // dont bother about extracting JarFile
//             }
	    //Sheetal: 09/30/02
	    //dont need to call Verifier's appendCLWithWebInfContents() since J2EEClassLoader takes care of it
	    //webTestsUtil.appendCLWithWebInfContents();
        } catch (Throwable e) {
//	    e.printStackTrace();
            Verifier.debug(e);
	    result.addErrorDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));
            result.addErrorDetails(smh.getLocalString
		("com.sun.enterprise.tools.verifier.tests.web.WebTest" + ".Exception",
		 "Error: Unexpected exception occurred [ {0} ]",
		 new Object[] {e.toString()}));
        }                
        return result;