FileDocCategorySizeDatePackage
Util.javaAPI DocApache James 2.3.15443Fri Jan 12 12:56:36 GMT 2007org.apache.james.test.util

Util

public class Util extends Object
some utilities for James unit testing

Fields Summary
private static final int
PORT_RANGE_START
private static final int
PORT_RANGE_END
private static int
PORT_LAST_USED
Constructors Summary
Methods Summary
private static org.apache.avalon.framework.configuration.DefaultConfigurationcreateCommandHandlerConfiguration(java.lang.String command, java.lang.Class commandClass)

        DefaultConfiguration cmdHandlerConfig = new DefaultConfiguration("handler");
        if (command != null) {
            cmdHandlerConfig.setAttribute("command", command);
        }
        String classname = commandClass.getName();
        cmdHandlerConfig.setAttribute("class", classname);
        return cmdHandlerConfig;
    
public static org.apache.avalon.framework.configuration.DefaultConfigurationcreateRemoteManagerHandlerChainConfiguration()

        DefaultConfiguration handlerChainConfig = new DefaultConfiguration("test");
        return handlerChainConfig;
    
public static org.apache.avalon.framework.configuration.DefaultConfigurationcreateSMTPHandlerChainConfiguration()

        DefaultConfiguration handlerChainConfig = new DefaultConfiguration("handlerchain");
        handlerChainConfig.addChild(createCommandHandlerConfiguration("HELO", HeloCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("EHLO", EhloCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("AUTH", AuthCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("VRFY", VrfyCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("EXPN", ExpnCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("MAIL", MailCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("RCPT", RcptCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("DATA", DataCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("RSET", RsetCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("HELP", HelpCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("QUIT", QuitCmdHandler.class));
        // mail sender
        handlerChainConfig.addChild(createCommandHandlerConfiguration(null, SendMailHandler.class));
        return handlerChainConfig;
    
protected static synchronized intgetNextNonPrivilegedPort()
assigns ports sequentially from the range of test ports

return
port number

        // Hack to increase probability that the port is bindable
        while (true) {
            try {
        PORT_LAST_USED++;
        if (PORT_LAST_USED > PORT_RANGE_END) PORT_LAST_USED = PORT_RANGE_START;
                ServerSocket ss;
                ss = new ServerSocket(PORT_LAST_USED);
                ss.setReuseAddress(true);
                ss.close();
                break;
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return PORT_LAST_USED;
    
public static intgetNonPrivilegedPort()
assigns a port from the range of test ports

return
port number


                     
        
        return getNextNonPrivilegedPort(); // uses sequential assignment of ports
    
protected static intgetRandomNonPrivilegedPortInt()
assigns a random port from the range of test ports

return
port number

        return ((int)( Math.random() * (PORT_RANGE_END - PORT_RANGE_START) + PORT_RANGE_START));
    
public static org.apache.avalon.framework.configuration.ConfigurationgetValuedConfiguration(java.lang.String name, java.lang.String value)

        DefaultConfiguration defaultConfiguration = new DefaultConfiguration(name);
        defaultConfiguration.setValue(value);
        return defaultConfiguration;