KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > installation > ComponentInstallationTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.jbi.installation;
18
19 import org.apache.servicemix.jbi.container.JBIContainer;
20
21 import java.io.File JavaDoc;
22 import java.net.URL JavaDoc;
23
24 import junit.framework.TestCase;
25
26 /**
27  *
28  * Tests the installation of a standard component, this is actual a dummy
29  * component that doesn't do anything though we are validating the parsing of
30  * the component descriptor and its deployment
31  *
32  * @version $Revision: 426415 $
33  */

34 public class ComponentInstallationTest extends TestCase {
35     protected JBIContainer container = new JBIContainer();
36
37     private File JavaDoc tempRootDir;
38
39     /*
40      * @see TestCase#setUp()
41      */

42     protected void setUp() throws Exception JavaDoc {
43         super.setUp();
44         container.setCreateMBeanServer(true);
45         container.setMonitorInstallationDirectory(true);
46         tempRootDir = File.createTempFile("servicemix", "rootDir");
47         tempRootDir.delete();
48         File JavaDoc tempTemp = new File JavaDoc(tempRootDir.getAbsolutePath() + "/temp");
49         if (!tempTemp.mkdirs())
50             fail("Unable to create temporary working root directory ["
51                     + tempTemp.getAbsolutePath() + "]");
52
53         System.out.println("Using temporary root directory ["
54                 + tempRootDir.getAbsolutePath() + "]");
55
56         container.setRootDir(tempRootDir.getAbsolutePath());
57         container.init();
58         container.start();
59
60     }
61
62     public void testInstallation() throws Exception JavaDoc {
63         try {
64             // Get the component
65
URL JavaDoc componentResource = getClass().getClassLoader().getResource(
66                     "component-dummy-1.0-jbi-installer.jar");
67             assertNotNull(
68                     "The component JAR component-dummy-1.0-jbi-installer.jar is missing from the classpath",
69                     componentResource);
70             container.installArchive(componentResource.toExternalForm());
71
72             URL JavaDoc assemblyResource = getClass().getClassLoader().getResource(
73                     "dummy-assembly.jar");
74             assertNotNull(
75                     "The assembly JAR dummy-assembly.jar is missing from the classpath",
76                     assemblyResource);
77             container.installArchive(getClass().getClassLoader().getResource(
78                     "dummy-assembly.jar").toExternalForm());
79
80         } catch (Exception JavaDoc e) {
81             e.printStackTrace();
82             fail(e.getMessage());
83         }
84     } /*
85          * @see TestCase#tearDown()
86          */

87
88     protected void tearDown() throws Exception JavaDoc {
89         super.tearDown();
90         container.shutDown();
91         deleteDir(tempRootDir);
92     }
93
94     public static boolean deleteDir(File JavaDoc dir) {
95         System.out.println("Deleting directory : "+dir.getAbsolutePath());
96         if (dir.isDirectory()) {
97             String JavaDoc[] children = dir.list();
98             for (int i = 0; i < children.length; i++) {
99                 boolean success = deleteDir(new File JavaDoc(dir, children[i]));
100                 if (!success) {
101                     return false;
102                 }
103             }
104         }
105
106         // The directory is now empty so delete it
107
return dir.delete();
108     }
109 }
110
Popular Tags