FileDocCategorySizeDatePackage
BaseLifeCycleCommandTest.javaAPI DocGlassfish v2 API13895Fri May 04 22:25:18 BST 2007com.sun.enterprise.cli.commands

BaseLifeCycleCommandTest

public class BaseLifeCycleCommandTest extends TestCase
Execute these tests using gmake (and Ant) by: cd gmake ANT_TARGETS=CommandTest.java

Fields Summary
BaseLifeCycleCommand
testCommand
Constructors Summary
public BaseLifeCycleCommandTest(String name)

        super(name);
    
Methods Summary
private java.lang.StringcreateDomainFileSystem(java.lang.String domainParent, java.lang.String domainName)

        final File domainParentDir = new File(System.getProperty("java.io.tmpdir"), domainParent);
        domainParentDir.mkdir();
        domainParentDir.deleteOnExit();
        if (domainName == null) return domainParentDir.getPath();
        final File domainDir = new File(domainParentDir, domainName);
        domainDir.mkdir();
        domainDir.deleteOnExit();
        final File binDir =  new File(domainDir, PEFileLayout.BIN_DIR);
        binDir.mkdir();
        binDir.deleteOnExit();
        //System.out.println(PEFileLayout.START_SERV_OS);
        final File f = new File(binDir, PEFileLayout.START_SERV_OS);
        f.createNewFile();
        f.deleteOnExit();
        return domainParentDir.getPath();
    
public static voidmain(java.lang.String[] args)

        final TestRunner runner= new TestRunner();
        final TestResult result = runner.doRun(BaseLifeCycleCommandTest.suite(), false);
        System.exit(result.errorCount() + result.failureCount());
    
private voidnyi()

        fail("Not Yet Implemented");
    
protected voidsetUp()

    
        
        //Properties systemProperties = new java.util.Propertis();
        //systemProperties.put("com.sun.aas.configRoot",)
        //String configProperty = SystemPropertyConstants.CONFIG_ROOT_PROPERTY;
        //System.out.println(configProperty + " = " + System.getProperty(configProperty));
        final CLIDescriptorsReader cliDescriptorsReader = CLIDescriptorsReader.getInstance();
        ValidCommand validCommand = cliDescriptorsReader.getCommand(null);
        LocalStringsManagerFactory.setCommandLocalStringsManagerProperties(
                CLIDescriptorsReader.getInstance().getProperties());
        testCommand = new BaseLifeCycleCommand() {
            public void runCommand()
            throws CommandException, CommandValidationException {
            }
            public boolean validateOptions() throws CommandValidationException {
                return true;
            }
        };
        testCommand.setName("sampleCommand");
    
public static junit.framework.Testsuite()

        TestSuite suite = new TestSuite(BackupCommandsTest.class);
        return suite;
    
protected voidtearDown()

    
public voidtestIsSpaceInPathFalse()

        assertEquals(testCommand.isSpaceInPath("StringHasNospace"), false);
    
public voidtestIsSpaceInPathTrue()

        assertEquals(testCommand.isSpaceInPath("String has space"), true);
    
public voidtestgetAdminUserFromCommandLine()

        testCommand.setOption("adminuser", "userFromCommandLine");
        String adminUser = testCommand.getAdminUser();
        assertEquals(adminUser, "userFromCommandLine");
    
public voidtestgetAdminUserFromPrefsFile()

        final String enc = "ISO-8859-1";
        final File f = new File(System.getProperty("java.io.tmpdir"),
                testCommand.ASADMINPREFS);
        f.deleteOnExit();
        final PrintWriter pw = new PrintWriter(
                new OutputStreamWriter(new FileOutputStream(f), enc));
        pw.println("AS_ADMIN_ADMINUSER=adminuserFromPrefsFile");
        pw.close();
        System.setProperty("user.home", System.getProperty("java.io.tmpdir"));
        String adminUser = testCommand.getAdminUser();
        assertEquals(adminUser, "adminuserFromPrefsFile");
    
public voidtestgetAdminUserFromPrefsFileUsingUserOption()

        final String enc = "ISO-8859-1";
        final File f = new File(System.getProperty("java.io.tmpdir"),
                testCommand.ASADMINPREFS);
        f.deleteOnExit();
        final PrintWriter pw = new PrintWriter(
                new OutputStreamWriter(new FileOutputStream(f), enc));
        pw.println("AS_ADMIN_USER=userFromPrefsFile");
        pw.close();
        System.setProperty("user.home", System.getProperty("java.io.tmpdir"));
        String adminUser = testCommand.getAdminUser();
        assertEquals(adminUser, "userFromPrefsFile");
    
public voidtestgetAdminUserWhenNotSet()

        try{
            String adminUser = testCommand.getAdminUser();
        }catch(Exception e){
            assertEquals(e.getMessage(), "CLI152 adminuser is a required option.");
        }
    
public voidtestgetDomainNameFromFileSystem()

        String domainName = "test_domain";
        String dirName = createDomainFileSystem("testgetDomainNameFromFileSystem", domainName);
        System.setProperty(SystemPropertyConstants.DOMAINS_ROOT_PROPERTY, dirName);
        assertEquals(testCommand.getDomainName(), domainName);
    
public voidtestgetDomainNameFromFileSystemWhenNone()

        String dirName = "domainsDirXYZ";
        File domaindir = new File(System.getProperty("java.io.tmpdir"), dirName);
        try{
        domaindir.mkdir();
        domaindir.deleteOnExit();
        System.setProperty(SystemPropertyConstants.DOMAINS_ROOT_PROPERTY, domaindir.getAbsolutePath());
        String domainName = testCommand.getDomainName();
        } catch (Exception e)
        {
            assertEquals(e.getMessage(), "CLI142 No domains in " + 
                                domaindir.getAbsolutePath() + ".");
        }
    
public voidtestgetDomainNameFromFileSystemWithMultipleDomains()

        String dirName = "";
        try{
        String domainName1 = "test_domain1";
        dirName = createDomainFileSystem("testgetDomainNameFromFileSystemWithMultipleDomains", domainName1);
        String domainName2 = "test_domain2";
        createDomainFileSystem("testgetDomainNameFromFileSystemWithMultipleDomains", domainName2);
        System.setProperty(SystemPropertyConstants.DOMAINS_ROOT_PROPERTY, dirName);
        String domainName = testCommand.getDomainName();
        } catch (Exception e)
        {
            assertEquals(e.getMessage(), "There is more than one domain in " +
                            dirName + 
                            ". Please use operand to specify the domain.");
        }
    
public voidtestgetDomainNameOperandFromCommandLine()

        Vector operands = new Vector();
        operands.add("test_domain");
        testCommand.setOperands(operands);
        //assuming there is a default domain
    
public voidtestgetDomainNameOptionFromCommandLine()

        testCommand.setOption("domain", "test_domain");
        //assuming there is a default domain
        assertEquals(testCommand.getDomainName(), "test_domain");
    
public voidtestgetDomainNameWhenZero()

        try{
            Vector operands = new Vector();
            operands.add("UndefinedDomain");
            testCommand.setOperands(operands);
            testCommand.getDomainName();
        } catch (Exception e)
        {
            assertEquals(e.getMessage(), "CLI156 Could not start the domain UndefinedDomain.");
        }
    
public voidtestgetDomainsRootFromCommandLine()

        testCommand.setOption("domaindir", "test_domain");
        assertEquals(testCommand.getDomainsRoot(), "test_domain");
    
public voidtestgetDomainsRootFromSystemProperty()

        System.setProperty(SystemPropertyConstants.DOMAINS_ROOT_PROPERTY, "test_domain");
        assertEquals(testCommand.getDomainsRoot(), "test_domain");
    
public voidtestgetDomainsWhenMultiple()

        String domainName1 = "test_domain1";
        String dirName = createDomainFileSystem("testgetDomainsWhenMultiple", domainName1);
        String domainName2 = "test_domain2";
        createDomainFileSystem("testgetDomainsWhenMultiple", domainName2);
        System.setProperty(SystemPropertyConstants.DOMAINS_ROOT_PROPERTY, dirName);
        String[] domains = testCommand.getDomains();
        assertEquals(domains[0], domainName1);
        assertEquals(domains[1], domainName2);
    
public voidtestgetDomainsWhenOne()

        String domainName = "test_domain1";
        String dirName = createDomainFileSystem("testgetDomainsWhenOne", domainName);
        System.setProperty(SystemPropertyConstants.DOMAINS_ROOT_PROPERTY, dirName);
        String[] domains = testCommand.getDomains();
        assertEquals(domains[0], domainName);
    
public voidtestgetDomainsWhenZero()

        String dirName = createDomainFileSystem("testgetDomainsWhenZero", null);
        System.setProperty(SystemPropertyConstants.DOMAINS_ROOT_PROPERTY, dirName);
        String[] domains = testCommand.getDomains();
        assertEquals(domains.length, 0);
    
public voidtestisWindows()

        String os = System.getProperty("os.name").toLowerCase();
        assertEquals(testCommand.isWindows(), (os.indexOf("windows") != -1) ? true : false);