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: * @(#)TestComponentInstaller.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.framework;
030:
031: import com.sun.jbi.management.ComponentInstallationContext;
032:
033: import java.io.File;
034:
035: import javax.management.ObjectName;
036:
037: /**
038: * Tests for the ComponentInstaller class. Note that these test are minimal,
039: * because the class does nothing more than delegate to the ComponentFramework.
040: * The tests here are merely to make sure the ComponentFramework methods get
041: * invoked.
042: *
043: * @author Sun Microsystems, Inc.
044: */
045: public class TestComponentInstaller extends junit.framework.TestCase {
046: /**
047: * EnvironmentContext
048: */
049: private EnvironmentContext mEnvironmentContext;
050:
051: /**
052: * EnvironmentSetup
053: */
054: private EnvironmentSetup mEnvironmentSetup;
055:
056: /**
057: * ComponentInstallationContext
058: */
059: private ComponentInstallationContext mInstallationContext;
060:
061: /**
062: * ComponentInstaller
063: */
064: private ComponentInstaller mComponentInstaller;
065:
066: /**
067: * Constant for install root
068: */
069: private static final String COMP_INSTALL_ROOT = "/as8/domains/domain1/jbi/TestComponent";
070:
071: /**
072: * Constant for lifecycle class name
073: */
074: private static final String COMP_CLASS_NAME = "com.sun.jbi.framework.TestComponent";
075:
076: /**
077: * Constant for component name
078: */
079: private static final String COMP_NAME = "TestComponent";
080:
081: /**
082: * Constant for workspace root
083: */
084: private static final String COMP_WORKSPACE_ROOT = "/as8/domains/domain1/jbi/work/TestComponent";
085:
086: /**
087: * The constructor for this testcase, forwards the test name to
088: * the jUnit TestCase base class.
089: * @param aTestName String with the name of this test.
090: */
091: public TestComponentInstaller(String aTestName) {
092: super (aTestName);
093: }
094:
095: /**
096: * Setup for the test. This creates the ComponentInstaller instance
097: * and other objects needed for the tests.
098: * @throws Exception when set up fails for any reason.
099: */
100: public void setUp() throws Exception {
101: super .setUp();
102:
103: // Create an EnvironmentContext
104: mEnvironmentSetup = new EnvironmentSetup();
105: mEnvironmentContext = mEnvironmentSetup.getEnvironmentContext();
106:
107: // Start up the Component Registry and Component Framework
108: mEnvironmentSetup.startup(true, true);
109:
110: // Create a ComponentInstallationContext
111: mInstallationContext = new ComponentInstallationContext(
112: COMP_NAME, ComponentInstallationContext.BINDING,
113: COMP_CLASS_NAME, null, null);
114: mInstallationContext.setInstallRoot(COMP_INSTALL_ROOT);
115: mInstallationContext.setWorkspaceRoot(COMP_WORKSPACE_ROOT);
116:
117: // Create a ComponentInstaller
118: mComponentInstaller = new ComponentInstaller(
119: mInstallationContext, mEnvironmentContext
120: .getComponentFramework(), mEnvironmentContext
121: .getComponentRegistry());
122: }
123:
124: /**
125: * Cleanup for the test.
126: * @throws Exception when tearDown fails for any reason.
127: */
128: public void tearDown() throws Exception {
129: mEnvironmentSetup.shutdown(true, true);
130: super .tearDown();
131: }
132:
133: // ============================= test methods ================================
134:
135: /**
136: * Test the get method for the installer configuration MBean name.
137: * @throws Exception if an unexpected error occurs.
138: */
139: public void testGetInstallerConfigurationMBean() throws Exception {
140: // The test is for a fresh install, and will fail because the
141: // component's installer has not been loaded.
142: try {
143: ObjectName mbn = mComponentInstaller
144: .getInstallerConfigurationMBean();
145: fail("Expected exception not received");
146: } catch (javax.jbi.JBIException jbiEx) {
147: // Verification
148: assertTrue("Incorrect exception received from install(): "
149: + jbiEx.getMessage(), (-1 < jbiEx.getMessage()
150: .indexOf("not found")));
151: }
152: }
153:
154: /**
155: * Test the get method for the component install root directory.
156: * @throws Exception if an unexpected error occurs.
157: */
158: public void testGetInstallRoot() throws Exception {
159: String installRoot = mComponentInstaller.getInstallRoot();
160: assertEquals("Failure on getInstallRoot(): ", COMP_INSTALL_ROOT
161: .replace('/', File.separatorChar), installRoot);
162: }
163:
164: /**
165: * Test the install method.
166: * @throws Exception if an unexpected error occurs.
167: */
168: public void testInstall() throws Exception {
169: // The test is for a fresh install, and will fail because the
170: // component's installer has not been loaded.
171: try {
172: ObjectName on = mComponentInstaller.install();
173: fail("Expected exception not received");
174: } catch (javax.jbi.JBIException jbiEx) {
175: // Verification
176: assertTrue("Incorrect exception received from install(): "
177: + jbiEx.getMessage(), (-1 < jbiEx.getMessage()
178: .indexOf("not yet been loaded")));
179: }
180: }
181:
182: /**
183: * Test the method for checking whether the component is installed.
184: * @throws Exception if an unexpected error occurs.
185: */
186: public void testIsInstalled() throws Exception {
187: boolean installed = mComponentInstaller.isInstalled();
188: assertFalse(
189: "Failure on isInstalled(): returned true, expected false",
190: installed);
191: }
192:
193: /**
194: * Test the uninstall method.
195: * @throws Exception if an unexpected error occurs.
196: */
197: public void testUninstall() throws Exception {
198: try {
199: mComponentInstaller.uninstall();
200: fail("Expected exception not received");
201: } catch (javax.jbi.JBIException jbiEx) {
202: // Verification
203: assertTrue(
204: "Incorrect exception received from uninstall(): "
205: + jbiEx.getMessage(), (-1 < jbiEx
206: .getMessage().indexOf(
207: "no Binding installed")));
208: }
209: }
210:
211: /**
212: * Test the uninstall method with the force flag.
213: * @throws Exception if an unexpected error occurs.
214: */
215: public void testUninstallForce() throws Exception {
216: try {
217: mComponentInstaller.uninstall(true);
218: fail("Expected exception not received");
219: } catch (javax.jbi.JBIException jbiEx) {
220: // Verification
221: assertTrue(
222: "Incorrect exception received from uninstall(): "
223: + jbiEx.getMessage(), (-1 < jbiEx
224: .getMessage().indexOf(
225: "no Binding installed")));
226: }
227: }
228: }
|