KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.apache.servicemix.jbi.util.FileUtil;
21
22 import java.io.File JavaDoc;
23 import java.net.URL JavaDoc;
24
25 import junit.framework.TestCase;
26
27 /**
28  *
29  * Tests the installation of a standard component, this is actual a dummy
30  * component that doesn't do anything though we are validating the parsing of
31  * the component descriptor and its deployment
32  *
33  * @version $Revision: 411178 $
34  */

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

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

93
94     protected void tearDown() throws Exception JavaDoc {
95         super.tearDown();
96         container.shutDown();
97         FileUtil.deleteFile(tempRootDir);
98     }
99
100 }
101
Popular Tags