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: * @(#)TestServiceAssemblyQueryImpl.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.ComponentState;
032: import com.sun.jbi.ComponentInfo;
033: import com.sun.jbi.ComponentType;
034: import com.sun.jbi.ServiceAssemblyQuery;
035: import com.sun.jbi.management.registry.Registry;
036: import com.sun.jbi.management.registry.RegistryBuilder;
037: import com.sun.jbi.management.registry.RegistryException;
038:
039: import com.sun.jbi.management.repository.Repository;
040: import com.sun.jbi.management.repository.ArchiveType;
041:
042: import com.sun.jbi.management.system.Util;
043:
044: import java.io.File;
045: import java.util.List;
046:
047: public class TestServiceAssemblyQueryImpl extends
048: junit.framework.TestCase {
049: /**
050: * The sample Configuration Directory.
051: */
052: private String mConfigDir = null;
053: private File mRegFile;
054: String mRegFilePath;
055: String mRegGoodFilePath;
056: String mEngineZipPath;
057: String mBindingZipPath;
058: String mSharedLibraryZipPath;
059: String mServiceAssemblyZipPath;
060:
061: static final String ENGINE_NAME = "SunSequencingEngine";
062: static final String BINDING_NAME = "SunJMSBinding";
063: static final String SHARED_LIBRARY_NAME = "sun-wsdl-library";
064: static final String SERVICE_ASSEMBLY_NAME = "CompositeApplication";
065:
066: public TestServiceAssemblyQueryImpl(String aTestName) {
067: super (aTestName);
068:
069: String srcroot = System.getProperty("junit.srcroot");
070: String manage = "/runtime/manage"; // open-esb build
071: mConfigDir = srcroot + manage + "/bld/test-classes/testdata/";
072:
073: java.io.File f = new java.io.File(srcroot + manage);
074: if (!f.exists()) {
075: manage = "/shasta/manage"; // mainline/whitney build
076: mConfigDir = srcroot + manage + "/bld/regress/testdata/";
077: }
078:
079: mRegFilePath = mConfigDir + File.separator + "jbi-registry.xml";
080: mRegGoodFilePath = mConfigDir + File.separator
081: + "jbi-registry-good.xml";
082: mEngineZipPath = mConfigDir + "component.zip";
083: mServiceAssemblyZipPath = mConfigDir + "service-assembly.zip";
084: mSharedLibraryZipPath = mConfigDir + "wsdlsl.jar";
085: mBindingZipPath = mConfigDir + "jmsbinding.jar";
086:
087: mRegFile = new File(mRegFilePath);
088:
089: }
090:
091: public void setUp() throws Exception {
092: super .setUp();
093: if (mRegFile.exists()) {
094: mRegFile.delete();
095: }
096: Util.fileCopy(mRegGoodFilePath, mRegFilePath);
097: }
098:
099: public void tearDown() throws Exception {
100: // -- restore registry.xml
101: RegistryBuilder.destroyRegistry();
102: Util.fileCopy(mRegGoodFilePath, mRegFilePath);
103: }
104:
105: public void testGetServiceAssemblies() throws Exception {
106: Registry reg = Util.createRegistry(true);
107: ServiceAssemblyQuery query = reg
108: .getServiceAssemblyQuery("server");
109:
110: Repository repository = reg.getRegistrySpec()
111: .getManagementContext().getRepository();
112:
113: repository.addArchive(ArchiveType.COMPONENT, mEngineZipPath);
114: repository.addArchive(ArchiveType.COMPONENT, mBindingZipPath);
115: repository.addArchive(ArchiveType.SERVICE_ASSEMBLY,
116: mServiceAssemblyZipPath);
117:
118: List<String> sas = query.getServiceAssemblies();
119: assertTrue(sas.contains(SERVICE_ASSEMBLY_NAME));
120:
121: repository.purge();
122: }
123:
124: public void testGetServiceAssemblyInfo() throws Exception {
125: Registry reg = Util.createRegistry(true);
126: ServiceAssemblyQuery query = reg
127: .getServiceAssemblyQuery("server");
128:
129: Repository repository = reg.getRegistrySpec()
130: .getManagementContext().getRepository();
131:
132: repository.addArchive(ArchiveType.COMPONENT, mEngineZipPath);
133: repository.addArchive(ArchiveType.COMPONENT, mBindingZipPath);
134: repository.addArchive(ArchiveType.SERVICE_ASSEMBLY,
135: mServiceAssemblyZipPath);
136:
137: com.sun.jbi.ServiceAssemblyInfo sa = query
138: .getServiceAssemblyInfo(SERVICE_ASSEMBLY_NAME);
139: assertEquals(sa.getName(), SERVICE_ASSEMBLY_NAME);
140: assertTrue(sa.getServiceUnitList().size() == 2);
141: assertTrue(sa.getStatus() == com.sun.jbi.ServiceAssemblyState.STOPPED);
142:
143: repository.purge();
144: }
145:
146: }
|