KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > commands > VerifyDomainXmlCommandTest


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 package com.sun.enterprise.cli.commands;
24
25 /**
26    Note that this test requires resources for testing. These resources
27    are construct4ed from the two files P1 & P2 located in the current
28    directory. If these file names are changed then the corresponding
29    names in this submodules build.xml file should be changed also
30 */

31 import com.sun.enterprise.cli.framework.*;
32 //import java.util.ArrayList;
33
//import java.util.Arrays;
34
//import java.util.HashMap;
35
//import java.util.List;
36
//import java.util.Properties;
37
import junit.framework.*;
38 import junit.textui.TestRunner;
39 import java.util.Vector JavaDoc;
40 import java.io.File JavaDoc;
41 import java.io.PrintWriter JavaDoc;
42 import java.io.OutputStreamWriter JavaDoc;
43 import java.io.FileOutputStream JavaDoc;
44 /**
45  *
46  * @author prashanth.abbagani@sun.com
47  * @version $Revision: 1.2 $
48  */

49
50 /**
51    Execute these tests using gmake (and Ant) by:
52    cd <commands>
53    gmake ANT_TARGETS=CommandTest.java
54 */

55
56 public class VerifyDomainXmlCommandTest extends TestCase {
57
58     public void testrunCommandWithNoDomainXMLFile() throws Exception JavaDoc{
59         try{
60             String JavaDoc domaindir = createDomainFileSystem("domains", "domain1", false);
61             testCommand.setOption("domaindir", domaindir);
62             Vector JavaDoc operands = new Vector JavaDoc();
63             operands.add("domain1");
64             testCommand.setOperands(operands);
65             testCommand.runCommand();
66         } catch (Exception JavaDoc e)
67         {
68             assertEquals(e.getMessage(), "CLI155 domain1 does not exist.");
69         }
70     }
71
72     public void testrunCommandWithEmptyDomainXMLFile() throws Exception JavaDoc{
73         String JavaDoc domaindir = "";
74         try{
75             domaindir = createDomainFileSystem("domains", "domain1", true);
76             testCommand.setOption("domaindir", domaindir);
77             Vector JavaDoc operands = new Vector JavaDoc();
78             operands.add("domain1");
79             testCommand.setOperands(operands);
80             testCommand.runCommand();
81         } catch (Exception JavaDoc e)
82         {
83             assertEquals(e.getMessage(), "Error refreshing ConfigContext:" +
84                 domaindir + File.separator + "domain1" + File.separator +
85                 "config" + File.separator + "domain.xml" +
86                 "\ncause: Failed to create the XML-DOM Document. Check your XML to make sure it is correct.\nPremature end of file.");
87         }
88     }
89
90     private String JavaDoc createDomainFileSystem(String JavaDoc domainParent, String JavaDoc domainName,
91                                     boolean createDomainXML) throws Exception JavaDoc{
92         final File JavaDoc domainParentDir = new File JavaDoc(System.getProperty("java.io.tmpdir"), domainParent);
93         domainParentDir.mkdir();
94         domainParentDir.deleteOnExit();
95         final File JavaDoc domainDir = new File JavaDoc(domainParentDir, domainName);
96         domainDir.mkdir();
97         domainDir.deleteOnExit();
98         if (!createDomainXML) return domainParentDir.getPath();
99         final File JavaDoc configDir = new File JavaDoc(domainDir, "config");
100         configDir.mkdir();
101         configDir.deleteOnExit();
102         final File JavaDoc f = new File JavaDoc(configDir, "domain.xml");
103         f.createNewFile();
104         f.deleteOnExit();
105         return domainParentDir.getPath();
106     }
107
108     public VerifyDomainXmlCommandTest(String JavaDoc name){
109         super(name);
110     }
111
112     VerifyDomainXmlCommand testCommand = null;
113
114     protected void setUp() throws Exception JavaDoc{
115         //Properties systemProperties = new java.util.Propertis();
116
//systemProperties.put("com.sun.aas.configRoot",)
117
//String configProperty = SystemPropertyConstants.CONFIG_ROOT_PROPERTY;
118
//System.out.println(configProperty + " = " + System.getProperty(configProperty));
119
final CLIDescriptorsReader cliDescriptorsReader = CLIDescriptorsReader.getInstance();
120         ValidCommand validCommand = cliDescriptorsReader.getCommand(null);
121         LocalStringsManagerFactory.setCommandLocalStringsManagerProperties(
122             CLIDescriptorsReader.getInstance().getProperties());
123         testCommand = new VerifyDomainXmlCommand();
124         testCommand.setName("sampleCommand");
125     }
126   
127   
128
129     protected void tearDown() {
130     }
131
132     private void nyi(){
133         fail("Not Yet Implemented");
134     }
135
136     public static Test suite(){
137         TestSuite suite = new TestSuite(VerifyDomainXmlCommandTest.class);
138         return suite;
139     }
140
141     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
142         final TestRunner runner= new TestRunner();
143         final TestResult result = runner.doRun(VerifyDomainXmlCommandTest.suite(), false);
144         System.exit(result.errorCount() + result.failureCount());
145     }
146 }
147
148
Popular Tags