KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > servermgmt > pe > PEDomainConfigValidatorTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.admin.servermgmt.pe;
25
26 import junit.framework.*;
27 import java.util.HashMap JavaDoc;
28 import java.util.Map JavaDoc;
29 import com.sun.enterprise.admin.servermgmt.DomainConfig;
30 import java.util.Properties JavaDoc;
31 import com.sun.enterprise.admin.servermgmt.InvalidConfigException;
32 /**
33  *
34  * @author <a HREF="mailto:toby.h.ferguson@sun.com">Toby H Ferguson</a>
35  * @version $Revision: 1.3 $
36  */

37
38 public class PEDomainConfigValidatorTest extends TestCase {
39   public void testNumPorts(){
40     assertEquals(7, dc2.getPorts().size());
41   }
42   
43   public void testDuplicatesInDomainConfig() {
44     try {
45       p.uniquePorts(dc2);
46       fail("Expectged an InvalidConfigException indicating that there were duplicate ports");
47     }
48     catch (InvalidConfigException e){
49       assertEquals("Duplicate ports were found: 1 -> {domain.adminPort, domain.instancePort, http.ssl.port, jms.port}, 2 -> {orb.listener.port, orb.ssl.port}", e.getMessage());
50     }
51   }
52   
53   public void testNoDuplicatesInDomainConfig() throws Exception JavaDoc {
54     p.uniquePorts(dc1);
55   }
56   
57   public void testNoDuplicatePorts(){
58     final Map JavaDoc ports = new HashMap JavaDoc();
59     ports.put("a", "1");
60     assertEquals("", p.getDuplicatePorts(ports));
61   }
62   
63   public void testGetDuplicatePorts() {
64     final Map JavaDoc ports = new HashMap JavaDoc();
65     ports.put("a", "1");
66     ports.put("b", "1");
67     ports.put("c", "2");
68     ports.put("d", "2");
69     ports.put("e", "3");
70     assertEquals("1 -> {a, b}, 2 -> {c, d}", p.getDuplicatePorts(ports));
71   }
72
73   public PEDomainConfigValidatorTest(String JavaDoc name){
74     super(name);
75   }
76
77   PEDomainConfigValidator p;
78   DomainConfig dc1, dc2;
79   
80   protected void setUp() throws Exception JavaDoc {
81     p = new PEDomainConfigValidator();
82     dc1 = new DomainConfig("domainName",
83                           new Integer JavaDoc(1),
84                           "domainRoot",
85                           "adminUser",
86                           "adminPassword",
87                           "masterPassword",
88                           new Integer JavaDoc(2),
89                           "jmsUser",
90                           "jmsPassword",
91                           new Integer JavaDoc(3),
92                           new Integer JavaDoc(4),
93                           new Integer JavaDoc(5),
94                           new Integer JavaDoc(6),
95                           new Integer JavaDoc(7),
96                           new Properties JavaDoc()){
97         protected String JavaDoc getFilePath(String JavaDoc p){
98           return p;
99         }
100       };
101     dc2 = new DomainConfig("domainName",
102                           new Integer JavaDoc(1),
103                           "domainRoot",
104                           "adminUser",
105                           "adminPassword",
106                           new Integer JavaDoc(1),
107                           "jmsUser",
108                           "jmsPassword",
109                           new Integer JavaDoc(1),
110                           new Integer JavaDoc(2),
111                           new Integer JavaDoc(1),
112                           new Integer JavaDoc(2),
113                           new Integer JavaDoc(3),
114                           new Properties JavaDoc()){
115         protected String JavaDoc getFilePath(String JavaDoc p){
116           return p;
117         }
118       };
119   }
120   
121
122   protected void tearDown() {
123   }
124
125   private void nyi(){
126     fail("Not Yet Implemented");
127   }
128
129   public static void main(String JavaDoc args[]){
130     if (args.length == 0){
131       junit.textui.TestRunner.run(PEDomainConfigValidatorTest.class);
132     } else {
133       junit.textui.TestRunner.run(makeSuite(args));
134     }
135   }
136   private static TestSuite makeSuite(String JavaDoc args[]){
137     final TestSuite ts = new TestSuite();
138     for (int i = 0; i < args.length; i++){
139       ts.addTest(new PEDomainConfigValidatorTest(args[i]));
140     }
141     return ts;
142   }
143     
144 }
145
Popular Tags