KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > test > AddRemoveSjsasInstanceTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.sun.test;
21
22 import java.io.File JavaDoc;
23 import org.netbeans.junit.NbTestCase;
24 import org.netbeans.junit.NbTestSuite;
25 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
26 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
27 import org.netbeans.modules.j2ee.sun.ide.j2ee.ui.AddDomainWizardIterator;
28 import org.openide.WizardDescriptor;
29 import org.openide.WizardDescriptor.Panel;
30
31 /**
32  *
33  * @author Michal Mocnak
34  */

35 public class AddRemoveSjsasInstanceTest extends NbTestCase {
36     
37     private final int SLEEP = 10000;
38     
39     public AddRemoveSjsasInstanceTest(String JavaDoc testName) {
40         super(testName);
41     }
42     
43     public void addSjsasInstance() {
44         try {
45             AddDomainWizardIterator inst = new AddDomainWizardIterator();
46             WizardDescriptor wizard = new WizardDescriptor(new Panel[] {});
47             wizard.putProperty(Util.PLATFORM_LOCATION, new File JavaDoc(Util._PLATFORM_LOCATION));
48             wizard.putProperty(Util.INSTALL_LOCATION, Util._INSTALL_LOCATION);
49             wizard.putProperty(Util.PROP_DISPLAY_NAME, Util._DISPLAY_NAME);
50             wizard.putProperty(Util.HOST, Util._HOST);
51             wizard.putProperty(Util.PORT, Util._PORT);
52             wizard.putProperty(Util.DOMAIN, Util._DOMAIN);
53             wizard.putProperty(Util.USER_NAME, Util._USER_NAME);
54             wizard.putProperty(Util.PASSWORD, Util._PASSWORD);
55             
56             inst.initialize(wizard);
57             inst.instantiate();
58             
59             ServerRegistry.getInstance().checkInstanceExists(Util._URL);
60             
61             Util.sleep(SLEEP);
62         } catch(Exception JavaDoc e) {
63             fail(e.getMessage());
64         }
65     }
66     
67     public void removeSjsasInstance() {
68         try {
69             Util.sleep(SLEEP);
70             
71             ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL);
72             boolean wasRunning = inst.isRunning();
73             
74             inst.remove();
75             
76             if (wasRunning) {
77                 Util.sleep(SLEEP);
78             }
79
80             try {
81                 ServerRegistry.getInstance().checkInstanceExists(Util._URL);
82             } catch(Exception JavaDoc e) {
83                 if (wasRunning && inst.isRunning())
84                     fail("remove did not stop the instance");
85                 String JavaDoc instances[] = ServerRegistry.getInstance().getInstanceURLs();
86                 if (null != instances)
87                     if (instances.length > 1)
88                         fail("too many instances");
89                 return;
90             }
91             
92             fail("Sjsas instance still exists !");
93         } catch(Exception JavaDoc e) {
94             fail(e.getMessage());
95         }
96     }
97     
98     public static NbTestSuite suite() {
99         NbTestSuite suite = new NbTestSuite("AddRemoveSjsasInstanceTest");
100         suite.addTest(new AddRemoveSjsasInstanceTest("addSjsasInstance"));
101         suite.addTest(new AddRemoveSjsasInstanceTest("removeSjsasInstance"));
102         return suite;
103     }
104 }
Popular Tags