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: * @(#)TestComponentConfigurationHelper.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.util;
030:
031: import java.util.Properties;
032: import javax.management.openmbean.TabularData;
033: import javax.management.openmbean.CompositeData;
034: import javax.management.openmbean.CompositeDataSupport;
035: import javax.management.openmbean.CompositeType;
036: import javax.management.openmbean.SimpleType;
037: import javax.management.openmbean.OpenType;
038: import javax.management.openmbean.ArrayType;
039:
040: import com.sun.jbi.EnvironmentContext;
041: import java.io.InputStream;
042: import java.io.StringBufferInputStream;
043: import org.w3c.dom.Document;
044: import javax.xml.parsers.DocumentBuilder;
045: import javax.xml.parsers.DocumentBuilderFactory;
046:
047: /**
048: * Tests for the ConfigurationHelper class.
049: *
050: * @author Sun Microsystems
051: */
052: public class TestComponentConfigurationHelper extends
053: junit.framework.TestCase {
054: private static final String CONFIG_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
055: + "<componentConfig:Configuration name=\"sun-http-binding\" "
056: + "xmlns:componentConfig=\"http://com.sun.jbi.component/schema/configuration\"> "
057: + "<componentConfig:OutboundThreads displayName=\"Number of outbound threads\" "
058: + "displayDescription=\"Number of threads to concurrently process outbound HTTP/SOAP requests\" "
059: + "isPasswordField=\"false\">10</componentConfig:OutboundThreads> "
060: +
061:
062: "<componentConfig:HttpDefaultPort displayName=\"Default HTTP port number\" "
063: + "displayDescription=\"Default HTTP port number for inbound HTTP/SOAP requests\" "
064: + "isPasswordField=\"false\">1111</componentConfig:HttpDefaultPort> "
065: +
066:
067: "<componentConfig:HttpsDefaultPort displayName=\"Default HTTPS port number\" "
068: + "displayDescription=\"Default HTTPS port number for inbound HTTP/SOAP requests\" "
069: + "isPasswordField=\"false\">2222</componentConfig:HttpsDefaultPort> "
070: +
071:
072: "<componentConfig:UseJVMProxySettings displayName=\"Use default JVM proxy settings\" "
073: + "displayDescription=\"Determines whether or not to use the default JVM system properties for proxy settings\" "
074: + "isPasswordField=\"false\">true</componentConfig:UseJVMProxySettings> "
075: +
076:
077: "<componentConfig:ProxyType displayName=\"Proxy type\" "
078: + "displayDescription=\"Specifies a valid proxy type\" "
079: + "isPasswordField=\"false\">SOCKS</componentConfig:ProxyType>"
080: +
081:
082: "<componentConfig:ProxyHost displayName=\"Proxy host\" "
083: + "displayDescription=\"Specifies a valid proxy host name\" "
084: + "isPasswordField=\"false\">dummy</componentConfig:ProxyHost>"
085: +
086:
087: "<componentConfig:ProxyPort displayName=\"Proxy port\" "
088: + "displayDescription=\"Specifies a valid proxy port\" "
089: + "isPasswordField=\"false\">3333</componentConfig:ProxyPort>"
090: +
091:
092: "<componentConfig:NonProxyHosts displayName=\"Non proxy hosts\" "
093: + "displayDescription=\"Specifies a list of server hosts whose connections do not require a proxy server.\" "
094: + "isPasswordField=\"false\">dummy</componentConfig:NonProxyHosts>"
095: +
096:
097: "<componentConfig:ProxyUserName displayName=\"Proxy user name\" "
098: + "displayDescription=\"Specifies a valid proxy user name\" "
099: + "isPasswordField=\"false\">dummy</componentConfig:ProxyUserName>"
100: +
101:
102: "<componentConfig:ProxyPassword displayName=\"Proxy user password\" "
103: + "displayDescription=\"Specifies a valid proxy user password.\" "
104: + "isPasswordField=\"true\">dummy</componentConfig:ProxyPassword>"
105: +
106:
107: "<componentConfig:ApplicationConfiguration>"
108: +
109:
110: "<componentConfig:configurationName displayName=\"Application Configuration Name\" "
111: + "displayDescription=\"Specifies the name of the application configuration.\" "
112: + "isPasswordField=\"false\" isRequiredField=\"true\">dummy</componentConfig:configurationName >"
113: +
114:
115: "<componentConfig:httpLocation displayName=\"HTTP URL Location\" "
116: + "displayDescription=\"Specifies the HTTP URL location.\" "
117: + "isPasswordField=\"false\" isRequiredField=\"true\">http://</componentConfig:httpLocation>"
118: +
119:
120: "<componentConfig:userPassword displayName=\"User Password\" "
121: + "displayDescription=\"Specifies the user password.\" "
122: + "isPasswordField=\"true\" isRequiredField=\"true\">secret</componentConfig:userPassword>"
123: +
124:
125: "</componentConfig:ApplicationConfiguration>"
126: + "</componentConfig:Configuration>";
127:
128: private static final String CONFIG_XML_NEW =
129:
130: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
131: +
132:
133: "<config:Configuration xmlns:config='http://www.sun.com/jbi/Configuration/V1.0'>"
134: +
135:
136: "<config:Property name=\"A\" "
137: + "type=\"xsd:string\" "
138: + "displayName=\"Property A\" "
139: + "displayDescription=\"A test string property A\" "
140: + "defaultValue=\"a\" "
141: + "isApplicationRestartRequired=\"false\" "
142: + "isComponentRestartRequired=\"false\" "
143: + "isServerRestartRequired=\"false\" "
144: + "showDisplay=\"all\" "
145: + "required=\"true\"/> "
146: +
147:
148: "<config:Property name=\"B\" "
149: + "type=\"xsd:string\" "
150: + "displayName=\"Property B\" "
151: + "displayDescription=\"A test string property B\" "
152: + "defaultValue=\"b\" "
153: + "isApplicationRestartRequired=\"false\" "
154: + "isComponentRestartRequired=\"false\" "
155: + "isServerRestartRequired=\"false\" "
156: + "showDisplay=\"all\"/> "
157: +
158:
159: "<config:Property name=\"C\" "
160: + "type=\"xsd:string\" "
161: + "displayName=\"Property C\" "
162: + "displayDescription=\"A test string property C\" "
163: + "defaultValue=\"c\" "
164: + "isApplicationRestartRequired=\"false\" "
165: + "isComponentRestartRequired=\"false\" "
166: + "isServerRestartRequired=\"false\" "
167: + "showDisplay=\"runtime\" "
168: + "encrypted=\"true\"/> "
169: +
170:
171: "<config:ApplicationConfiguration> "
172: + "<config:Property name=\"configurationName\" "
173: + "displayName=\"Application Configuration Name\" "
174: + "displayDescription=\"Name of the application configuration\" "
175: + "type=\"xsd:string\" "
176: + "required=\"true\"/> "
177: + "<config:Property name=\"connectionURL\" "
178: + "displayName=\"Connection URL\" "
179: + "displayDescription=\"The connection URL\" "
180: + "type=\"xsd:string\" "
181: + "required=\"true\"/> "
182: +
183:
184: "<config:Property name=\"securityPrincipal\" "
185: + "displayName=\"Security Principal\" "
186: + "displayDescription=\"User Name\" "
187: + "type=\"xsd:string\" "
188: + "required=\"true\"/> "
189: +
190:
191: "<config:Property name=\"securityCredential\" "
192: + "displayName=\"Security Credential\" "
193: + "displayDescription=\"User Password\" "
194: + "type=\"xsd:string\" "
195: + "required=\"true\" "
196: + "encrypted=\"true\"/> "
197: +
198:
199: "<config:Property name=\"jndienv\" "
200: + "displayName=\"JNDI Environment Properties\" "
201: + "displayDescription=\"The JNDI Environment Properties\" "
202: + "type=\"xsd:string\" "
203: + "required=\"false\" "
204: + "maxOccurs=\"unbounded\"/> "
205: +
206:
207: "</config:ApplicationConfiguration>"
208: +
209:
210: "<!-- Example of Application Variable -->"
211: + "<config:ApplicationVariable isApplicationRestartRequired=\"true\">"
212: + "<config:name/>" + "<config:type/>" + "<config:value/>"
213: + "</config:ApplicationVariable>"
214: + "</config:Configuration>";
215:
216: private static final String CONFIG_XML_NEW_NO_APP_CONFIG =
217:
218: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
219: +
220:
221: "<config:Configuration xmlns:config='http://www.sun.com/jbi/Configuration/V1.0'>"
222: +
223:
224: "<config:Property name=\"C\" "
225: + "type=\"xsd:string\" "
226: + "displayName=\"Property C\" "
227: + "displayDescription=\"A test string property C\" "
228: + "defaultValue=\"c\" "
229: + "isApplicationRestartRequired=\"false\" "
230: + "isComponentRestartRequired=\"false\" "
231: + "isServerRestartRequired=\"false\" "
232: + "showDisplay=\"runtime\" "
233: + "encrypted=\"true\"/> "
234: +
235:
236: "<!-- Example of Application Variable -->"
237: + "<config:ApplicationVariable isApplicationRestartRequired=\"true\">"
238: + "<config:name/>" + "<config:type/>" + "<config:value/>"
239: + "</config:ApplicationVariable>"
240: + "</config:Configuration>";
241:
242: private static final String CONFIG_XML_NEW_NO_APP_VAR =
243:
244: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
245: +
246:
247: "<config:Configuration xmlns:config='http://www.sun.com/jbi/Configuration/V1.0'>"
248: +
249:
250: "<config:Property name=\"C\" "
251: + "type=\"xsd:string\" "
252: + "displayName=\"Property C\" "
253: + "displayDescription=\"A test string property C\" "
254: + "defaultValue=\"c\" "
255: + "isApplicationRestartRequired=\"false\" "
256: + "isComponentRestartRequired=\"false\" "
257: + "isServerRestartRequired=\"false\" "
258: + "showDisplay=\"runtime\" "
259: + "encrypted=\"true\"/> "
260: +
261:
262: "<config:ApplicationConfiguration> "
263: + "<config:Property name=\"configurationName\" "
264: + "displayName=\"Application Configuration Name\" "
265: + "displayDescription=\"Name of the application configuration\" "
266: + "type=\"xsd:string\" " + "required=\"true\"/> "
267: + "<config:Property name=\"connectionURL\" "
268: + "displayName=\"Connection URL\" "
269: + "displayDescription=\"The connection URL\" "
270: + "type=\"xsd:string\" " + "required=\"true\"/> " +
271:
272: "<config:Property name=\"securityPrincipal\" "
273: + "displayName=\"Security Principal\" "
274: + "displayDescription=\"User Name\" "
275: + "type=\"xsd:string\" " + "required=\"true\"/> " +
276:
277: "<config:Property name=\"securityCredential\" "
278: + "displayName=\"Security Credential\" "
279: + "displayDescription=\"User Password\" "
280: + "type=\"xsd:string\" " + "required=\"true\" "
281: + "encrypted=\"true\"/> " +
282:
283: "<config:Property name=\"jndienv\" "
284: + "displayName=\"JNDI Environment Properties\" "
285: + "displayDescription=\"The JNDI Environment Properties\" "
286: + "type=\"xsd:string\" " + "required=\"false\" "
287: + "maxOccurs=\"unbounded\"/> " +
288:
289: "</config:ApplicationConfiguration>"
290: + "</config:Configuration>";
291:
292: private static final String CONFIG_XML_NEW_NO_COMP_CONFIG =
293:
294: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
295: +
296:
297: "<config:Configuration xmlns:config='http://www.sun.com/jbi/Configuration/V1.0'>"
298: +
299:
300: "<config:ApplicationConfiguration> "
301: + "<config:Property name=\"configurationName\" "
302: + "displayName=\"Application Configuration Name\" "
303: + "displayDescription=\"Name of the application configuration\" "
304: + "type=\"xsd:string\" "
305: + "required=\"true\"/> "
306: + "<config:Property name=\"connectionURL\" "
307: + "displayName=\"Connection URL\" "
308: + "displayDescription=\"The connection URL\" "
309: + "type=\"xsd:string\" "
310: + "required=\"true\"/> "
311: +
312:
313: "<config:Property name=\"securityPrincipal\" "
314: + "displayName=\"Security Principal\" "
315: + "displayDescription=\"User Name\" "
316: + "type=\"xsd:string\" "
317: + "required=\"true\"/> "
318: +
319:
320: "<config:Property name=\"securityCredential\" "
321: + "displayName=\"Security Credential\" "
322: + "displayDescription=\"User Password\" "
323: + "type=\"xsd:string\" "
324: + "required=\"true\" "
325: + "encrypted=\"true\"/> "
326: +
327:
328: "<config:Property name=\"jndienv\" "
329: + "displayName=\"JNDI Environment Properties\" "
330: + "displayDescription=\"The JNDI Environment Properties\" "
331: + "type=\"xsd:string\" "
332: + "required=\"false\" "
333: + "maxOccurs=\"unbounded\"/> "
334: +
335:
336: "</config:ApplicationConfiguration>"
337: +
338:
339: "<!-- Example of Application Variable -->"
340: + "<config:ApplicationVariable isApplicationRestartRequired=\"true\">"
341: + "<config:name/>" + "<config:type/>" + "<config:value/>"
342: + "</config:ApplicationVariable>"
343: + "</config:Configuration>";
344:
345: /**
346: * The constructor for this testcase, forwards the test name to
347: * the jUnit TestCase base class.
348: * @param aTestName String with the name of this test.
349: */
350: public TestComponentConfigurationHelper(String aTestName) {
351: super (aTestName);
352: }
353:
354: /**
355: * Test splitting property value into value and type
356: */
357: public void testGetAppVarType() throws Exception {
358: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
359:
360: assertEquals("PASSWORD", cchlpr.getAppVarType(
361: "[PASSWORD]5646vg", cchlpr.DEFAULT_APP_VAR_TYPE));
362: }
363:
364: /**
365: * Test splitting property value into value and type, when type goind in
366: * is lower case, but coming out should be upper case.
367: */
368: public void testGetAppVarType1() throws Exception {
369: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
370:
371: assertEquals("STRING", cchlpr.getAppVarType("[String]5646vg",
372: cchlpr.DEFAULT_APP_VAR_TYPE));
373: }
374:
375: /**
376: * Test splitting property value into value and type, when type is not specified
377: */
378: public void testGetAppVarType2() throws Exception {
379: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
380:
381: assertEquals("STRING", cchlpr.getAppVarType("5646vg",
382: cchlpr.DEFAULT_APP_VAR_TYPE));
383: }
384:
385: /**
386: * Test splitting property value into value and type, when type is not specified
387: */
388: public void testGetAppVarType3() throws Exception {
389: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
390:
391: assertEquals("STRING", cchlpr.getAppVarType("[ ]5646vg",
392: cchlpr.DEFAULT_APP_VAR_TYPE));
393: }
394:
395: /**
396: * Test splitting property value into value and type
397: */
398: public void testGetAppVarValue() throws Exception {
399: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
400:
401: System.out.println(cchlpr.getAppVarValue("[PASSWORD]5646vg"));
402: assertEquals("5646vg", cchlpr
403: .getAppVarValue("[PASSWORD]5646vg"));
404: }
405:
406: /**
407: * Test Converting App. Var properties to Tabular data
408: */
409: public void testConvertToApplicationVariablesTable()
410: throws Exception {
411: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
412:
413: Properties props = new Properties();
414: props.put("Host", "[STRING]mystique01");
415: props.put("Port", "[NUMBER]1056");
416: props.put("User", "[STRING]perty");
417: props.put("Pwd", "[PASSWORD]678hjj");
418:
419: TabularData td = cchlpr
420: .convertToApplicationVariablesTable(props);
421: assertNotNull(td);
422:
423: Properties convProps = cchlpr
424: .convertToApplicationVariablesProperties(td);
425:
426: assertTrue(convProps.containsKey("Host"));
427: assertTrue(convProps.get("Host").equals("[STRING]mystique01"));
428:
429: assertTrue(convProps.containsKey("Port"));
430: assertTrue(convProps.get("Port").equals("[NUMBER]1056"));
431:
432: assertTrue(convProps.containsKey("User"));
433: assertTrue(convProps.get("User").equals("[STRING]perty"));
434:
435: assertTrue(convProps.containsKey("Pwd"));
436: assertTrue(convProps.get("Pwd").equals("[PASSWORD]678hjj"));
437: }
438:
439: /**
440: *
441: */
442: public void testConvertPropertiesToCompositeData() throws Exception {
443: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
444:
445: Properties props = new Properties();
446: props.put("configurationName", "myTestConfig");
447: props.put("connectionURL", "http://");
448: props.put("jndienv.0", "n1=v1");
449: props.put("jndienv.1", "n2=v2");
450: props.put("jndienv.2", "n3=v3");
451: props.put("ports.0", "1");
452: props.put("ports.1", "2");
453:
454: CompositeData cd = cchlpr.convertPropertiesToCompositeData(
455: props, createTestCompositeType());
456:
457: // Verify
458: assertEquals("myTestConfig", cd.get("configurationName"));
459: assertEquals("http://", cd.get("connectionURL"));
460: String[] jndienv = (String[]) cd.get("jndienv");
461: assertEquals(jndienv[0], "n1=v1");
462: assertEquals(jndienv[1], "n2=v2");
463: assertEquals(jndienv[2], "n3=v3");
464: Integer[] ports = (Integer[]) cd.get("ports");
465: assertEquals(ports[0].intValue(), 1);
466: assertEquals(ports[1].intValue(), 2);
467: }
468:
469: /**
470: * Test converting a incomplete properties set to Composite Data
471: */
472: public void testConvertIncompPropertiesToCompositeData()
473: throws Exception {
474: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
475:
476: Properties props = new Properties();
477: props.put("configurationName", "myTestConfig");
478: props.put("connectionURL", "http://");
479: props.put("jndienv.0", "n1=v1");
480: props.put("jndienv.1", "n2=v2");
481: props.put("jndienv.2", "n3=v3");
482: props.put("subComposite", "\"host=myHost, maxUsers=2\"");
483:
484: CompositeData cd = cchlpr.convertPropertiesToCompositeData(
485: props, createTestCompositeType());
486:
487: // Verify
488: assertEquals("myTestConfig", cd.get("configurationName"));
489: assertEquals("http://", cd.get("connectionURL"));
490: String[] jndienv = (String[]) cd.get("jndienv");
491: assertEquals(jndienv[0], "n1=v1");
492: assertEquals(jndienv[1], "n2=v2");
493: assertEquals(jndienv[2], "n3=v3");
494: Integer[] ports = (Integer[]) cd.get("ports");
495: assertNull(ports);
496:
497: CompositeData scd = (CompositeData) cd.get("subComposite");
498: assertNotNull(scd);
499: assertEquals(scd.get("host"), "myHost");
500: assertEquals(scd.get("maxUsers"), "2");
501: }
502:
503: /**
504: * Test converting a CompositeData to properties
505: */
506: public void testConvertCompositeDataToProperties() throws Exception {
507:
508: String[] itemNames = new String[] { "configurationName",
509: "connectionURL", "jndienv", "ports", "subComposite" };
510:
511: CompositeData scd = new CompositeDataSupport(
512: createTestSubCompositeType(), new String[] { "host",
513: "maxUsers" },
514: new Object[] { "someHost", "100" });
515: Object[] itemValues = new Object[] { "myConfig",
516: "myConnectionURL",
517: new String[] { "jndienv1", "jndienv2" },
518: new Integer[] { 1, 2 }, scd };
519:
520: CompositeData cd = new CompositeDataSupport(
521: createTestCompositeType(), itemNames, itemValues);
522: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
523: Properties props = cchlpr.convertCompositeDataToProperties(cd);
524:
525: assertTrue(props.containsKey("configurationName"));
526: assertEquals("myConfig", props.getProperty("configurationName"));
527: assertTrue(props.containsKey("connectionURL"));
528: assertEquals("myConnectionURL", props
529: .getProperty("connectionURL"));
530: assertTrue(props.containsKey("jndienv.0"));
531: assertEquals("jndienv1", props.getProperty("jndienv.0"));
532: assertTrue(props.containsKey("jndienv.1"));
533: assertEquals("jndienv2", props.getProperty("jndienv.1"));
534: assertTrue(props.containsKey("ports.0"));
535: assertEquals("1", props.getProperty("ports.0"));
536: assertTrue(props.containsKey("ports.1"));
537: assertEquals("2", props.getProperty("ports.1"));
538: assertTrue(props.containsKey("subComposite"));
539: //System.out.println("Sub composite value " + props.getProperty("subComposite"));
540: //assertEquals("\"host=someHost, maxUsers=100\"", props.getProperty("subComposite"));
541: }
542:
543: /**
544: * Test converting a CompositeData to properties
545: */
546: public void testConvertIncompleteCompositeDataToProperties()
547: throws Exception {
548:
549: String[] itemNames = new String[] { "configurationName",
550: "connectionURL", "jndienv", "ports", "subComposite" };
551:
552: Object[] itemValues = new Object[] { "myConfig",
553: "myConnectionURL", new String[0], new Integer[0], null };
554:
555: CompositeData cd = new CompositeDataSupport(
556: createTestCompositeType(), itemNames, itemValues);
557: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
558: Properties props = cchlpr.convertCompositeDataToProperties(cd);
559:
560: //System.out.println("Converted composite data : " + props.toString());
561: assertTrue(props.containsKey("configurationName"));
562: assertEquals("myConfig", props.getProperty("configurationName"));
563: assertTrue(props.containsKey("connectionURL"));
564: assertEquals("myConnectionURL", props
565: .getProperty("connectionURL"));
566: assertFalse(props.containsKey("jndienv.0"));
567: assertFalse(props.containsKey("jndienv.1"));
568: assertFalse(props.containsKey("ports.0"));
569: assertFalse(props.containsKey("ports.1"));
570: }
571:
572: /**
573: * Test determining if a app config field is a password field.
574: */
575: public void testIsEncrypted() throws Exception {
576: Document configDoc = createConfigDataDoc(CONFIG_XML_NEW);
577:
578: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
579: boolean isPwd = cchlpr.isPassword("securityCredential",
580: configDoc);
581:
582: assertTrue(isPwd);
583: }
584:
585: /**
586: * Test determining if a field is a password field.
587: */
588: public void testIsEncrypted2() throws Exception {
589: Document configDoc = createConfigDataDoc(CONFIG_XML_NEW);
590:
591: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
592: boolean isPwd = cchlpr.isPassword("C", configDoc);
593:
594: assertTrue(isPwd);
595: }
596:
597: /**
598: * Test determining if a field is a password field.
599: */
600: public void testIsEncrypted3() throws Exception {
601: Document configDoc = createConfigDataDoc(CONFIG_XML_NEW);
602:
603: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
604: boolean isPwd = cchlpr.isPassword("A", configDoc);
605:
606: assertFalse(isPwd);
607: }
608:
609: /**
610: * Test determining if a field is a password field. missing field case
611: */
612: public void testIsEncrypted4() throws Exception {
613: Document configDoc = createConfigDataDoc(CONFIG_XML_NEW);
614:
615: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
616: boolean isPwd = cchlpr.isPassword("dummy", configDoc);
617:
618: assertFalse(isPwd);
619: }
620:
621: /**
622: * Test determining if a field is a required field.
623: */
624: public void testIsRequired() throws Exception {
625: Document configDoc = createConfigDataDoc(CONFIG_XML_NEW);
626:
627: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
628: boolean isRqd = cchlpr.isRequired("A", configDoc);
629:
630: assertTrue(isRqd);
631: }
632:
633: /**
634: * Test determining if a app config field is a required field.
635: */
636: public void testIsRequired2() throws Exception {
637: Document configDoc = createConfigDataDoc(CONFIG_XML_NEW);
638:
639: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
640: boolean isPwd = cchlpr.isRequired("jndienv", configDoc);
641:
642: assertFalse(isPwd);
643: }
644:
645: /**
646: * Test determining if a app config field is a required field. false case
647: */
648: public void testIsRequired3() throws Exception {
649: Document configDoc = createConfigDataDoc(CONFIG_XML_NEW);
650:
651: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
652: boolean isPwd = cchlpr.isRequired("securityCredential",
653: configDoc);
654:
655: assertTrue(isPwd);
656: }
657:
658: /**
659: * Test determining if a field is a required field. false case
660: */
661: public void testIsRequired4() throws Exception {
662: Document configDoc = createConfigDataDoc(CONFIG_XML_NEW);
663:
664: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
665: boolean isPwd = cchlpr.isRequired("C", configDoc);
666:
667: assertFalse(isPwd);
668: }
669:
670: /**
671: * Test determining if a field is a required field. missing field case
672: */
673: public void testIsRequired5() throws Exception {
674: Document configDoc = createConfigDataDoc(CONFIG_XML_NEW);
675:
676: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
677: boolean isPwd = cchlpr.isRequired("dummy", configDoc);
678:
679: assertFalse(isPwd);
680: }
681:
682: /**
683: * Test determining if a field is a password field.
684: */
685: public void testIsPassword() throws Exception {
686: Document configDoc = createConfigDataDoc(CONFIG_XML);
687:
688: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
689: boolean isPwd = cchlpr.isPassword("ProxyPassword", configDoc);
690:
691: assertTrue(isPwd);
692: }
693:
694: /**
695: * Test determining if a field is a password field. false case.
696: */
697: public void testIsPassword2() throws Exception {
698: Document configDoc = createConfigDataDoc(CONFIG_XML);
699:
700: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
701: boolean isPwd = cchlpr.isPassword("OutboundThreads", configDoc);
702:
703: assertFalse(isPwd);
704: }
705:
706: /**
707: * Test determining if a suffixed field is a password field. false case.
708: */
709: public void testIsPassword3() throws Exception {
710: Document configDoc = createConfigDataDoc(CONFIG_XML);
711:
712: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
713: boolean isPwd = cchlpr.isPassword("OutboundThreads.0",
714: configDoc);
715:
716: assertFalse(isPwd);
717: }
718:
719: /**
720: * Test determining if a field is a password field for a undefined
721: * field. false case.
722: */
723: public void testIsPasswordMissingField() throws Exception {
724: Document configDoc = createConfigDataDoc(CONFIG_XML);
725:
726: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
727: boolean isPwd = cchlpr.isPassword("dummy", configDoc);
728:
729: assertFalse(isPwd);
730: }
731:
732: /**
733: * Test determining if a application configuration field is a password field.
734: */
735: public void testIsPasswordForAppConfig() throws Exception {
736: Document configDoc = createConfigDataDoc(CONFIG_XML);
737:
738: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
739: boolean isPwd = cchlpr.isPassword("userPassword", configDoc);
740:
741: assertTrue(isPwd);
742: }
743:
744: /**
745: * Test determining if a suffixed application configurationfield is a password field.
746: */
747: public void testIsPasswordForAppConfig2() throws Exception {
748: Document configDoc = createConfigDataDoc(CONFIG_XML);
749:
750: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
751: boolean isPwd = cchlpr.isPassword("userPassword.0", configDoc);
752:
753: assertTrue(isPwd);
754: }
755:
756: /**
757: * Test determining if a application configurationfield is a password field.
758: * This is the case where a field is not a password field
759: */
760: public void testIsPasswordForAppConfig3() throws Exception {
761: Document configDoc = createConfigDataDoc(CONFIG_XML);
762:
763: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
764: boolean isPwd = cchlpr.isPassword("httpLocation", configDoc);
765:
766: assertFalse(isPwd);
767: }
768:
769: /**
770: * Test determining if a suffixed application configuration field is a password field.
771: * This is the case where a field is not a password field
772: */
773: public void testIsPasswordForAppConfig4() throws Exception {
774: Document configDoc = createConfigDataDoc(CONFIG_XML);
775:
776: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
777: boolean isPwd = cchlpr.isPassword("httpLocation.0", configDoc);
778:
779: assertFalse(isPwd);
780: }
781:
782: /**
783: * Test determining if a application configurationfield is a password field.
784: * This is the case where a field is missing
785: */
786: public void testIsPasswordForAppConfigMissingField()
787: throws Exception {
788: Document configDoc = createConfigDataDoc(CONFIG_XML);
789:
790: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
791: boolean isPwd = cchlpr.isPassword("dummy", configDoc);
792:
793: assertFalse(isPwd);
794: }
795:
796: /**
797: * Test determining if a component supports component configuration
798: */
799: public void testIsComponentConfigSupported() throws Exception {
800: Document configDoc = createConfigDataDoc(CONFIG_XML_NEW);
801:
802: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
803: boolean supported = cchlpr
804: .isComponentConfigSupported(configDoc);
805:
806: assertTrue(supported);
807: }
808:
809: /**
810: * Test determining if a component supports component configuration
811: */
812: public void testIsComponentConfigSupportedNegative()
813: throws Exception {
814: Document configDoc = createConfigDataDoc(CONFIG_XML_NEW_NO_COMP_CONFIG);
815:
816: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
817: boolean supported = cchlpr
818: .isComponentConfigSupported(configDoc);
819:
820: assertFalse(supported);
821: }
822:
823: /**
824: * Test determining if a component supports application variables
825: */
826: public void testIsAppVarsSupported() throws Exception {
827: Document configDoc = createConfigDataDoc(CONFIG_XML_NEW);
828:
829: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
830: boolean supported = cchlpr.isAppVarsSupported(configDoc);
831:
832: assertTrue(supported);
833: }
834:
835: /**
836: * Test determining if a component supports application variables
837: */
838: public void testIsAppVarsSupportedNegative() throws Exception {
839: Document configDoc = createConfigDataDoc(CONFIG_XML_NEW_NO_APP_VAR);
840:
841: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
842: boolean supported = cchlpr.isAppVarsSupported(configDoc);
843:
844: assertFalse(supported);
845: }
846:
847: /**
848: * Test determining if a component supports application configuration
849: */
850: public void testIsAppConfigSupported() throws Exception {
851: Document configDoc = createConfigDataDoc(CONFIG_XML_NEW);
852:
853: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
854: boolean supported = cchlpr.isAppConfigSupported(configDoc);
855:
856: assertTrue(supported);
857: }
858:
859: /**
860: * Test determining if a component supports application configuration
861: */
862: public void testIsAppConfigSupportedNegative() throws Exception {
863: Document configDoc = createConfigDataDoc(CONFIG_XML_NEW_NO_APP_CONFIG);
864:
865: ComponentConfigurationHelper cchlpr = new ComponentConfigurationHelper();
866: boolean supported = cchlpr.isAppConfigSupported(configDoc);
867:
868: assertFalse(supported);
869: }
870:
871: private Document createConfigDataDoc(String configData)
872: throws Exception {
873: DocumentBuilderFactory dbf = DocumentBuilderFactory
874: .newInstance();
875: dbf.setNamespaceAware(true);
876: DocumentBuilder db = dbf.newDocumentBuilder();
877: InputStream ios = new StringBufferInputStream(configData);
878:
879: Document doc = db.parse(ios);
880: ios.close();
881: return doc;
882: }
883:
884: /**
885: *
886: */
887: private CompositeType createTestCompositeType() throws Exception {
888: String[] itemNames = new String[] { "configurationName",
889: "connectionURL", "jndienv", "ports", "subComposite" };
890:
891: OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
892: SimpleType.STRING, new ArrayType(1, SimpleType.STRING),
893: new ArrayType(1, SimpleType.INTEGER),
894: createTestSubCompositeType() };
895:
896: String[] itemDescr = new String[] { "Configuration Name",
897: "Connection URL", "JNDI env", "List of Ports",
898: "Host and Users" };
899:
900: return new CompositeType("TestComposite",
901: "Test Composite Type", itemNames, itemDescr, itemTypes);
902: }
903:
904: /**
905: *
906: */
907: private CompositeType createTestSubCompositeType() throws Exception {
908: String[] itemNames = new String[] { "host", "maxUsers" };
909:
910: OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
911: SimpleType.STRING };
912:
913: String[] itemDescr = new String[] { "Host Name", "Max Users" };
914:
915: return new CompositeType("TestSubComposite",
916: "Test Sub Composite Type", itemNames, itemDescr,
917: itemTypes);
918: }
919: }
|