KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > binding > xquarebc > XQuareBCBootstrapImplTest


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id : $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.binding.xquarebc;
23
24 import java.io.File JavaDoc;
25
26 import javax.jbi.JBIException;
27 import javax.jbi.component.InstallationContext;
28
29 import junit.framework.TestCase;
30 import static org.easymock.EasyMock.expect;
31 import static org.easymock.classextension.EasyMock.createMock;
32 import static org.easymock.classextension.EasyMock.replay;
33 import static org.easymock.classextension.EasyMock.verify;
34
35 /**
36  *
37  * Tests the XQuareBCBootstrapImpl
38  *
39  * @version $Rev: 250 $Date: {date}
40  * @since Petals 1.0
41  * @author Marc Dutoo - Open Wide
42  *
43  */

44 public class XQuareBCBootstrapImplTest extends TestCase {
45     File JavaDoc installationRoot = null;
46
47     private String JavaDoc baseDir;
48
49     public void testCleanUp() {
50
51         XQuareBCBootstrapImpl xquareBCBootstrap = new XQuareBCBootstrapImpl();
52
53         // Run the Test
54
try {
55             xquareBCBootstrap.cleanUp();
56         } catch (JBIException e) {
57             e.printStackTrace();
58             fail("Error in SMTPBCBootstrap clean up");
59         }
60     }
61
62     public void testGetExtensionMBeanName() {
63         // Create objects
64
XQuareBCBootstrapImpl xquareBCBootstrap = new XQuareBCBootstrapImpl();
65
66         // Run the Test
67
Object JavaDoc result = null;
68         result = xquareBCBootstrap.getExtensionMBeanName();
69         assertNull("Result of invocation should be null", result);
70     }
71
72     public void testInit() {
73         // Create Mock Objects
74
InstallationContext installationContext = createMock(InstallationContext.class);
75         // Init mocks
76
expect(installationContext.getInstallRoot()).andReturn(
77             installationRoot.getAbsolutePath());
78         replay(installationContext);
79
80         XQuareBCBootstrapImpl xquareBCBootstrap = new XQuareBCBootstrapImpl();
81         // Run the Test
82
try {
83             xquareBCBootstrap.init(installationContext);
84         } catch (JBIException e) {
85             e.printStackTrace();
86             fail("Error in XQuareBCBootstrapImpl init method");
87         }
88
89         assertEquals(xquareBCBootstrap.context, installationContext);
90     }
91
92     public void testOnInstall() {
93         // Create Mock Objects
94
InstallationContext installationContext = createMock(InstallationContext.class);
95         // Init mocks
96
XQuareBCBootstrapImpl xquareBCBootstrap = new XQuareBCBootstrapImpl();
97         // Run the Test
98
try {
99             xquareBCBootstrap.init(installationContext);
100         } catch (JBIException e) {
101             e.printStackTrace();
102             fail("Error in XQuareBCBootstrapImpl onInstall method");
103         }
104     }
105
106     public void testOnUninstall() {
107         // Create Mock Objects
108
InstallationContext installationContext = createMock(InstallationContext.class);
109         // Init mocks
110
expect(installationContext.getInstallRoot()).andReturn(
111             installationRoot.getAbsolutePath()).anyTimes();
112         replay(installationContext);
113
114         XQuareBCBootstrapImpl xquareBCBootstrap = new XQuareBCBootstrapImpl();
115         // Run the Test
116
try {
117             xquareBCBootstrap.init(installationContext);
118             xquareBCBootstrap.onInstall();
119         } catch (JBIException e) {
120             e.printStackTrace();
121             fail("Error in XQuareBCBootstrapImpl init or onUninstall method");
122         }
123
124         // Run the Test
125
try {
126             xquareBCBootstrap.onUninstall();
127         } catch (JBIException e) {
128             e.printStackTrace();
129             fail("Error in XQuareBCBootstrapImpl onuninstall method");
130         }
131         verify(installationContext);
132         File JavaDoc certDir = new File JavaDoc(installationRoot.getAbsolutePath()
133             + File.separator + "certificate");
134         assertFalse(certDir.exists());
135     }
136
137     @Override JavaDoc
138     protected void finalize() throws Throwable JavaDoc {
139         File JavaDoc file = installationRoot.getParentFile();
140         File JavaDoc[] files = file.listFiles();
141         for (File JavaDoc files2 : files) {
142             if (("bootstrap").equals(files2.getName())) {
143                 if (files2.listFiles().length == 0) {
144                     files2.delete();
145                 }
146             }
147         }
148         super.finalize();
149     }
150
151     @Override JavaDoc
152     protected void setUp() throws Exception JavaDoc {
153         baseDir = this.getClass().getResource(".").toString();
154         baseDir = baseDir.substring(0, baseDir.indexOf("target"));
155         baseDir = baseDir.substring(baseDir.indexOf(":") + 1);
156         installationRoot = new File JavaDoc(baseDir + File.separator + "src"
157             + File.separator + "test-data" + File.separator + "bootstrap");
158         installationRoot.mkdirs();
159
160     }
161
162 }
163
Popular Tags