FileDocCategorySizeDatePackage
JvmOptionsTest.javaAPI DocGlassfish v2 API17535Fri May 04 22:24:18 BST 2007com.sun.enterprise.admin.mbeans

JvmOptionsTest

public class JvmOptionsTest extends TestCase
Depends on junit.jar, admin/mbeans.jar, admin-core/util.jar, appserv-commons.jar

Fields Summary
Constructors Summary
public JvmOptionsTest(String name)

        super(name);
    
Methods Summary
public static voidmain(java.lang.String[] args)

        final TestRunner runner= new TestRunner();
        final TestResult result = runner.doRun(JvmOptionsTest.suite(), false);
        System.exit(result.errorCount() + result.failureCount());
    
private voidprintOptions(JvmOptions o)

        String[] options = o.getJvmOptions();
        System.out.println("============================");
        for (int i = 0; i < options.length; i++)
        {
            System.out.println("Option[" + options[i] + "]");
        }
        System.out.println("============================");
    
protected voidsetUp()

    
public static junit.framework.Testsuite()

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

    
public voidtestAddDuplicateJvmOptions0()

        String[] sa = new String[] {"-x=y"};
        JvmOptions options = new JvmOptions(sa);
        String[] invalid = options.addJvmOptions(new String[] {"-x=y"});
        Assert.assertTrue(Arrays.equals(new String[] {"-x=y"}, invalid));
        Assert.assertTrue(Arrays.equals(new String[] {"-x=y"}, 
            options.getJvmOptions()));
    
public voidtestAddDuplicateJvmOptions1()

        String[] sa = new String[] {"-x=y", "-a=b"};
        JvmOptions options = new JvmOptions(sa);
        String[] invalid = options.addJvmOptions(new String[] {"-a=b"});
        Assert.assertTrue(Arrays.equals(new String[] {"-a=b"}, invalid));
        Assert.assertTrue(Arrays.equals(new String[] {"-x=y", "-a=b"}, 
            options.getJvmOptions()));
    
public voidtestAddDuplicateJvmOptions2()

        String[] sa = new String[] {"-x=y -a=b"};
        JvmOptions options = new JvmOptions(sa);
        String[] invalid = options.addJvmOptions(new String[] {"-a=b"});
        Assert.assertTrue(Arrays.equals(new String[] {"-a=b"}, invalid));
        Assert.assertTrue(Arrays.equals(new String[] {"-x=y -a=b"}, 
            options.getJvmOptions()));
    
public voidtestAddDuplicateJvmOptions3()

        String[] sa = new String[] {"-x=y -a=b"};
        JvmOptions options = new JvmOptions(sa);
        String[] invalid = options.addJvmOptions(new String[] {"-a=b", "-c=d"});
        Assert.assertTrue(Arrays.equals(new String[] {"-a=b"}, invalid));
        Assert.assertTrue(Arrays.equals(new String[] {"-x=y -a=b", "-c=d"}, 
            options.getJvmOptions()));
    
public voidtestAddDuplicateJvmOptions4()

        String[] sa = new String[] {"-x=y -a=b"};
        JvmOptions options = new JvmOptions(sa);
        String[] invalid = options.addJvmOptions(new String[] {"-a=b -c=d"});
        Assert.assertTrue(invalid.length == 0);
        Assert.assertTrue(Arrays.equals(new String[] {"-x=y -a=b", "-a=b -c=d"}, 
            options.getJvmOptions()));
    
public voidtestAddInValidJvmOptions()

        JvmOptions options = new JvmOptions(new String[] {"-option_with_dash"});
        try
        {
            options.addJvmOptions(new String[] {"option_with_no_dash"});
        }
        catch (InvalidJvmOptionException e)
        {
            //ok
        }
    
public voidtestAddJvmOptions()

        String[] sa = new String[] {"-x=y", "-a=b"};
        JvmOptions options = new JvmOptions(sa);
        String[] invalid = options.addJvmOptions(new String[] {"-c=d"});
        Assert.assertTrue(invalid.length == 0);
        Assert.assertTrue(Arrays.equals(new String[] {"-x=y", "-a=b", "-c=d"}, 
            options.getJvmOptions()));
    
public voidtestAddJvmOptionsNull()

        String[] sa = new String[] {"-x=y", "-a=b"};
        JvmOptions options = new JvmOptions(sa);
        try
        {
            options.addJvmOptions(null);
            Assert.assertTrue(false);
        }
        catch (IllegalArgumentException iae)
        {
            Assert.assertTrue(Arrays.equals(sa, options.getJvmOptions()));
        }
    
public voidtestAddJvmOptionsZeroLength()

        String[] sa = new String[] {"-x=y", "-a=b"};
        JvmOptions options = new JvmOptions(sa);
        options.addJvmOptions(new String[0]);
        Assert.assertTrue(Arrays.equals(sa, options.getJvmOptions()));
    
public voidtestAddNullJvmOption()

        String[] sa = new String[] {"-x=y", "-a=b"};
        JvmOptions options = new JvmOptions(sa);
        try
        {
            options.addJvmOptions(new String[] {null});
            Assert.assertTrue(false);
        }
        catch (IllegalArgumentException iae)
        {
            Assert.assertTrue(Arrays.equals(sa, options.getJvmOptions()));
        }
    
public voidtestAppServerJvmOptions()

        String[] options = new String[] {
            "-client",
            "-Djava.endorsed.dirs=${com.sun.aas.installRoot}/lib/endorsed",
            "-Djava.security.policy=${com.sun.aas.instanceRoot}/config/server.policy",
            "-Djava.security.auth.login.config=${com.sun.aas.instanceRoot}/config/login.conf",
            "-Dsun.rmi.dgc.server.gcInterval=3600000",
            "-Dcom.sun.web.console.appbase=/${com.sun.aas.installRoot}/lib/install/applications/com_sun_web_ui",
            "-Xmx512m",
            "-Djavax.net.ssl.keyStore=${com.sun.aas.instanceRoot}/config/keystore.jks",
            "-Djavax.net.ssl.trustStore=${com.sun.aas.instanceRoot}/config/cacerts.jks",
            "-Djava.ext.dirs=${com.sun.aas.javaRoot}/jre/lib/ext${path.separator}${com.sun.aas.instanceRoot}/lib/ext",
            "-Djdbc.drivers=com.pointbase.jdbc.jdbcUniversalDriver",
            "-Djavax.xml.transform.TransformerFactory=org.apache.xalan.xsltc.trax.TransformerFactoryImpl"
        };
        try
        {
            JvmOptions jvmOptions = new JvmOptions(options);
            Assert.assertTrue(Arrays.equals(options, jvmOptions.getJvmOptions()));
        }
        catch (InvalidJvmOptionException e)
        {
            Assert.assertTrue(false);
        }
    
public voidtestCreateInValidJvmOptions()

        try
        {
            JvmOptions options = new JvmOptions(new String[] {"option_with_no_dash"});
        }
        catch (InvalidJvmOptionException e)
        {
            //ok
        }
    
public voidtestCreateJvmOptions()

        String[] sa = new String[] {"-x=y", "-a=b"};
        JvmOptions options = new JvmOptions(sa);
        Assert.assertTrue(Arrays.equals(sa, options.getJvmOptions()));

        sa = new String[] {"-x=y -a=b", "-a=b"};
        options = new JvmOptions(sa);
        Assert.assertTrue(Arrays.equals(sa, options.getJvmOptions()));

        sa = new String[] {"-x=y -x=y"};
        options = new JvmOptions(sa);
        Assert.assertTrue(Arrays.equals(
            new String[] {"-x=y"}, options.getJvmOptions()));
    
public voidtestCreateNull()

        try
        {
            JvmOptions options = new JvmOptions(null);
            Assert.assertTrue(false);
        }
        catch (IllegalArgumentException iae)
        {
            //ok
        }
    
public voidtestCreateOptionNull()

        String[] sa = new String[] {"-x=y", null};
        try
        {
            JvmOptions options = new JvmOptions(sa);
            Assert.assertTrue(false);
        }
        catch (IllegalArgumentException iae)
        {
            //ok
        }
    
public voidtestDeleteInValidJvmOptions()

        JvmOptions options = new JvmOptions(new String[] {"-option_with_dash"});
        options.deleteJvmOptions(new String[] {"option_with_no_dash"});
        Assert.assertTrue(Arrays.equals(
            new String[] {"-option_with_dash"}, options.getJvmOptions()));
    
public voidtestDeleteJvmOptions()

        String[] sa = new String[] {"-x=y"};
        JvmOptions options = new JvmOptions(sa);
        String[] invalid = options.deleteJvmOptions(new String[]{"-x=y"});
        Assert.assertTrue(invalid.length == 0);
        Assert.assertTrue(Arrays.equals(
            new String[0], options.getJvmOptions()));
    
public voidtestDeleteJvmOptions1()

        String[] sa = new String[] {"-x=y", "-a=b"};
        JvmOptions options = new JvmOptions(sa);
        String[] invalid = options.deleteJvmOptions(new String[]{"-x=y"});
        Assert.assertTrue(invalid.length == 0);
        Assert.assertTrue(Arrays.equals(
            new String[]{"-a=b"}, options.getJvmOptions()));
    
public voidtestDeleteJvmOptions2()

        String[] sa = new String[] {"-x=y -a=b"};
        JvmOptions options = new JvmOptions(sa);
        String[] invalid = options.deleteJvmOptions(new String[]{"-x=y"});
        Assert.assertTrue(invalid.length == 0);
        Assert.assertTrue(Arrays.equals(
            new String[]{"-a=b"}, options.getJvmOptions()));
    
public voidtestDeleteJvmOptions3()

        String[] sa = new String[] {"-x=y -a=b -c=d"};
        JvmOptions options = new JvmOptions(sa);
        String[] invalid = options.deleteJvmOptions(new String[]{"-x=y", "-c=d"});
        Assert.assertTrue(invalid.length == 0);
        Assert.assertTrue(Arrays.equals(
            new String[]{"-a=b"}, options.getJvmOptions()));
    
public voidtestDeleteJvmOptions4()

        String[] sa = new String[] {"-x=y -a=b", "-a=b -c=d"};
        JvmOptions options = new JvmOptions(sa);
        String[] invalid = options.deleteJvmOptions(new String[]{"-x=y", "-c=d"});
        Assert.assertTrue(invalid.length == 0);
        Assert.assertTrue(Arrays.equals(
            new String[]{"-a=b"}, options.getJvmOptions()));
    
public voidtestDeleteJvmOptions5()

        String[] sa = new String[] {"-x=y"};
        JvmOptions options = new JvmOptions(sa);
        String[] invalid = options.deleteJvmOptions(new String[]{"-c=d"});
        Assert.assertTrue(Arrays.equals(invalid, new String[]{"-c=d"}));
        Assert.assertTrue(Arrays.equals(
            new String[]{"-x=y"}, options.getJvmOptions()));
    
public voidtestDeleteJvmOptions6()

        String[] sa = new String[] {"-x=y", "-a=b"};
        JvmOptions options = new JvmOptions(sa);
        String[] invalid = options.deleteJvmOptions(new String[]{"-a=b", "-c=d"});
        Assert.assertTrue(Arrays.equals(invalid, new String[]{"-c=d"}));
        Assert.assertTrue(Arrays.equals(
            new String[]{"-x=y"}, options.getJvmOptions()));
    
public voidtestDeleteJvmOptions7()

        String[] sa = new String[] {"-x=y "};
        JvmOptions options = new JvmOptions(sa);
        String[] invalid = options.deleteJvmOptions(new String[]{"-a=b"});
        Assert.assertTrue(Arrays.equals(invalid, new String[]{"-a=b"}));
        Assert.assertTrue(Arrays.equals(
            new String[]{"-x=y"}, options.getJvmOptions()));
    
public voidtestDeleteJvmOptionsNull()

        String[] sa = new String[] {"-x=y"};
        JvmOptions options = new JvmOptions(sa);
        try
        {
            options.deleteJvmOptions(null);
        }
        catch (IllegalArgumentException iae)
        {
            Assert.assertTrue(Arrays.equals(sa, options.getJvmOptions()));
        }
    
public voidtestDeleteJvmOptionsZeroLength()

        String[] sa = new String[] {"-x=y", "-a=b"};
        JvmOptions options = new JvmOptions(sa);
        options.deleteJvmOptions(new String[0]);
        Assert.assertTrue(Arrays.equals(sa, options.getJvmOptions()));
    
public voidtestDeleteNullJvmOption()

        String[] sa = new String[] {"-x=y"};
        JvmOptions options = new JvmOptions(sa);
        try
        {
            options.deleteJvmOptions(new String[]{null});
        }
        catch (IllegalArgumentException iae)
        {
            Assert.assertTrue(Arrays.equals(sa, options.getJvmOptions()));
        }
    
public voidtestJvmOptions()

        String[] sa = new String[] {"-x=y"};
        JvmOptions options = new JvmOptions(sa);

        options.addJvmOptions(new String[]{"-a=b", "-c=d"});
        Assert.assertTrue(Arrays.equals(
            new String[]{"-x=y", "-a=b", "-c=d"}, options.getJvmOptions()));

        options.addJvmOptions(new String[]{"-a=b -c=d"});
        Assert.assertTrue(Arrays.equals(
            new String[]{"-x=y", "-a=b", "-c=d", "-a=b -c=d"}, options.getJvmOptions()));
        String[] invalid = options.deleteJvmOptions(new String[]{"-a=b"});
        Assert.assertTrue(invalid.length == 0);
    
public voidtestJvmOptionsElement()

        JvmOptionsElement e = new JvmOptionsElement("-x=y");
        Assert.assertFalse(e.hasNext());
        JvmOptionsElement next = new JvmOptionsElement("-a=b");
        e.setNext(next);
        Assert.assertTrue(e.hasNext());
        Assert.assertEquals(next, e.next());
        JvmOptionsElement next1 = new JvmOptionsElement("-c=d");
        next.setNext(next1);
        Assert.assertEquals(next1, e.next().next());
        JvmOptionsElement next2 = new JvmOptionsElement("-a=b -c=d");
        next1.setNext(next2);

        boolean b = e.deleteJvmOption("-a=b");
        Assert.assertTrue(b);
    
public voidtestQuotedOptions()

        String[] options = new String[] {"-Dfile=\"a b\""};
        JvmOptions jvmOptions = new JvmOptions(options);
        Assert.assertTrue(Arrays.equals(options, jvmOptions.getJvmOptions()));
        jvmOptions.deleteJvmOptions(options);

        try {
            new JvmOptions(new String[] {"-Dfile=\""});
            Assert.assertTrue(false);
        } catch (InvalidJvmOptionException e) {}

        try {
            new JvmOptions(new String[] {"-Dx=\"a\" -Dy=\"b"});
            Assert.assertTrue(false);
        } catch (InvalidJvmOptionException e) {}

        try {
            new JvmOptions(new String[] {"-Dx=\"a\" -Dy=\"b"});
            Assert.assertTrue(false);
        } catch (InvalidJvmOptionException e) {}
    
public voidtestZeroLength()

        JvmOptions options = new JvmOptions(new String[0]);
        Assert.assertTrue(Arrays.equals(new String[0], options.getJvmOptions()));