1 23 package com.sun.enterprise.cli.commands; 24 25 31 import com.sun.enterprise.cli.framework.*; 32 import junit.framework.*; 38 import junit.textui.TestRunner; 39 import java.util.Vector ; 40 import java.io.File ; 41 import java.io.PrintWriter ; 42 import java.io.OutputStreamWriter ; 43 import java.io.FileOutputStream ; 44 49 50 55 56 public class ExportCommandTest extends TestCase { 57 58 public void testrunCommandRemoveEnvVariables() throws Exception { 59 Vector operands = new Vector (); 60 final String enc = "ISO-8859-1"; 61 final File f = new File (System.getProperty("java.io.tmpdir"), 62 testCommand.ASADMINPREFS); 63 f.deleteOnExit(); 64 final PrintWriter pw = new PrintWriter ( 65 new OutputStreamWriter (new FileOutputStream (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 { 79 try{ 80 Vector operands = new Vector (); 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 { 91 try{ 92 Vector operands = new Vector (); 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 125 public ExportCommandTest(String name){ 126 super(name); 127 } 128 129 ExportCommand testCommand = null; 130 131 protected void setUp() throws Exception { 132 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 args[]) throws Exception { 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 |