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 UnsetCommandTest extends TestCase { 57 58 public void testrunCommandRemoveEnvVariables() throws Exception { 59 Vector operands = new Vector (); 60 System.setProperty("user.home", System.getProperty("java.io.tmpdir")); 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 { 72 Vector operands = new Vector (); 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 { 84 try{ 85 Vector operands = new Vector (); 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 { 96 try{ 97 Vector operands = new Vector (); 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 name){ 107 super(name); 108 } 109 110 UnsetCommand testCommand = null; 111 112 protected void setUp() throws Exception { 113 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 args[]) throws Exception { 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 |