KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > SunONEDeploymentFactoryTest


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  * SunONEDeploymentFactoryTest.java
21  * JUnit based test
22  *
23  * Created on March 25, 2003, 8:50 AM
24  */

25
26 package org.netbeans.modules.j2ee.sun.share;
27
28 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
29 import javax.enterprise.deploy.spi.factories.DeploymentFactory JavaDoc;
30 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException JavaDoc;
31 import java.io.*;
32 import javax.enterprise.deploy.spi.Target JavaDoc;
33 //import com.sun.enterprise.deployapi.SunDeploymentPlan;
34
import javax.enterprise.deploy.spi.status.ProgressObject JavaDoc;
35 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
36 import junit.framework.*;
37
38 /**
39  *
40  * @author vkraemer
41  */

42 public class SunONEDeploymentFactoryTest extends TestCase implements Constants {
43     
44     public void testGetPortFromURI() {
45         assertEquals(-1,DF.getPortFromURI("anyother thing without a colon in it"));
46         assertEquals(12345, DF.getPortFromURI("deployer:Sun:S1AS::host:12345"));
47         assertEquals(-1,DF.getPortFromURI("anyother thing with a : in it"));
48         assertEquals(-1,DF.getPortFromURI("deployer:Sun:S1AS::host:12345:"));
49     }
50     
51     public void testGetHost() {
52         assertEquals("host", DF.getHostFromURI("deployer:Sun:S1AS::host:12345"));
53         assertEquals("host", DF.getHostFromURI("host:12345"));
54         assertEquals(null, DF.getHostFromURI("host12345"));
55     }
56         
57     public void testTomcatUriIssues() {
58         if (DF.handlesURI("tomcat:home=jakarta-tomcat-5.0.5:base=jakarta-tomcat-5.0.5_base:http://localhost:8080/manager/"))
59             fail("tomcat uri accepted");
60     }
61     
62     public SunONEDeploymentFactoryTest(java.lang.String JavaDoc testName) {
63         super(testName);
64     }
65         
66     public static SunDeploymentFactory DF =
67         new SunDeploymentFactory();
68     
69     
70     /** Test of getDeploymentManager method, of class org.netbeans.modules.j2ee.sun.share.SunONEDeploymentFactory. */
71     public void testGetDeploymentManager() {
72 // System.out.println("testGetDeploymentManager");
73
DeploymentManager JavaDoc c;
74         jsr88Logger.config("level is "+jsr88Logger.getLevel());
75         jsr88Logger.entering("","level is "+jsr88Logger.getLevel());
76         jsr88Logger.exiting("","level is "+jsr88Logger.getLevel());
77         jsr88Logger.fine("level is "+jsr88Logger.getLevel());
78         jsr88Logger.finer("level is "+jsr88Logger.getLevel());
79         jsr88Logger.finest("level is "+jsr88Logger.getLevel());
80         jsr88Logger.info("level is "+jsr88Logger.getLevel());
81         jsr88Logger.severe("level is "+jsr88Logger.getLevel());
82         jsr88Logger.throwing("","level is "+jsr88Logger.getLevel(),new RuntimeException JavaDoc("ABC"));
83         jsr88Logger.warning("level is "+jsr88Logger.getLevel());
84         try {
85             String JavaDoc bogusuri = "a:foo:bar::plink:fudge";
86             String JavaDoc validuri = "deployer:Sun:S1AS::localhost:4848";
87             String JavaDoc adminName = "admin";
88             String JavaDoc adminPassword = "admin321";
89             c = DF.getDeploymentManager(validuri, adminName, adminPassword);
90             //assert
91
assertNotNull("valid case failed",c);
92             try {
93                 c = DF.getDeploymentManager(bogusuri, "a", "a");
94                 fail("negative case failed");
95             }
96             catch (DeploymentManagerCreationException JavaDoc dmce) {
97                 assertEquals("invalid URI",
98                     dmce.getMessage());
99             }
100         }
101         catch (junit.framework.AssertionFailedError afe) {
102             throw afe;
103         }
104         catch (Throwable JavaDoc t) {
105             t.printStackTrace();
106             fail("unexpected exception");
107         }
108     }
109     
110     /** Test of getDisconnectedDeploymentManager method, of class org.netbeans.modules.j2ee.sun.share.SunONEDeploymentFactory. */
111     public void testGetDisconnectedDeploymentManager() {
112         System.out.println("testGetDisconnectedDeploymentManager");
113         
114         DeploymentManager JavaDoc c;
115         try {
116             String JavaDoc bogusuri = "a:foo:bar::plink:fudge";
117             String JavaDoc validuri = "deployer:Sun:S1AS::localhost:4848";
118             String JavaDoc adminName = "admin";
119             String JavaDoc adminPassword = "admin321";
120             c = DF.getDisconnectedDeploymentManager(validuri);
121             assertNotNull("valid case failed",c);
122             try {
123                 c = DF.getDisconnectedDeploymentManager(bogusuri);
124                 fail("negative case failed");
125             }
126             catch (DeploymentManagerCreationException JavaDoc dmce) {
127                 assertEquals("invalid URI",
128                     dmce.getMessage());
129             }
130         }
131         catch (junit.framework.AssertionFailedError afe) {
132             throw afe;
133         }
134         catch (Throwable JavaDoc t) {
135             t.printStackTrace();
136             fail("unexpected exception");
137         }
138     }
139     
140     /** Test of handlesURI method, of class org.netbeans.modules.j2ee.sun.share.SunONEDeploymentFactory. */
141     public void testHandlesDisconnectedURI() {
142         //System.out.println("testHandlesURI");
143

144         // Add your test code below by replacing the default call to fail.
145
//fail("The test case is empty.");
146
//try {
147
if (!DF.handlesURI("deployer:Sun:S1AS"))
148                 fail("disconnected URI is not accepted");
149     }
150     public void testHandlesCompleteURI() {
151             if (!DF.handlesURI("deployer:Sun:S1AS::localhost:4848"))
152                 fail("complete URI is not accpeted");
153     }
154     public void testHandlesIPURI() {
155             if (!DF.handlesURI("deployer:Sun:S1AS::127.0.0.1:4848"))
156                 fail("IP address not accepted");
157     }
158             
159     public void testHandleMisspelledURI() {
160              if (DF.handlesURI("deployerr:Sun:S1AS"))
161                 fail("misspelled URI accepted");
162     }
163             
164     public void testHandleIllegalThirdSepURI() {
165             if (!DF.handlesURI("deployer:Sun:S1AS:localhost:4848"))
166                 fail("illegal host sep ':' not accepted");
167     }
168     public void testHandleIllegalFirstSepURI() {
169             if (DF.handlesURI("deployer@Sun:S1AS::localhost:4848"))
170                 fail("illegal first sep '@' accepted");
171     }
172     public void testHandleIllegalSecondSepURI() {
173             if (DF.handlesURI("deployer:Sun@S1AS::localhost:4848"))
174                 fail("illegal second sep '@' accepted");
175     }
176             
177     /*public void testHandleEmptyHostAndPortURI() {
178             if (DF.handlesURI("deployer:Sun:S1AS:::"))
179                 fail("empty host and port accepted");
180     }*/

181             /*
182             if (DF.handlesURI("deployer:Sun:S1AS@localhost:4848"))
183                 fail("illegal host sep '@' accepted");
184              
185             if (DF.handlesURI("deployer:Sun:S1AS:::4848"))
186                 fail("empty host value accepted");
187              
188             if (DF.handlesURI("deployer:Sun:S1AS::127.0.0.280:4848"))
189                 fail("illegal IP address accepted");
190              
191             if (DF.handlesURI("deployer:Sun:S1AS::localhost:1234567890"))
192                 fail("illegal port accpted");
193              *
194             if (DF.handlesURI("deployer:Sun:S1AS::illegal host name:4848"))
195                 fail("invalid host name accepted");
196              */

197         /*}
198         catch (junit.framework.AssertionFailedError afe) {
199             throw afe;
200         }
201         catch (Throwable t) {
202             t.printStackTrace();
203             fail("positive test throws exception");
204         }*/

205     //}
206

207     /** Test of getDisplayName method, of class org.netbeans.modules.j2ee.sun.share.SunONEDeploymentFactory. */
208     public void testGetDisplayName() {
209         System.out.println("testGetDisplayName");
210         String JavaDoc dn = DF.getDisplayName();
211         System.out.println("dn = "+dn);
212         assertNotNull("the dn is null",dn);
213         assertEquals("empty dn", dn.length() > 0, true);
214     }
215     
216     /** Test of getProductVersion method, of class org.netbeans.modules.j2ee.sun.share.SunONEDeploymentFactory. */
217     public void testGetProductVersion() {
218         System.out.println("testGetProductVersion");
219         String JavaDoc pv = DF.getProductVersion();
220         System.out.println("pv = "+pv);
221         assertNotNull("the pv is null",pv);
222         assertEquals("empty pv", pv.length() > 0, true);
223     }
224     
225 }
226
Popular Tags