KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > util > AppserverConnectionFactoryTest


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 package org.netbeans.modules.j2ee.sun.util;
20
21 import java.io.IOException JavaDoc;
22 import junit.framework.*;
23 import com.sun.appserv.management.client.ConnectionSource;
24 import com.sun.appserv.management.client.AppserverConnectionSource;
25 import com.sun.appserv.management.DomainRoot;
26 import org.netbeans.modules.j2ee.sun.util.AppserverConnectionFactory;
27
28 /**
29  *
30  *
31  */

32 public class AppserverConnectionFactoryTest extends TestCase {
33     
34     private static final String JavaDoc HOST = "localhost";
35     private static final int PORT = 4848;
36     private static final String JavaDoc USER_NAME = "admin";
37     private static final String JavaDoc PASSWORD = "adminadmin";
38     
39     
40     public AppserverConnectionFactoryTest(java.lang.String JavaDoc testName) {
41         super(testName);
42     }
43     
44     public void testGetHTTPAppserverConnection() {
45         AppserverConnectionSource conn =
46             AppserverConnectionFactory.getHTTPAppserverConnectionSource(HOST,
47                 PORT, USER_NAME, PASSWORD, null);
48         assertNotNull(conn);
49         try {
50             conn.getDomainRoot();
51         } catch(IOException JavaDoc e) {
52             fail("Error connecting to the DAS!!!");
53             e.printStackTrace();
54         }
55     }
56     
57     public void testIsAppserverConnectionSecurityEnabled() {
58         try {
59             System.out.println("Is Security Enabled? " +
60             AppserverConnectionFactory.isAppserverConnectionSecurityEnabled(
61                     AppserverConnectionFactory.getHTTPAppserverConnectionSource(
62                         HOST, PORT, USER_NAME, PASSWORD, null)));
63         } catch(IOException JavaDoc e) {
64             e.printStackTrace();
65         }
66     }
67     
68     
69     public void testGetAppserverConnection() {
70         try {
71             AppserverConnectionSource conn =
72                 AppserverConnectionFactory.getAppserverConnection(HOST, PORT,
73                     USER_NAME, PASSWORD, null, false);
74             System.out.println(conn.getDomainRoot().getAppserverDomainName());
75             System.out.println(conn.getJMXConnector(false).getConnectionId());
76             AppserverConnectionSource conn2 =
77                 AppserverConnectionFactory.getAppserverConnection(HOST, PORT,
78                     USER_NAME, PASSWORD, null, true);
79             AppserverConnectionSource conn3 =
80                 AppserverConnectionFactory.getAppserverConnection(HOST, PORT,
81                     USER_NAME, PASSWORD, null, false);
82         } catch(Exception JavaDoc e) {
83             e.printStackTrace();
84         }
85     }
86     
87     
88     public static Test suite() {
89         TestSuite suite = new TestSuite(AppserverConnectionFactoryTest.class);
90         return suite;
91     }
92     
93     public static void main(java.lang.String JavaDoc[] args) {
94         junit.textui.TestRunner.run(suite());
95     }
96     
97 }
Popular Tags