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 com.sun.enterprise.util.SystemPropertyConstants; 40 import com.sun.enterprise.admin.servermgmt.DomainConfig; 41 import com.sun.enterprise.admin.servermgmt.pe.PEFileLayout; 42 import com.sun.enterprise.config.serverbeans.ServerTags; 43 44 import java.io.File ; 45 import java.io.PrintWriter ; 46 import java.io.OutputStreamWriter ; 47 import java.io.FileOutputStream ; 48 import java.util.Vector ; 49 import java.util.Map ; 50 51 56 57 62 63 public class CreateServiceCommandTest extends TestCase { 64 65 public CreateServiceCommandTest(String name){ 66 super(name); 67 } 68 69 public void testValidateOptionsWithInvalidPasswordFile() throws Exception { 70 try{ 71 Vector operands = new Vector (); 72 operands.add("typeDir"); 73 testCommand.setOperands(operands); 74 testCommand.setOption(testCommand.PASSWORDFILE, "FileDoesNotExist"); 75 testCommand.validateOptions(); 76 }catch (CommandValidationException cve){ 77 assertEquals(cve.getMessage(), "CLI146 FileDoesNotExist does not exist in the file system or read permission denied."); 78 } 79 } 80 81 public void testValidateOptionsWithInvalidTypeDir() throws Exception { 82 try{ 83 final File f = File.createTempFile("testValidateOptionsWithInvalidTypeDir", ".password"); 84 f.deleteOnExit(); 85 testCommand.setOption(testCommand.PASSWORDFILE, f.getAbsolutePath()); 86 Vector operands = new Vector (); 87 operands.add("typeDir"); 88 testCommand.setOperands(operands); 89 testCommand.validateOptions(); 90 }catch (CommandValidationException cve){ 91 assertEquals(cve.getMessage(), 92 "CLI153 typeDir does not exist or does not have write permission"); 93 } 94 } 95 96 public void testValidateOptionsWithInvalidServiceType() throws Exception { 97 try{ 98 final File f = File.createTempFile("testValidateOptionsWithInvalidServiceType", ".password"); 99 f.deleteOnExit(); 100 testCommand.setOption(testCommand.PASSWORDFILE, f.getAbsolutePath()); 101 final File dir = new File ("testValidateOptionsWithInvalidServiceTypeDir"); 102 dir.mkdir(); 103 dir.deleteOnExit(); 104 Vector operands = new Vector (); 105 operands.add(dir.getAbsolutePath()); 106 testCommand.setOperands(operands); 107 testCommand.setOption("type", "invalidType"); 108 testCommand.validateOptions(); 109 }catch (CommandValidationException cve){ 110 assertEquals(cve.getMessage(), 111 "CLI185 Invalid type specified. --type should be das or node-agent"); 112 } 113 } 114 115 public void testValidateOptionsWithValidOptions() throws Exception { 116 final File f = File.createTempFile("testValidateOptionsWithInvalidServiceType", ".password"); 117 f.deleteOnExit(); 118 testCommand.setOption(testCommand.PASSWORDFILE, f.getAbsolutePath()); 119 final File dir = new File ("testValidateOptionsWithInvalidServiceTypeDir"); 120 dir.mkdir(); 121 dir.deleteOnExit(); 122 Vector operands = new Vector (); 123 operands.add(dir.getAbsolutePath()); 124 testCommand.setOperands(operands); 125 testCommand.setOption("type", "das"); 126 testCommand.validateOptions(); 127 } 128 CreateServiceCommand testCommand = null; 129 130 protected void setUp() throws Exception { 131 final CLIDescriptorsReader cliDescriptorsReader = CLIDescriptorsReader.getInstance(); 136 ValidCommand validCommand = cliDescriptorsReader.getCommand(null); 137 LocalStringsManagerFactory.setCommandLocalStringsManagerProperties( 138 CLIDescriptorsReader.getInstance().getProperties()); 139 testCommand = new CreateServiceCommand(); 140 testCommand.setName("sampleCommand"); 141 } 142 143 144 145 protected void tearDown() { 146 } 147 148 private void nyi(){ 149 fail("Not Yet Implemented"); 150 } 151 152 public static Test suite(){ 153 TestSuite suite = new TestSuite(BackupCommandsTest.class); 154 return suite; 155 } 156 157 public static void main(String args[]) throws Exception { 158 final TestRunner runner= new TestRunner(); 159 final TestResult result = runner.doRun(BaseLifeCycleCommandTest.suite(), false); 160 System.exit(result.errorCount() + result.failureCount()); 161 } 162 } 163 164 | Popular Tags |