KickJava   Java API By Example, From Geeks To Geeks.

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


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 CreateMBeanCommandTest extends TestCase {
64     
65     public CreateMBeanCommandTest(String JavaDoc name){
66         super(name);
67     }
68     
69     public void testgetParamsInfoWithInvalidAttrs() throws Exception JavaDoc{
70         //testCommand.setOption(testCommand.TARGET_OPTION, "server");
71
//testCommand.setOption(testCommand.NAME_OPTION, "name");
72
//testCommand.setOption(testCommand.OBJECT_NAME_OPTION, "objName1");
73
Vector JavaDoc operands = new Vector JavaDoc();
74         operands.add("impl1");
75         testCommand.setOperands(operands);
76         testCommand.setOption("attributes", "attr1=value1attr2=value2");
77         try{
78             Object JavaDoc[] params = testCommand.getParamsInfo();
79         }catch (CommandValidationException cve){
80             assertEquals(cve.getMessage(), "CLI178 Invalid attribute syntax.");
81         }
82         
83         
84     }
85     
86     public void testgetParamsInfo() throws Exception JavaDoc{
87         testCommand.setOption(testCommand.TARGET_OPTION, "server");
88         testCommand.setOption(testCommand.NAME_OPTION, "name");
89         testCommand.setOption(testCommand.OBJECT_NAME_OPTION, "objName1");
90         Vector JavaDoc operands = new Vector JavaDoc();
91         operands.add("impl1");
92         testCommand.setOperands(operands);
93         testCommand.setOption("attributes", "attr1=value1:attr2=value2");
94         Object JavaDoc[] params = testCommand.getParamsInfo();
95         Map JavaDoc mbeanParams = (Map JavaDoc) params[1];
96         Map JavaDoc attributesList = (Map JavaDoc) params[2];
97         assertEquals(params[0], "server");
98         assertEquals(mbeanParams.get(ServerTags.IMPL_CLASS_NAME), "impl1");
99         assertEquals(mbeanParams.get(ServerTags.OBJECT_NAME), "objName1");
100         assertEquals(mbeanParams.get(ServerTags.NAME), "name");
101         assertEquals(attributesList.get("attr1"), "value1");
102         assertEquals(attributesList.get("attr2"), "value2");
103     }
104     
105     CreateMBeanCommand testCommand = null;
106     
107     protected void setUp() throws Exception JavaDoc{
108         //Properties systemProperties = new java.util.Propertis();
109
//systemProperties.put("com.sun.aas.configRoot",)
110
//String configProperty = SystemPropertyConstants.CONFIG_ROOT_PROPERTY;
111
//System.out.println(configProperty + " = " + System.getProperty(configProperty));
112
final CLIDescriptorsReader cliDescriptorsReader = CLIDescriptorsReader.getInstance();
113         ValidCommand validCommand = cliDescriptorsReader.getCommand(null);
114         LocalStringsManagerFactory.setCommandLocalStringsManagerProperties(
115                 CLIDescriptorsReader.getInstance().getProperties());
116         testCommand = new CreateMBeanCommand();
117         testCommand.setName("sampleCommand");
118     }
119     
120     
121     
122     protected void tearDown() {
123     }
124     
125     private void nyi(){
126         fail("Not Yet Implemented");
127     }
128     
129     public static Test suite(){
130         TestSuite suite = new TestSuite(BackupCommandsTest.class);
131         return suite;
132     }
133     
134     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
135         final TestRunner runner= new TestRunner();
136         final TestResult result = runner.doRun(BaseLifeCycleCommandTest.suite(), false);
137         System.exit(result.errorCount() + result.failureCount());
138     }
139 }
140
141
Popular Tags