KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > tools > ant > ServiceAssembliesTasksTest


1 package org.objectweb.petals.tools.ant;
2
3 import java.io.File JavaDoc;
4 import java.io.IOException JavaDoc;
5
6 import junit.framework.TestCase;
7
8 import org.objectweb.petals.tools.ant.DeployServiceAssemblyTask;
9 import org.objectweb.petals.tools.ant.ListServiceAssembliesTask;
10 import org.objectweb.petals.tools.ant.ShutdownServiceAssemblyTask;
11 import org.objectweb.petals.tools.ant.StartServiceAssemblyTask;
12 import org.objectweb.petals.tools.ant.StopServiceAssemblyTask;
13 import org.objectweb.petals.tools.ant.UndeployServiceAssemblyTask;
14 import org.objectweb.petals.tools.ant.util.ServerUtil;
15
16 /**
17  * Test the service assemlies ant tasks
18  *
19  * @author ddesjardins - eBMWebsourcing
20  */

21 public class ServiceAssembliesTasksTest extends TestCase {
22
23     /**
24      * Port of the JMX server
25      */

26     private static int port = 9988;
27
28     public void setUp() throws Exception JavaDoc {
29         ServerUtil.start(port);
30     }
31
32     public void tearDown() throws IOException JavaDoc {
33         ServerUtil.stop();
34     }
35
36     /**
37      * Test the deploy of a service assembly task
38      *
39      * @throws Exception
40      */

41     public void testDeploy() {
42         String JavaDoc baseDir = this.getClass().getResource(".").toString();
43         baseDir = baseDir.substring(0, baseDir.indexOf("target"));
44         baseDir = baseDir.substring(baseDir.indexOf(":")+1);
45         DeployServiceAssemblyTask deployServiceAssemblyTask = new DeployServiceAssemblyTask();
46         deployServiceAssemblyTask.setFile("file:" + baseDir + "src"
47                 + File.separator + "test-data" + File.separator + "sa.zip");
48         deployServiceAssemblyTask.setPort("" + port);
49         deployServiceAssemblyTask.execute();
50     }
51
52     /**
53      * Test the exception throwing
54      *
55      */

56     public void testExceptionDeployUnsuccessfull() {
57         DeployServiceAssemblyTask deployServiceAssemblyTask = new DeployServiceAssemblyTask();
58         String JavaDoc baseDir = this.getClass().getResource(".").toString();
59         baseDir = baseDir.substring(0, baseDir.indexOf("target"));
60         baseDir = baseDir.substring(baseDir.indexOf(":")+1);
61         deployServiceAssemblyTask.setFile("file:" + baseDir + "src"
62                 + File.separator + "test-data" + File.separator
63                 + "sa-unsuccess.zip");
64         deployServiceAssemblyTask.setPort("" + port);
65         deployServiceAssemblyTask.execute();
66     }
67
68     /**
69      * Test the exception throwing
70      *
71      */

72     public void testExceptionFileNull() {
73         DeployServiceAssemblyTask deployServiceAssemblyTask = new DeployServiceAssemblyTask();
74         deployServiceAssemblyTask.setPort("" + port);
75         try {
76             deployServiceAssemblyTask.execute();
77             fail();
78         } catch (Exception JavaDoc e) {
79
80         }
81     }
82
83     /**
84      * Test the exception throwing
85      *
86      */

87     public void testExceptionInvalidState() {
88         ListServiceAssembliesTask listServiceAssembliesTask = new ListServiceAssembliesTask();
89         listServiceAssembliesTask.setPort("" + port);
90         listServiceAssembliesTask.setState("InvalidState");
91         try {
92             listServiceAssembliesTask.execute();
93             fail();
94         } catch (Exception JavaDoc e) {
95         }
96     }
97
98     /**
99      * Test the exception throwing
100      *
101      */

102     public void testExceptionProblemServerJMX() {
103         DeployServiceAssemblyTask deployServiceAssemblyTask = new DeployServiceAssemblyTask();
104         String JavaDoc baseDir = this.getClass().getResource(".").toString();
105         baseDir = baseDir.substring(0, baseDir.indexOf("target"));
106         baseDir = baseDir.substring(baseDir.indexOf(":")+1);
107         deployServiceAssemblyTask.setFile("file:" + baseDir + "src"
108                 + File.separator + "test-data" + File.separator + "sa.zip");
109         deployServiceAssemblyTask.setPort("" + port);
110         try {
111             tearDown();
112             deployServiceAssemblyTask.execute();
113             fail();
114         } catch (Exception JavaDoc e) {
115
116         }
117     }
118
119     /**
120      * Test the exception throwing
121      *
122      */

123     public void testExceptionXMLOutput() {
124         ListServiceAssembliesTask listServiceAssembliesTask = new ListServiceAssembliesTask();
125         listServiceAssembliesTask.setPort("" + port);
126         listServiceAssembliesTask.setXmlOutput("output");
127         listServiceAssembliesTask.execute();
128     }
129
130     /**
131      * Test the exception throwing
132      *
133      */

134     public void testExceptionNameNull() {
135         StartServiceAssemblyTask startServiceAssemblyTask = new StartServiceAssemblyTask();
136         startServiceAssemblyTask.setPort("" + port);
137         try {
138             startServiceAssemblyTask.execute();
139             fail();
140         } catch (Exception JavaDoc e) {
141
142         }
143     }
144
145     /**
146      * Test the exception throwing
147      *
148      */

149     public void testExceptionServerJMX() {
150         testDeploy();
151         StartServiceAssemblyTask startServiceAssemblyTask = new StartServiceAssemblyTask();
152         startServiceAssemblyTask.setPort("" + port);
153         startServiceAssemblyTask.setName("unsuccessSA");
154         startServiceAssemblyTask.execute();
155     }
156
157     /**
158      * Test the list of service assemblies task
159      */

160     public void testList() {
161         testDeploy();
162         ListServiceAssembliesTask listServiceAssembliesTask = new ListServiceAssembliesTask();
163         listServiceAssembliesTask.setPort("" + port);
164         listServiceAssembliesTask.execute();
165     }
166
167     /**
168      * Test the list of service assemblies task
169      */

170     public void testList1() {
171         testDeploy();
172         ListServiceAssembliesTask listServiceAssembliesTask = new ListServiceAssembliesTask();
173         listServiceAssembliesTask.setPort("" + port);
174         listServiceAssembliesTask.setComponentName("foo");
175         listServiceAssembliesTask.execute();
176     }
177
178     /**
179      * Test the shutdown of a service assembly task
180      */

181     public void testShutdown() {
182         testDeploy();
183         ShutdownServiceAssemblyTask shutdownServiceAssemblyTask = new ShutdownServiceAssemblyTask();
184         shutdownServiceAssemblyTask.setName("foo0002");
185         shutdownServiceAssemblyTask.setPort("" + port);
186         shutdownServiceAssemblyTask.execute();
187     }
188
189     /**
190      * Test the start of a service assembly task
191      */

192     public void testStart() {
193         testDeploy();
194         StartServiceAssemblyTask startServiceAssemblyTask = new StartServiceAssemblyTask();
195         startServiceAssemblyTask.setName("foo0002");
196         startServiceAssemblyTask.setPort("" + port);
197         startServiceAssemblyTask.execute();
198     }
199
200     /**
201      * Test the stop of a service assembly task
202      */

203     public void testStop() {
204         testDeploy();
205         StopServiceAssemblyTask stopServiceAssemblyTask = new StopServiceAssemblyTask();
206         stopServiceAssemblyTask.setName("foo0002");
207         stopServiceAssemblyTask.setPort("" + port);
208         stopServiceAssemblyTask.execute();
209     }
210
211     /**
212      * Test the undeployment of a service assembly task
213      */

214     public void testUndeploy() {
215         testDeploy();
216         UndeployServiceAssemblyTask undeployServiceAssemblyTask = new UndeployServiceAssemblyTask();
217         undeployServiceAssemblyTask.setName("foo0002");
218         undeployServiceAssemblyTask.setPort("" + port);
219         undeployServiceAssemblyTask.execute();
220     }
221 }
222
Popular Tags