KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > lwcontainer > LwContainerComponentTest


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.lwcontainer;
18
19 import org.apache.servicemix.client.DefaultServiceMixClient;
20 import org.apache.servicemix.client.ServiceMixClient;
21 import org.apache.servicemix.jbi.container.JBIContainer;
22 import org.apache.servicemix.lwcontainer.LwContainerComponent;
23
24 import javax.jbi.messaging.InOut;
25 import javax.jbi.messaging.MessagingException;
26 import javax.xml.namespace.QName JavaDoc;
27
28 import java.io.File JavaDoc;
29 import java.net.URI JavaDoc;
30 import java.net.URL JavaDoc;
31
32 import junit.framework.TestCase;
33
34 /**
35  *
36  * @version $Revision: 426415 $
37  */

38 public class LwContainerComponentTest extends TestCase {
39     protected JBIContainer container = new JBIContainer();
40
41     private File JavaDoc tempRootDir;
42
43     /*
44      * @see TestCase#setUp()
45      */

46     protected void setUp() throws Exception JavaDoc {
47         super.setUp();
48         container.setCreateMBeanServer(false);
49         container.setMonitorInstallationDirectory(false);
50         tempRootDir = File.createTempFile("servicemix", "rootDir");
51         tempRootDir.delete();
52         File JavaDoc tempTemp = new File JavaDoc(tempRootDir.getAbsolutePath() + "/temp");
53         if (!tempTemp.mkdirs())
54             fail("Unable to create temporary working root directory ["
55                     + tempTemp.getAbsolutePath() + "]");
56
57         System.out.println("Using temporary root directory ["
58                 + tempRootDir.getAbsolutePath() + "]");
59
60         container.setRootDir(tempRootDir.getAbsolutePath());
61         container.setMonitorInstallationDirectory(false);
62         container.setUseMBeanServer(false);
63         container.setCreateMBeanServer(false);
64         container.setFlowName("st");
65         container.init();
66         container.start();
67     }
68
69     public void testComponentInstallation() throws Exception JavaDoc {
70         LwContainerComponent component = new LwContainerComponent();
71         container.activateComponent(component, "#ServiceMixComponent#");
72         URL JavaDoc url = getClass().getResource("su1-src/servicemix.xml");
73         File JavaDoc path = new File JavaDoc(new URI JavaDoc(url.toString()));
74         path = path.getParentFile();
75         ServiceMixClient client = new DefaultServiceMixClient(container);
76         
77         for (int i = 0; i < 2; i++) {
78             // Deploy and start su
79
component.getServiceUnitManager().deploy("su1", path.getAbsolutePath());
80             component.getServiceUnitManager().init("su1", path.getAbsolutePath());
81             component.getServiceUnitManager().start("su1");
82             
83             // Send message
84
InOut inout = client.createInOutExchange();
85             inout.setService(new QName JavaDoc("http://servicemix.apache.org/demo/", "chained"));
86             client.send(inout);
87             
88             // Stop and undeploy
89
component.getServiceUnitManager().stop("su1");
90             component.getServiceUnitManager().shutDown("su1");
91             component.getServiceUnitManager().undeploy("su1", path.getAbsolutePath());
92
93             // Send message
94
inout = client.createInOutExchange();
95             inout.setService(new QName JavaDoc("http://servicemix.apache.org/demo/", "chained"));
96             try {
97                 client.send(inout);
98             } catch (MessagingException e) {
99                 // Ok, the lw component is undeployed
100
}
101             
102         }
103     }
104
105     /*
106      * @see TestCase#tearDown()
107      */

108
109     protected void tearDown() throws Exception JavaDoc {
110         super.tearDown();
111         container.stop();
112         container.shutDown();
113         deleteDir(tempRootDir);
114     }
115
116     public static boolean deleteDir(File JavaDoc dir) {
117         System.out.println("Deleting directory : " + dir.getAbsolutePath());
118         if (dir.isDirectory()) {
119             String JavaDoc[] children = dir.list();
120             for (int i = 0; i < children.length; i++) {
121                 boolean success = deleteDir(new File JavaDoc(dir, children[i]));
122                 if (!success) {
123                     return false;
124                 }
125             }
126         }
127         // The directory is now empty so delete it
128
return dir.delete();
129     }
130 }
131
Popular Tags