KickJava   Java API By Example, From Geeks To Geeks.

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


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 ability of the deployer to deploy an exploded component
29  *
30  * @version $Revision: 426415 $
31  */

32 public class ExplodedComponentInstallationTest extends TestCase {
33     protected JBIContainer container = new JBIContainer();
34
35     private File JavaDoc tempRootDir;
36
37     private static final String JavaDoc COMPONENT_NAME = "logger-component-1.0-exploded.jar";
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_NAME);
67             assertNotNull("Unable to find exploded resource " + COMPONENT_NAME,
68                     componentResource);
69             container.installArchive(componentResource.getFile());
70
71             fail("Component should be invalid");
72         } catch (Exception JavaDoc e) {
73         }
74     }
75
76     /*
77      * @see TestCase#tearDown()
78      */

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