FileDocCategorySizeDatePackage
PEDomainsManagerTest.javaAPI DocGlassfish v2 API10785Fri May 04 22:24:32 BST 2007com.sun.enterprise.admin.servermgmt.pe

PEDomainsManagerTest

public class PEDomainsManagerTest extends TestCase

Fields Summary
Constructors Summary
public PEDomainsManagerTest(String name)

        super(name);
        String templatesDir = System.getProperty("com.sun.aas.templatesDir");
        if (templatesDir == null)
        {
            throw new Exception("com.sun.aas.templatesDir is null");
        }
        if (!new File(templatesDir).exists())
        {
            throw new Exception(templatesDir + " Doesnot exist");
        }
        File dest = getFileLayout().getTemplatesDir();
        createClean(dest);
        copy(new File(templatesDir), dest);
    
Methods Summary
static voidcopy(java.io.File templatesDir, java.io.File dest)

        File[] fa = templatesDir.listFiles();
        for (int i = 0; i < fa.length; i++)
        {
            copyFile(fa[i], dest);
        }
    
static voidcopyFile(java.io.File src, java.io.File destDir)

        FileInputStream inStream = new FileInputStream(src);
        FileOutputStream outStream = new FileOutputStream(
            new File(destDir, src.getName()));
        try
        {
            byte[] buf = new byte[1024];
            int len = 0;
            while (len != -1) 
            {
                len = inStream.read(buf, 0, buf.length);
                if (len == -1) { break; }
                outStream.write(buf, 0, len);
            }
        }
        finally
        {
            inStream.close();
            outStream.close();
        }
    
static voidcreateClean(java.io.File f)

        f.delete();
        f.mkdirs();
        if (!f.exists())
        {
            throw new IOException("Could not create " + f.getAbsolutePath());
        }
    
private java.util.MapgetDomainConfig()

        final Map domainConfig = new HashMap();
        domainConfig.put(DomainConfig.K_INSTALL_ROOT, getInstallRoot());
        domainConfig.put(DomainConfig.K_DOMAINS_ROOT, getDomainRoot());
        domainConfig.put(DomainConfig.K_HOST_NAME, "surya10");
        domainConfig.put(DomainConfig.K_ADMIN_PORT, Integer.valueOf(8888));
        domainConfig.put(DomainConfig.K_INSTANCE_PORT, Integer.valueOf(8889));
        domainConfig.put(DomainConfig.K_ORB_LISTENER_PORT, Integer.valueOf(1025));
        domainConfig.put(DomainConfig.K_JAVA_HOME, getDomainRoot());
        domainConfig.put(DomainConfig.K_JMS_PASSWORD, "admin1");
        domainConfig.put(DomainConfig.K_JMS_USER, "admin1");
        domainConfig.put(DomainConfig.K_JMS_PORT, Integer.valueOf(7677));
        domainConfig.put(DomainConfig.K_HTTP_SSL_PORT, Integer.valueOf(8181));
        domainConfig.put(DomainConfig.K_IIOP_SSL_PORT, Integer.valueOf(1060));
        domainConfig.put(DomainConfig.K_IIOP_MUTUALAUTH_PORT,
                         Integer.valueOf(1061));

        return domainConfig;
    
private java.lang.StringgetDomainName()

        return "domain5";
    
private java.lang.StringgetDomainRoot()

        File f = new File(getInstallRoot(), "domains");
        f.mkdir();
        f.deleteOnExit();
        return f.getAbsolutePath();
    
private PEFileLayoutgetFileLayout()

        return new PEFileLayout(getInstallRoot(), getDomainRoot(),
            getDomainName());
    
private static java.lang.StringgetInstallRoot()

        File f = new File(System.getProperty("java.io.tmpdir"), 
                          System.getProperty("user.name", "install"));
        f.mkdir();
        f.deleteOnExit();
        return f.getAbsolutePath();
    
private java.lang.StringgetInstanceName()

        return "server";
    
private booleanisValidXml(java.io.File xml)

        boolean isValid = true;
        try
        {
            InputSource is = new InputSource(new FileInputStream(xml));
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setValidating(true);
            DocumentBuilder db = dbf.newDocumentBuilder();
            db.parse(is);
        }
        catch (Exception e) { e.printStackTrace(); isValid = false; }
        return isValid;
    
public static voidmain(java.lang.String[] args)

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

        fail("Not yet implemented");
    
protected voidsetUp()

    
public static junit.framework.Testsuite()

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

    
public voidtestCreate()

        assertNotNull("Couldnt create PEDomainManager", 
                    new PEDomainsManager());
    
public voidtestCreateAccXml()

        final PEDomainsManager mgr = new PEDomainsManager();
        mgr.createAppClientContainerXml(getDomainName(), getDomainConfig());
        assertTrue("Acc Xml file not created", 
            getFileLayout().getAppClientContainerXml(getDomainName(), 
                                            getInstanceName()).exists());
    
public voidtestCreateDefaultWebXml()

        final PEDomainsManager mgr = new PEDomainsManager();
        mgr.createDefaultWebXml(getDomainName(), getDomainConfig());
        assertTrue("Default Web Xml file not created", 
            getFileLayout().getDefaultWebXml(getDomainName(), 
                                            getInstanceName()).exists());
    
public voidtestCreateDomainXml()

        final PEDomainsManager mgr = new PEDomainsManager();
        mgr.createDomainXml(getDomainName(), getDomainConfig());
        final PEFileLayout layout = getFileLayout();
        final String domainName = getDomainName();
        final File domainXml = layout.getDomainConfigFile(domainName, 
                                                          getInstanceName());
        final File domainXmlBackup = 
            layout.getDomainConfigBackupFile(domainName, getInstanceName());
        assertTrue("Domain xml not created", domainXml.exists());
        assertTrue("Domain xml backup not created", domainXmlBackup.exists());
//         assertTrue("Invalid domain xml", isValidXml(domainXml));
    
public voidtestCreateFileLayout()

        final Map domainConfig = getDomainConfig();
        final PEDomainsManager mgr = new PEDomainsManager();
        mgr.createFileLayout(getDomainName(), domainConfig);

        final String domainRoot = 
            (String)domainConfig.get(DomainConfig.K_DOMAINS_ROOT);
        final String domainName = getDomainName();
        assertTrue("Domain dir not created",  
            new File(domainRoot, domainName).exists());

        final File repositoryRoot = 
            getFileLayout().getRepositoryRoot(domainName, getInstanceName());
        assertTrue("Repository dir not created", repositoryRoot.exists());

        final File repositoryBackup = 
            getFileLayout().getRepositoryBackupRoot(domainName, 
                                                    getInstanceName());
        assertTrue("Repository backup dir not created", 
            repositoryBackup.exists());
    
public voidtestCreateScripts()

        final PEDomainsManager mgr = new PEDomainsManager();
        mgr.createScripts(getDomainName(), getDomainConfig());
        final PEFileLayout layout = getFileLayout();
        final File startServ = layout.getStartServ(getDomainName(), 
                                                   getInstanceName());
        final File stopServ = layout.getStopServ(getDomainName(), 
                                                 getInstanceName());
        assertTrue("startserv not created", startServ.exists());
        assertTrue("stopserv not created", stopServ.exists());
    
public voidtestCreateServerPolicyFile()

        final PEDomainsManager mgr = new PEDomainsManager();
        mgr.createServerPolicyFile(getDomainName(), getDomainConfig());
        assertTrue("Policy file not created", 
            getFileLayout().getPolicyFile(getDomainName(), 
                                          getInstanceName()).exists());
    
public voidtestValidate()

        final Map domainConfig = getDomainConfig();
        final PEDomainsManager mgr = new PEDomainsManager();
        mgr.validate(getDomainName(), domainConfig);