KickJava   Java API By Example, From Geeks To Geeks.

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


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 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 JavaDoc;
45 import java.io.PrintWriter JavaDoc;
46 import java.io.OutputStreamWriter JavaDoc;
47 import java.io.FileOutputStream JavaDoc;
48 import java.util.Vector JavaDoc;
49 import java.util.Map JavaDoc;
50
51 /**
52  *
53  * @author prashanth.abbagani@sun.com
54  * @version $Revision: 1.2 $
55  */

56
57 /**
58  * Execute these tests using gmake (and Ant) by:
59  * cd <commands>
60  * gmake ANT_TARGETS=CommandTest.java
61  */

62
63 public class CreateServiceCommandTest extends TestCase {
64     
65     public CreateServiceCommandTest(String JavaDoc name){
66         super(name);
67     }
68     
69     public void testValidateOptionsWithInvalidPasswordFile() throws Exception JavaDoc{
70         try{
71             Vector JavaDoc operands = new Vector JavaDoc();
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 JavaDoc{
82         try{
83             final File JavaDoc f = File.createTempFile("testValidateOptionsWithInvalidTypeDir", ".password");
84             f.deleteOnExit();
85             testCommand.setOption(testCommand.PASSWORDFILE, f.getAbsolutePath());
86             Vector JavaDoc operands = new Vector JavaDoc();
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 JavaDoc{
97         try{
98             final File JavaDoc f = File.createTempFile("testValidateOptionsWithInvalidServiceType", ".password");
99             f.deleteOnExit();
100             testCommand.setOption(testCommand.PASSWORDFILE, f.getAbsolutePath());
101             final File JavaDoc dir = new File JavaDoc("testValidateOptionsWithInvalidServiceTypeDir");
102             dir.mkdir();
103             dir.deleteOnExit();
104             Vector JavaDoc operands = new Vector JavaDoc();
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 JavaDoc{
116         final File JavaDoc f = File.createTempFile("testValidateOptionsWithInvalidServiceType", ".password");
117         f.deleteOnExit();
118         testCommand.setOption(testCommand.PASSWORDFILE, f.getAbsolutePath());
119         final File JavaDoc dir = new File JavaDoc("testValidateOptionsWithInvalidServiceTypeDir");
120         dir.mkdir();
121         dir.deleteOnExit();
122         Vector JavaDoc operands = new Vector JavaDoc();
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 JavaDoc{
131         //Properties systemProperties = new java.util.Propertis();
132
//systemProperties.put("com.sun.aas.configRoot",)
133
//String configProperty = SystemPropertyConstants.CONFIG_ROOT_PROPERTY;
134
//System.out.println(configProperty + " = " + System.getProperty(configProperty));
135
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 JavaDoc args[]) throws Exception JavaDoc {
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