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: * @(#)TestSharedLibraryValidator.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.util;
030:
031: import com.sun.jbi.management.system.ScaffoldEnvironmentContext;
032: import com.sun.jbi.management.system.Util;
033: import java.io.File;
034:
035: public class TestSharedLibraryValidator extends
036: junit.framework.TestCase {
037:
038: private String mConfigDir = null;
039: private String GOOD_SL = "wsdlsl.jar";
040: private String SL_MISSING_CLASS = "wsdlsl-missing-classpath.zip";
041: private String SL_MISSING_CLASS_2 = "wsdlsl-missing-classpath2.zip";
042: private Validator mValidator;
043:
044: public TestSharedLibraryValidator(String aTestName)
045: throws Exception {
046: super (aTestName);
047:
048: String srcroot = System.getProperty("junit.srcroot");
049: String manage = "/runtime/manage"; // open-esb build
050: mConfigDir = srcroot + manage + "/bld/test-classes/testdata/";
051:
052: java.io.File f = new java.io.File(srcroot + manage);
053: if (!f.exists()) {
054: manage = "/shasta/manage"; // mainline/whitney build
055: mConfigDir = srcroot + manage + "/bld/regress/testdata/";
056: }
057:
058: ValidatorFactory.setDescriptorValidation(true);
059: ScaffoldEnvironmentContext envCtx = new ScaffoldEnvironmentContext();
060: envCtx.setJbiInstallRoot(System.getProperty("junit.as8base")
061: + "/jbi");
062: com.sun.jbi.util.EnvironmentAccess.setContext(envCtx);
063:
064: //this is a bad dependency on ManagementContext.
065: //This should be fixed when validation logic is removed from Archive
066: Util.createManagementContext();
067:
068: mValidator = ValidatorFactory.createValidator(envCtx,
069: ValidatorType.SHARED_LIBRARY);
070:
071: }
072:
073: public void setUp() throws Exception {
074: super .setUp();
075: }
076:
077: public void tearDown() throws Exception {
078: }
079:
080: /**
081: * Test with a good shared library
082: */
083: public void testValidateSharedLibraryGood() throws Exception {
084: File testComp = new File(mConfigDir, GOOD_SL);
085:
086: try {
087: mValidator.validate(testComp);
088: } catch (Exception ex) {
089: fail("Unexpected exception " + ex.getMessage());
090: }
091: }
092:
093: /**
094: * Test with a bad shared library missing classpath elements
095: */
096: public void testValidateSharedLibraryMissingClasspath()
097: throws Exception {
098: File testComp = new File(mConfigDir, SL_MISSING_CLASS);
099:
100: try {
101: mValidator.validate(testComp);
102: } catch (Exception ex) {
103: assertTrue(ex.getMessage().contains(
104: "JBI_ADMIN_EMPTY_SHARED_LIBRARY_CLASSPATH"));
105: }
106: }
107:
108: /**
109: * Test with a bad shared library missing classpath elements
110: */
111: public void testValidateSharedLibraryMissingClasspath2()
112: throws Exception {
113: File testComp = new File(mConfigDir, SL_MISSING_CLASS_2);
114:
115: try {
116: mValidator.validate(testComp);
117: } catch (Exception ex) {
118: assertTrue(ex.getMessage().contains(
119: "JBI_ADMIN_ARCHIVE_DESCRIPTOR_NOT_SCHEMA_VALID"));
120: }
121: }
122:
123: }
|