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: * @(#)TestLoader.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.internal.security.util;
030:
031: import java.io.File;
032:
033: import javax.xml.parsers.DocumentBuilder;
034: import javax.xml.parsers.DocumentBuilderFactory;
035: import javax.xml.parsers.ParserConfigurationException;
036:
037: import org.w3c.dom.Document;
038: import org.w3c.dom.Element;
039:
040: public class TestLoader extends junit.framework.TestCase {
041:
042: /**
043: */
044: private String config = null;
045: private File tmpFile = null;
046: private File newFile = null;
047: private String newFileName = null;
048: private String configSchema = null;
049: private String xwssSchema = null;
050: private String instConfig = null;
051: private String instConfigSchema = null;
052:
053: /**
054: */
055: public TestLoader(String aTestName) {
056: super (aTestName);
057: String srcroot = System.getProperty("junit.srcroot");
058: String security = "/runtime/esb-security"; // open-esb build
059:
060: java.io.File f = new java.io.File(srcroot + security);
061: if (!f.exists()) {
062: security = "/shasta/security"; // mainline/whitney build
063: }
064:
065: config = srcroot + security
066: + "/regress/deployconfig/EndptDeployConfig.xml";
067: configSchema = srcroot + security
068: + "/schema/secdeployconfig.xsd";
069: xwssSchema = srcroot + security + "/schema/xwssconfig.xsd";
070: instConfig = srcroot + security
071: + "/regress/installconfig/InstallConfig1.xml";
072: instConfigSchema = srcroot + security
073: + "/schema/secinstallconfig.xsd";
074: }
075:
076: /**
077: * Test the load without any validation
078: * @throws Exception if an unexpected error occurs
079: */
080: public void testLoad() throws Exception {
081: String testname = "testLoad";
082: try {
083: // -- Test the Load method
084: Loader ldr = new Loader();
085: org.w3c.dom.Document doc = ldr.load(config, false, null,
086: null);
087: assertNotNull("The Document was not loaded correctly.", doc);
088: } catch (Exception aEx) {
089: aEx.printStackTrace();
090: fail(testname + ": failed due to -" + aEx.getMessage());
091: throw aEx;
092: }
093: }
094:
095: /**
096: * Test the load with validation.
097: *
098: * @throws Exception if an unexpected error occurs
099: */
100: public void testLoadWithValidation() throws Exception {
101: String testname = "testLoadWithValidation";
102: try {
103:
104: Loader ldr = new Loader();
105: org.w3c.dom.Document doc = ldr
106: .load(
107: instConfig,
108: true,
109: new com.sun.jbi.internal.security.config.ConfigErrorHandler(
110: (new com.sun.jbi.internal.security.SampleBindingContext(
111: "sb-111"))
112: .getStringTranslator("com.sun.jbi.internal.security")),
113: new String[] { instConfigSchema });
114: assertNotNull("The Document was not loaded correctly.", doc);
115:
116: } catch (Exception aEx) {
117: aEx.printStackTrace();
118: fail(testname + ": failed due to -" + aEx.getMessage());
119: throw aEx;
120: }
121: }
122:
123: /**
124: * Test the load with validation.
125: *
126: * @throws Exception if an unexpected error occurs
127: */
128: public void testLoadWithValidation2() throws Exception {
129: String testname = "testLoadWithValidation2";
130: try {
131: Loader ldr = new Loader();
132: org.w3c.dom.Document doc = ldr
133: .load(
134: config,
135: true,
136: new com.sun.jbi.internal.security.config.ConfigErrorHandler(
137: (new com.sun.jbi.internal.security.SampleBindingContext(
138: "sb-111"))
139: .getStringTranslator("com.sun.jbi.internal.security")),
140: new String[] { configSchema });
141: assertNotNull("The Document was not loaded correctly.", doc);
142:
143: } catch (Exception aEx) {
144: aEx.printStackTrace();
145: fail(testname + ": failed due to -" + aEx.getMessage());
146: throw aEx;
147: }
148: }
149:
150: }
|