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 VerifyDomainXmlCommandTest extends TestCase { 57 58 public void testrunCommandWithNoDomainXMLFile() throws Exception { 59 try{ 60 String domaindir = createDomainFileSystem("domains", "domain1", false); 61 testCommand.setOption("domaindir", domaindir); 62 Vector operands = new Vector (); 63 operands.add("domain1"); 64 testCommand.setOperands(operands); 65 testCommand.runCommand(); 66 } catch (Exception e) 67 { 68 assertEquals(e.getMessage(), "CLI155 domain1 does not exist."); 69 } 70 } 71 72 public void testrunCommandWithEmptyDomainXMLFile() throws Exception { 73 String domaindir = ""; 74 try{ 75 domaindir = createDomainFileSystem("domains", "domain1", true); 76 testCommand.setOption("domaindir", domaindir); 77 Vector operands = new Vector (); 78 operands.add("domain1"); 79 testCommand.setOperands(operands); 80 testCommand.runCommand(); 81 } catch (Exception e) 82 { 83 assertEquals(e.getMessage(), "Error refreshing ConfigContext:" + 84 domaindir + File.separator + "domain1" + File.separator + 85 "config" + File.separator + "domain.xml" + 86 "\ncause: Failed to create the XML-DOM Document. Check your XML to make sure it is correct.\nPremature end of file."); 87 } 88 } 89 90 private String createDomainFileSystem(String domainParent, String domainName, 91 boolean createDomainXML) throws Exception { 92 final File domainParentDir = new File (System.getProperty("java.io.tmpdir"), domainParent); 93 domainParentDir.mkdir(); 94 domainParentDir.deleteOnExit(); 95 final File domainDir = new File (domainParentDir, domainName); 96 domainDir.mkdir(); 97 domainDir.deleteOnExit(); 98 if (!createDomainXML) return domainParentDir.getPath(); 99 final File configDir = new File (domainDir, "config"); 100 configDir.mkdir(); 101 configDir.deleteOnExit(); 102 final File f = new File (configDir, "domain.xml"); 103 f.createNewFile(); 104 f.deleteOnExit(); 105 return domainParentDir.getPath(); 106 } 107 108 public VerifyDomainXmlCommandTest(String name){ 109 super(name); 110 } 111 112 VerifyDomainXmlCommand testCommand = null; 113 114 protected void setUp() throws Exception { 115 final CLIDescriptorsReader cliDescriptorsReader = CLIDescriptorsReader.getInstance(); 120 ValidCommand validCommand = cliDescriptorsReader.getCommand(null); 121 LocalStringsManagerFactory.setCommandLocalStringsManagerProperties( 122 CLIDescriptorsReader.getInstance().getProperties()); 123 testCommand = new VerifyDomainXmlCommand(); 124 testCommand.setName("sampleCommand"); 125 } 126 127 128 129 protected void tearDown() { 130 } 131 132 private void nyi(){ 133 fail("Not Yet Implemented"); 134 } 135 136 public static Test suite(){ 137 TestSuite suite = new TestSuite(VerifyDomainXmlCommandTest.class); 138 return suite; 139 } 140 141 public static void main(String args[]) throws Exception { 142 final TestRunner runner= new TestRunner(); 143 final TestResult result = runner.doRun(VerifyDomainXmlCommandTest.suite(), false); 144 System.exit(result.errorCount() + result.failureCount()); 145 } 146 } 147 148 | Popular Tags |