KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > test > serverplugins > generic > GenericInstanceTest


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.test.serverplugins.generic;
21
22 import org.netbeans.junit.NbTestCase;
23 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
24 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
25 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
26 import org.netbeans.modules.test.serverplugins.api.ConstantsProvider;
27 import org.netbeans.modules.test.serverplugins.api.ServerProvider;
28 import org.openide.util.NbBundle;
29
30 /**
31  * Generic instantiation tests
32  *
33  * @author Michal Mocnak
34  */

35 public class GenericInstanceTest extends NbTestCase {
36     
37     private ConstantsProvider cProvider;
38     private ServerProvider sProvider;
39     
40     /**
41      * Creates a new instance of GenericInstanceTest
42      *
43      * @param name name of the test method which has to be performed
44      * @param cProvider instance of ConstantsProvider
45      * @param sProvider instance of ServerProvider
46      */

47     public GenericInstanceTest(String JavaDoc name, ConstantsProvider cProvider, ServerProvider sProvider) {
48         super(name);
49         
50         this.cProvider = cProvider;
51         this.sProvider = sProvider;
52     }
53     
54     /**
55      * Add application server's instance test
56      */

57     public void addInstanceTest() {
58         try {
59             // Add a server instance
60
InstanceProperties ip = InstanceProperties.createInstanceProperties(
61                     cProvider.getServerURI(), cProvider.getUsername(),
62                     cProvider.getPassword(), cProvider.getDisplayName());
63             
64             // Set server specific properties
65
sProvider.setServerSpecificProperties(ip);
66             
67             // Test if the instance is well added
68
ServerRegistry.getInstance().checkInstanceExists(cProvider.getServerURI());
69         } catch(Exception JavaDoc e) {
70             fail(e.getMessage());
71         }
72     }
73     
74     /**
75      * Remove server instance test
76      */

77     public void removeInstanceTest() {
78         try {
79             // Get instance from ServerRegistry
80
ServerInstance si = ServerRegistry.getInstance().getServerInstance(cProvider.getServerURI());
81             
82             // Remove instance
83
if (!si.isRemoveForbidden())
84                 si.remove();
85             else
86                 return;
87             
88             // Check if the instance is removed
89
if (null != ServerRegistry.getInstance().getServerInstance(cProvider.getServerURI()))
90                 throw new Exception JavaDoc(NbBundle.getMessage(GenericInstanceTest.class, "MSG_Remove_Failed", cProvider.getServerURI()));
91         } catch(Exception JavaDoc e) {
92             fail(e.getMessage());
93         }
94     }
95 }
Popular Tags