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: * @(#)TestArchive.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.repository;
030:
031: import java.io.File;
032: import com.sun.jbi.management.system.Util;
033:
034: public class TestArchive extends junit.framework.TestCase {
035: private static final String COMPONENT_ARCHIVE_PATH = "/testdata/component.zip";
036:
037: private static final String BAD_COMPONENT_ARCHIVE_PATH = "/testdata/bad-component.zip";
038:
039: private static final String SERVICE_ASSEMBLY_ARCHIVE_PATH = "/testdata/service-assembly.zip";
040:
041: private static final String SCHEMA_INVALID_ARCHIVE_PATH = "/testdata/sa-schema-invalid.zip";
042:
043: private static final String COMPONENT_NAME = "SunSequencingEngine";
044:
045: private static final String SERVICE_ASSEMBLY_NAME = "CompositeApplication";
046:
047: private static final String SERVICE_UNIT_1_NAME = "ESB_ADMIN_SERVICE_UNIT_1";
048:
049: private static final String SERVICE_UNIT_2_NAME = "ESB_ADMIN_SERVICE_UNIT_2";
050:
051: private static final String SERVICE_UNIT_1_PATH = "su1.jar";
052:
053: private static final String SERVICE_UNIT_2_PATH = "su2.jar";
054:
055: private File mComponentArchive;
056: private File mBadComponentArchive;
057: private File mServiceAssemblyArchive;
058: private File mSchemaInvalidArchive;
059:
060: public TestArchive(String aTestName) {
061: super (aTestName);
062:
063: try {
064: String srcRoot = System.getProperty("junit.srcroot");
065: String manage = "/runtime/manage"; // open-esb build
066: String regress = "/bld/test-classes"; // open-esb build
067:
068: java.io.File f = new java.io.File(srcRoot + manage);
069: if (!f.exists()) {
070: manage = "/shasta/manage"; // mainline/whitney build
071: regress = "/bld/regress"; // mainline/whitney build
072: }
073: srcRoot = srcRoot + manage + regress;
074:
075: mComponentArchive = new File(srcRoot,
076: COMPONENT_ARCHIVE_PATH);
077: mBadComponentArchive = new File(srcRoot,
078: BAD_COMPONENT_ARCHIVE_PATH);
079: mServiceAssemblyArchive = new File(srcRoot,
080: SERVICE_ASSEMBLY_ARCHIVE_PATH);
081: mSchemaInvalidArchive = new File(srcRoot,
082: SCHEMA_INVALID_ARCHIVE_PATH);
083:
084: //this is a bad dependency on ManagementContext.
085: //This should be fixed when validation logic is removed from Archive
086: Util.createManagementContext();
087:
088: } catch (Exception ex) {
089: ex.printStackTrace();
090: }
091: }
092:
093: public void setUp() throws Exception {
094: super .setUp();
095:
096: }
097:
098: public void tearDown() throws Exception {
099:
100: }
101:
102: public void testNewComponentArchive() throws Exception {
103: Archive component;
104:
105: component = new Archive(mComponentArchive, true);
106:
107: assertTrue(component.getType() == ArchiveType.COMPONENT);
108: assertTrue(component.getJbiName().equals(COMPONENT_NAME));
109: }
110:
111: public void testNewComponentArchiveMissingJbiXml() throws Exception {
112: Archive component;
113:
114: try {
115: component = new Archive(mBadComponentArchive, true);
116: fail("Created archive from invalid source -- missing jbi.xml");
117: } catch (RepositoryException rEx) {
118: }
119: }
120:
121: public void testNewServiceAssemblyArchive() throws Exception {
122: Archive assembly;
123:
124: assembly = new Archive(mServiceAssemblyArchive, true);
125:
126: // verify SA details
127: assertTrue(assembly.getType() == ArchiveType.SERVICE_ASSEMBLY);
128: assertTrue(assembly.getJbiName().equals(SERVICE_ASSEMBLY_NAME));
129:
130: // verify SU details
131: assertTrue(assembly.hasChildren());
132: assertEquals(assembly.getChildPath(SERVICE_UNIT_1_NAME),
133: SERVICE_UNIT_1_PATH);
134: assertEquals(assembly.getChildPath(SERVICE_UNIT_2_NAME),
135: SERVICE_UNIT_2_PATH);
136: }
137:
138: public void testSchemaInvalidSA() throws Exception {
139: Archive component;
140:
141: try {
142: component = new Archive(mSchemaInvalidArchive, true);
143: fail("Created archive from invalid source -- schema invalid");
144: } catch (RepositoryException rEx) {
145: }
146: }
147: }
|