KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.util.SystemPropertyConstants;
40 import java.io.File JavaDoc;
41 /**
42  *
43  * @author prashanth.abbagani@sun.com
44  * @version $Revision: 1.2 $
45  */

46
47 /**
48    Execute these tests using gmake (and Ant) by:
49    cd <commands>
50    gmake ANT_TARGETS=CommandTest.java
51 */

52
53 public class BackupCommandsTest extends TestCase {
54
55     public void testValidateOptionsInvalidCommandName() throws Exception JavaDoc{
56         try{
57             testCommand.validateOptions();
58         }
59         catch (CommandValidationException cve){
60             assertEquals(cve.getMessage(),
61             "There is no such command sampleCommand. Use \"asadmin help\" for a list of valid commands.");
62         }
63     }
64
65     public void testValidateOptionsInvalidVerboseAndTerse() throws Exception JavaDoc{
66         try{
67             testCommand.setName("backup-domain");
68             testCommand.setOption("terse", "true");
69             testCommand.setOption("verbose", "true");
70             testCommand.validateOptions();
71         }
72         catch (CommandValidationException cve){
73             assertEquals(cve.getMessage(),
74             "The verbose and terse options can''t both be true at the same time.");
75         }
76     }
77
78     //check the error from isRunning()
79
public void testValidateOptionsInvalidDomainPath() throws Exception JavaDoc{
80         try{
81             testCommand.setName("backup-domain");
82             testCommand.setOption("domaindir", "InvalidDomainDir");
83             testCommand.validateOptions();
84         }
85         catch (CommandValidationException cve){
86             assertEquals(cve.getMessage(),
87             "com.sun.enterprise.cli.framework.CommandException: Domain directory "+
88             new File JavaDoc("InvalidDomainDir").getAbsolutePath() +" is not a directory or does not exist.");
89         }
90     }
91
92     public BackupCommandsTest(String JavaDoc name){
93         super(name);
94     }
95
96     BackupCommands testCommand = null;
97
98     protected void setUp() throws Exception JavaDoc{
99         //Properties systemProperties = new java.util.Propertis();
100
//systemProperties.put("com.sun.aas.configRoot",)
101
//String configProperty = SystemPropertyConstants.CONFIG_ROOT_PROPERTY;
102
//System.out.println(configProperty + " = " + System.getProperty(configProperty));
103
final CLIDescriptorsReader cliDescriptorsReader = CLIDescriptorsReader.getInstance();
104         ValidCommand validCommand = cliDescriptorsReader.getCommand(null);
105         LocalStringsManagerFactory.setCommandLocalStringsManagerProperties(
106             CLIDescriptorsReader.getInstance().getProperties());
107         testCommand = new BackupCommands();
108         testCommand.setName("sampleCommand");
109     }
110   
111   
112
113     protected void tearDown() {
114     }
115
116     private void nyi(){
117         fail("Not Yet Implemented");
118     }
119
120     public static Test suite(){
121         TestSuite suite = new TestSuite(BackupCommandsTest.class);
122         return suite;
123     }
124
125     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
126         final TestRunner runner= new TestRunner();
127         final TestResult result = runner.doRun(BackupCommandsTest.suite(), false);
128         System.exit(result.errorCount() + result.failureCount());
129     }
130 }
131
132
Popular Tags