KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > management > task > InstallComponentTaskTest


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.management.task;
18
19 import java.io.File JavaDoc;
20 import java.io.FileOutputStream JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import java.util.jar.JarOutputStream JavaDoc;
23 import java.util.zip.ZipEntry JavaDoc;
24
25 import javax.jbi.JBIException;
26 import javax.jbi.component.Bootstrap;
27 import javax.jbi.component.InstallationContext;
28 import javax.management.ObjectName JavaDoc;
29
30 import org.apache.servicemix.jbi.installation.AbstractManagementTest;
31 import org.apache.servicemix.jbi.installation.Bootstrap1;
32 import org.apache.servicemix.jbi.util.FileUtil;
33 import org.apache.tools.ant.Project;
34
35 /**
36  *
37  * InstallComponentTaskTest
38  */

39 public class InstallComponentTaskTest extends JbiTaskSupport {
40     
41     
42     private InstallComponentTask installComponentTask;
43     private File JavaDoc rootDir = new File JavaDoc("target/testWDIR");
44     /*
45      * @see TestCase#setUp()
46      */

47     protected void setUp() throws Exception JavaDoc {
48         FileUtil.deleteFile(rootDir);
49         this.container.setRootDir(rootDir.getPath());
50         super.setUp();
51         installComponentTask = new InstallComponentTask(){};
52         installComponentTask.setProject(new Project());
53         installComponentTask.init();
54     }
55
56     /*
57      * @see TestCase#tearDown()
58      */

59     protected void tearDown() throws Exception JavaDoc {
60         installComponentTask.close();
61         super.tearDown();
62     }
63     
64     public void testInstallation() throws Exception JavaDoc {
65         Bootstrap1.setDelegate(new Bootstrap() {
66             public void cleanUp() throws JBIException {
67             }
68             public ObjectName JavaDoc getExtensionMBeanName() {
69                 return null;
70             }
71             public void init(InstallationContext installContext) throws JBIException {
72             }
73             public void onInstall() throws JBIException {
74             }
75             public void onUninstall() throws JBIException {
76             }
77         });
78         String JavaDoc installJarUrl = createInstallerArchive("component1").getAbsolutePath();
79         installComponentTask.setFile(installJarUrl);
80         installComponentTask.init();
81         installComponentTask.execute();
82         File JavaDoc testFile = new File JavaDoc(rootDir, "components" + File.separator
83                 + "component1");
84         assertTrue(testFile.exists());
85         FileUtil.deleteFile(rootDir);
86     }
87
88     protected File JavaDoc createInstallerArchive(String JavaDoc jbi) throws Exception JavaDoc {
89         InputStream JavaDoc is = AbstractManagementTest.class.getResourceAsStream(jbi + "-jbi.xml");
90         File JavaDoc jar = File.createTempFile("jbi", ".zip");
91         JarOutputStream JavaDoc jos = new JarOutputStream JavaDoc(new FileOutputStream JavaDoc(jar));
92         jos.putNextEntry(new ZipEntry JavaDoc("META-INF/jbi.xml"));
93         byte[] buffer = new byte[is.available()];
94         is.read(buffer);
95         jos.write(buffer);
96         jos.closeEntry();
97         jos.close();
98         is.close();
99         return jar;
100     }
101 }
102
Popular Tags