FileDocCategorySizeDatePackage
TestSrcContent.javaAPI DocApache Axis 1.49741Sat Apr 22 18:57:28 BST 2006test.utils

TestSrcContent

public class TestSrcContent extends TestCase
This TestCase verifies that content of the source files adheres to certain coding practices by matching regular expressions (string patterns): - Verify that Log4J logger is not being used directly ("org.apache.log4j" is not in source files). - Verify that System.out.println is not used except in wsdl to/from java tooling. - Verify that log.info(), log.warn(), log.error(), and log.fatal() use Messages.getMessage() (i18n). - Verify that exceptions are created with Messages.getMessage() (i18n). To add new patterns, search for and append to the private attribute 'avoidPatterns'. Based on code in TestMessages.java.

Fields Summary
private static final String
LS
private String
errors
private static final FileNameContentPattern[]
avoidPatterns
Patterns to be checked. Each pattern has three parameters: (i) a pattern that matches filenames that are to be checked, (ii) a pattern to be searched for in the chosen files (iii) whether the pattern is to be allowed (typically false indicating not allowed) See the Axis Developer's Guide for more information.
Constructors Summary
public TestSrcContent(String name)

        super(name);
    
Methods Summary
private voidcheckFile(java.io.File file)


        
        try {
            FileInputStream fis = new FileInputStream(file);
            byte[] bytes = new byte[fis.available()];
            fis.read(bytes);
            String content = new String(bytes);

            for (int i = 0; i < avoidPatterns.length; i++) {
                if (avoidPatterns[i].noMatch(file.getPath(), content)) {
                //                if (content.indexOf(avoidStrings[i]) >= 0) {
                    errors = errors
                        + "File: " + file.getPath() + ": "
                        + (avoidPatterns[i].getExpectContent()
                           ? "Expected: "
                           : "Unexpected: ")
                        + avoidPatterns[i].getContentPattern()
                        + LS;
                }
            }
        }
        catch (Throwable t) {
            errors = errors
                + "File: " + file.getPath()
                + ": " + t.getMessage()
                + LS;
        }
    
public static junit.framework.Testsuite()

        return new TestSuite(TestSrcContent.class);
    
public voidtestSourceFiles()
If this test is run from xml-axis/java, then walk through the source tree (xml-axis/java/src), calling checkFile for each file.


                            
       
        String baseDir = System.getProperty("user.dir");
        File   srcDir = new File(baseDir, "src");

        if (srcDir.exists()) {
            walkTree(srcDir);
        }

        if (!errors.equals("")) {
            throw new AssertionFailedError(errors);
        }
    
private voidwalkTree(java.io.File srcDir)
Walk the source tree

        File[] files = srcDir.listFiles();
        for (int i = 0; i < files.length; ++i) {
            if (files[i].isDirectory()) {
                walkTree(files[i]);
            }
            else {
                checkFile(files[i]);
            }
        }