KickJava   Java API By Example, From Geeks To Geeks.

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


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 ExportCommandTest extends TestCase {
57
58     public void testrunCommandRemoveEnvVariables() throws Exception JavaDoc{
59         Vector JavaDoc operands = new Vector JavaDoc();
60         final String JavaDoc enc = "ISO-8859-1";
61         final File JavaDoc f = new File JavaDoc(System.getProperty("java.io.tmpdir"),
62                                 testCommand.ASADMINPREFS);
63         f.deleteOnExit();
64         final PrintWriter JavaDoc pw = new PrintWriter JavaDoc (
65                 new OutputStreamWriter JavaDoc(new FileOutputStream JavaDoc(f), enc));
66         pw.println("AS_ADMIN_USER=test_user");
67         pw.println("AS_ADMIN_PASSWORD=test_password");
68         pw.close();
69         System.setProperty("user.home", System.getProperty("java.io.tmpdir"));
70         operands.add("AS_ADMIN_USER=");
71         operands.add("AS_ADMIN_PASSWORD=");
72         testCommand.setOperands(operands);
73         testCommand.runCommand();
74         assertEquals(testCommand.getOption("user"), null);
75         assertEquals(testCommand.getOption("password"), null);
76     }
77
78     public void testrunCommandRemoveNonExistingEnvVariable() throws Exception JavaDoc{
79         try{
80             Vector JavaDoc operands = new Vector JavaDoc();
81             operands.add("AS_ADMIN_INTERACTIVE=");
82             testCommand.setOperands(operands);
83             testCommand.runCommand();
84         }catch(CommandException ce){
85             assertEquals(ce.getMessage(), "CLI149 Unable to remove environment variable, " +
86                     "AS_ADMIN_INTERACTIVE=.");
87         }
88     }
89
90     public void testrunCommandInvalidPrefix() throws Exception JavaDoc{
91         try{
92             Vector JavaDoc operands = new Vector JavaDoc();
93             operands.add("_ADMIN_INTERACTIVE=true");
94             testCommand.setOperands(operands);
95             testCommand.runCommand();
96         }catch(CommandException ce){
97             assertEquals(ce.getMessage(), "CLI148 Could not set environment variable, _ADMIN_INTERACTIVE.");
98         }
99     }
100 /*
101     //problem in removing the options user and password
102     public void testrunCommandPrintWhenNoEnvVariables() throws Exception{
103         //remove the options if read from .asadminprefs
104         Vector operands = new Vector();
105         final String enc = "ISO-8859-1";
106         final File f = new File(System.getProperty("java.io.tmpdir"),
107                                 testCommand.ASADMINPREFS);
108         f.deleteOnExit();
109         final PrintWriter pw = new PrintWriter (
110                 new OutputStreamWriter(new FileOutputStream(f), enc));
111         pw.println("AS_ADMIN_USER=test_user");
112         pw.println("AS_ADMIN_PASSWORD=test_password");
113         pw.close();
114         System.setProperty("user.home", System.getProperty("java.io.tmpdir"));
115         System.out.println(testCommand.getPassword() + " "+ testCommand.getUser());
116         operands.add("AS_ADMIN_USER=");
117         operands.add("AS_ADMIN_PASSWORD=");
118         testCommand.setOperands(operands);
119         testCommand.runCommand();
120         //end of removal
121         //print env variables
122         testCommand.setOperands(new Vector());
123     }
124 */

125     public ExportCommandTest(String JavaDoc name){
126         super(name);
127     }
128
129     ExportCommand testCommand = null;
130
131     protected void setUp() throws Exception JavaDoc{
132         //Properties systemProperties = new java.util.Propertis();
133
//systemProperties.put("com.sun.aas.configRoot",)
134
//String configProperty = SystemPropertyConstants.CONFIG_ROOT_PROPERTY;
135
//System.out.println(configProperty + " = " + System.getProperty(configProperty));
136
final CLIDescriptorsReader cliDescriptorsReader = CLIDescriptorsReader.getInstance();
137         ValidCommand validCommand = cliDescriptorsReader.getCommand(null);
138         LocalStringsManagerFactory.setCommandLocalStringsManagerProperties(
139             CLIDescriptorsReader.getInstance().getProperties());
140         testCommand = new ExportCommand();
141         testCommand.setName("sampleCommand");
142     }
143   
144   
145
146     protected void tearDown() {
147     }
148
149     private void nyi(){
150         fail("Not Yet Implemented");
151     }
152
153     public static Test suite(){
154         TestSuite suite = new TestSuite(ExportCommandTest.class);
155         return suite;
156     }
157
158     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
159         final TestRunner runner= new TestRunner();
160         final TestResult result = runner.doRun(ExportCommandTest.suite(), false);
161         System.exit(result.errorCount() + result.failureCount());
162     }
163 }
164
165
Popular Tags