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

TargetTest

public class TargetTest extends TestCase

Fields Summary
private com.sun.enterprise.config.ConfigContext
domainContext
private static File
domainXml
Constructors Summary
public TargetTest(String name)

        super(name);
    
Methods Summary
private com.sun.enterprise.config.ConfigContextgetConfigContext()

        return ConfigFactory.createConfigContext(domainXml.getAbsolutePath());
    
private java.lang.StringgetConfigRef()

        return "server-config";
    
private java.lang.StringgetDomainName()

        return "testdomain";
    
private com.sun.enterprise.admin.mbeans.TargetTest$TargetDatagetTargetData(java.lang.String name, TargetType type, java.lang.String configRef, boolean is1ToN, java.lang.String target, boolean checkConfigTarget)

        TargetData td = new TargetData();
        td.name = name;
        td.type = type;
        td.configRef = configRef;
        td.is1ToN = is1ToN;
        td.target = target;
        td.checkConfigTarget = checkConfigTarget;
        return td;
    
private java.lang.StringgetTargetObjectName(java.lang.String name, TargetType type)

        String on = null;
        if (type.equals(TargetType.DOMAIN))
        {
            on = getDomainName() + ":type=domain,category=config";
        }
        else if (type.equals(TargetType.CONFIG))
        {
            on = getDomainName() + ":type=config,category=config,name=" + name;
        }
        else if (type.equals(TargetType.SERVER))
        {
            on = getDomainName() + ":type=server,category=config,name=" + name;
        }
        return on;
    
public static voidmain(java.lang.String[] args)

        final TestRunner runner= new TestRunner();
        setDomainXml(new File(args[0]));
        final TestResult result = runner.doRun(TargetTest.suite(), false);
        System.exit(result.errorCount() + result.failureCount());
    
public static voidsetDomainXml(java.io.File xml)

        domainXml = xml;
    
protected voidsetUp()

        try
        {
            domainContext = getConfigContext();
        }
        catch (Exception e)
        {
            throw new RuntimeException(e.getMessage());
        }
    
public static junit.framework.Testsuite()

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

        domainContext = null;
    
public voidtestTarget()

        testTarget(getTargetData(null, TargetType.SERVER, getConfigRef(), 
                    false, "server", true));
        testTarget(getTargetData("server", TargetType.SERVER, getConfigRef(), 
                    false, "server", true));
        testTarget(getTargetData("domain", TargetType.DOMAIN, null, false, 
                    "domain", false));
        testTarget(getTargetData(getConfigRef(), TargetType.CONFIG, 
                    getConfigRef(), false, getConfigRef(), true));
    
voidtestTarget(com.sun.enterprise.admin.mbeans.TargetTest$TargetData td)

        Target target = TargetBuilder.INSTANCE.createTarget(
                                    td.name, domainContext);
        Assert.assertTrue(target != null);
        Assert.assertEquals(td.type, target.getType());
        Assert.assertEquals(getTargetObjectName(td.target, td.type), 
            target.getTargetObjectName(new String[] { getDomainName() }));
        Assert.assertEquals(td.configRef ,target.getConfigRef());
        if (td.checkConfigTarget)
        {
            final ConfigTarget configTarget = target.getConfigTarget();
            Assert.assertTrue(configTarget != null);
            Assert.assertEquals(td.is1ToN, configTarget.is1ToN(target));
        }
    
public voidtestUnknownTarget()

        try
        {
            Target target = TargetBuilder.INSTANCE.createTarget(
                "abcd", domainContext);
            Assert.assertTrue(false);
        }
        catch (Exception e) {}
        try
        {
            Target target = TargetBuilder.INSTANCE.createTarget(null, null);
            Assert.assertTrue(false);
        }
        catch (Exception e) {}