001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)TestRegistryDocument.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.management.registry.xml;
030:
031: import com.sun.jbi.management.ComponentInfo;
032: import com.sun.jbi.management.ConfigurationCategory;
033: import com.sun.jbi.management.system.Util;
034: import com.sun.jbi.management.registry.RegistryBuilder;
035:
036: import javax.xml.parsers.DocumentBuilder;
037: import javax.xml.parsers.DocumentBuilderFactory;
038: import java.io.File;
039: import org.w3c.dom.Document;
040:
041: public class TestRegistryDocument extends junit.framework.TestCase {
042: /**
043: * The sample Configuration Directory.
044: */
045: private String mConfigDir = null;
046: private File mRegFile;
047: private Document mRegistryDocument;
048:
049: String mRegFilePath;
050: String mRegGoodFilePath;
051:
052: public TestRegistryDocument(String aTestName) {
053: super (aTestName);
054:
055: String srcroot = System.getProperty("junit.srcroot");
056: String manage = "/runtime/manage"; // open-esb build
057: mConfigDir = srcroot + manage + "/bld/test-classes/testdata/";
058:
059: java.io.File f = new java.io.File(srcroot + manage);
060: if (!f.exists()) {
061: manage = "/shasta/manage"; // mainline/whitney build
062: mConfigDir = srcroot + manage + "/bld/regress/testdata/";
063: }
064:
065: mRegFilePath = mConfigDir + File.separator + "jbi-registry.xml";
066: mRegGoodFilePath = mConfigDir + File.separator
067: + "jbi-registry-good.xml";
068:
069: mRegFile = new File(mRegFilePath);
070:
071: }
072:
073: public void setUp() throws Exception {
074: super .setUp();
075:
076: Util.fileCopy(mRegGoodFilePath, mRegFilePath);
077:
078: if (mRegFile.canRead()) {
079: DocumentBuilderFactory dbf = DocumentBuilderFactory
080: .newInstance();
081: DocumentBuilder db = dbf.newDocumentBuilder();
082: mRegistryDocument = db.parse(mRegFile);
083: }
084: }
085:
086: public void tearDown() throws Exception {
087:
088: }
089:
090: /**
091: * Test getting a configuration attribute value
092: */
093: public void testGetConfigurationAttribute() throws Exception {
094: RegistryDocument regDoc = new RegistryDocument(
095: mRegistryDocument);
096:
097: String value = regDoc.getConfigurationAttribute("domain",
098: ConfigurationCategory.Installation, "componentTimeout");
099: assertEquals("5000", value);
100: }
101:
102: /**
103: * Test getting a configuration attribute value
104: */
105: public void testGetOverridenConfigurationAttribute()
106: throws Exception {
107: RegistryDocument regDoc = new RegistryDocument(
108: mRegistryDocument);
109:
110: String value = regDoc.getConfigurationAttribute("clusterA",
111: ConfigurationCategory.Installation, "componentTimeout");
112: assertEquals("4000", value);
113: }
114:
115: /**
116: * Test getting all the attributes in a category
117: */
118: public void testGetConfigurationAttributes() throws Exception {
119: RegistryDocument regDoc = new RegistryDocument(
120: mRegistryDocument);
121:
122: java.util.Map<String, String> values = regDoc
123: .getConfigurationAttributes("domain",
124: ConfigurationCategory.Deployment);
125: assertTrue(values.get("startOnDeploy").equals("true"));
126: assertTrue(values.get("serviceUnitTimeout").equals("5000"));
127: assertTrue(values.get("deploymentTimeout").equals("6000"));
128: }
129:
130: /**
131: * Test getting all the attributes in a category for a target, which has some
132: * overrides
133: */
134: public void testGetOverridenConfigurationAttributes()
135: throws Exception {
136: RegistryDocument regDoc = new RegistryDocument(
137: mRegistryDocument);
138:
139: java.util.Map<String, String> values = regDoc
140: .getConfigurationAttributes("clusterA",
141: ConfigurationCategory.Deployment);
142:
143: assertTrue(values.get("startOnDeploy").equals("false"));
144: }
145:
146: /**
147: * Test getting a missing configuration attribute.
148: */
149: public void testGetMissingConfigurationAttribute() throws Exception {
150: RegistryDocument regDoc = new RegistryDocument(
151: mRegistryDocument);
152:
153: String value = regDoc.getConfigurationAttribute("domain",
154: ConfigurationCategory.Installation, "xyz");
155: assertNull(value);
156: }
157:
158: /**
159: * Test getting component configuration attributes.
160: */
161: public void testGetComponentConfigurationAttributes() {
162: RegistryDocument regDoc = new RegistryDocument(
163: mRegistryDocument);
164:
165: java.util.Properties props = regDoc
166: .getComponentConfigurationAttributes("server", true,
167: "SunSequencingEngine");
168: assertNotNull(props);
169: assertEquals(props.get("HostName"), "tango");
170: assertEquals(props.get("Port"), "5656");
171: }
172:
173: /**
174: * Test getting component application variables.
175: */
176: public void testGetComponentApplicationVariables() {
177: RegistryDocument regDoc = new RegistryDocument(
178: mRegistryDocument);
179:
180: ComponentInfo.Variable[] vars = regDoc
181: .getComponentApplicationVariables("server", true,
182: "SunSequencingEngine");
183: assertNotNull(vars);
184: assertEquals(2, vars.length);
185: ComponentInfo.Variable var = vars[0];
186:
187: assertEquals(var.getName(), "name");
188: assertEquals(var.getValue(), "Gill Bates");
189: assertEquals(var.getType(), "STRING");
190: }
191:
192: /**
193: * Test getting component application configuration.
194: */
195: public void testGetComponentApplicationConfiguration() {
196: RegistryDocument regDoc = new RegistryDocument(
197: mRegistryDocument);
198:
199: java.util.Map<String, java.util.Properties> configMap = regDoc
200: .getComponentApplicationConfiguration("server", true,
201: "SunSequencingEngine");
202: assertTrue(configMap.containsKey("SEQ_CONFIG1"));
203: assertTrue(configMap.containsKey("SEQ_CONFIG2"));
204:
205: // -- Test whether the property values are read correctly
206: java.util.Properties config1 = configMap.get("SEQ_CONFIG1");
207: assertTrue(config1.getProperty("configurationName").equals(
208: "SEQ_CONFIG1"));
209: assertTrue(config1.getProperty("initialContextFactory").equals(
210: "com.sonicsw.jndi.mfcontext.MFContextFactory"));
211: assertTrue(config1.getProperty("connectionURL").equals(
212: "jndi://cfg1"));
213:
214: java.util.Properties config2 = configMap.get("SEQ_CONFIG2");
215: assertTrue(config2.getProperty("configurationName").equals(
216: "SEQ_CONFIG2"));
217: assertTrue(config2.getProperty("initialContextFactory").equals(
218: "com.sonicsw.jndi.mfcontext.MFContextFactory"));
219: assertTrue(config2.getProperty("connectionURL").equals(
220: "jndi://cfg2"));
221: }
222:
223: }
|