KickJava   Java API By Example, From Geeks To Geeks.

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


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 UnsetCommandTest extends TestCase {
57
58     public void testrunCommandRemoveEnvVariables() throws Exception JavaDoc{
59         Vector JavaDoc operands = new Vector JavaDoc();
60         System.setProperty("user.home", System.getProperty("java.io.tmpdir"));//tempDir.getPath());
61
operands.add("AS_ADMIN_USER");
62         operands.add("AS_ADMIN_PASSWORD");
63         testCommand.setOperands(operands);
64         CommandEnvironment.getInstance().setEnvironment("user", "admin");
65         CommandEnvironment.getInstance().setEnvironment("password", "adminadmin");
66         testCommand.runCommand();
67         assertEquals(testCommand.getOption("user"), null);
68         assertEquals(testCommand.getOption("password"), null);
69     }
70
71     public void testrunCommandRemoveEnvVariablesWithWildCard() throws Exception JavaDoc{
72         Vector JavaDoc operands = new Vector JavaDoc();
73         System.setProperty("user.home", System.getProperty("java.io.tmpdir"));
74         operands.add("AS_ADMIN_*");
75         testCommand.setOperands(operands);
76         CommandEnvironment.getInstance().setEnvironment("user", "admin");
77         CommandEnvironment.getInstance().setEnvironment("password", "adminadmin");
78         testCommand.runCommand();
79         assertEquals(testCommand.getOption("user"), null);
80         assertEquals(testCommand.getOption("password"), null);
81     }
82
83     public void testrunCommandRemoveNonExistingEnvVariable() throws Exception JavaDoc{
84         try{
85             Vector JavaDoc operands = new Vector JavaDoc();
86             operands.add("AS_ADMIN_INTERACTIVE");
87             testCommand.setOperands(operands);
88             testCommand.runCommand();
89         }catch(CommandException ce){
90             assertEquals(ce.getMessage(), "CLI149 Unable to remove environment variable, " +
91                     "AS_ADMIN_INTERACTIVE.");
92         }
93     }
94
95     public void testrunCommandInvalidPrefix() throws Exception JavaDoc{
96         try{
97             Vector JavaDoc operands = new Vector JavaDoc();
98             operands.add("_ADMIN_INTERACTIVE");
99             testCommand.setOperands(operands);
100             testCommand.runCommand();
101         }catch(CommandException ce){
102             assertEquals(ce.getMessage(), "CLI163 Could not unset environment variable, _ADMIN_INTERACTIVE.");
103         }
104     }
105
106     public UnsetCommandTest(String JavaDoc name){
107         super(name);
108     }
109
110     UnsetCommand testCommand = null;
111
112     protected void setUp() throws Exception JavaDoc{
113         //Properties systemProperties = new java.util.Propertis();
114
//systemProperties.put("com.sun.aas.configRoot",)
115
//String configProperty = SystemPropertyConstants.CONFIG_ROOT_PROPERTY;
116
//System.out.println(configProperty + " = " + System.getProperty(configProperty));
117
final CLIDescriptorsReader cliDescriptorsReader = CLIDescriptorsReader.getInstance();
118         ValidCommand validCommand = cliDescriptorsReader.getCommand(null);
119         LocalStringsManagerFactory.setCommandLocalStringsManagerProperties(
120             CLIDescriptorsReader.getInstance().getProperties());
121         testCommand = new UnsetCommand();
122         testCommand.setName("sampleCommand");
123     }
124   
125   
126
127     protected void tearDown() {
128     }
129
130     private void nyi(){
131         fail("Not Yet Implemented");
132     }
133
134     public static Test suite(){
135         TestSuite suite = new TestSuite(UnsetCommandTest.class);
136         return suite;
137     }
138
139     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
140         final TestRunner runner= new TestRunner();
141         final TestResult result = runner.doRun(UnsetCommandTest.suite(), false);
142         System.exit(result.errorCount() + result.failureCount());
143     }
144 }
145
146
Popular Tags