1 package org.objectweb.petals.tools.ant; 2 3 import java.io.File ; 4 import java.io.IOException ; 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 21 public class ServiceAssembliesTasksTest extends TestCase { 22 23 26 private static int port = 9988; 27 28 public void setUp() throws Exception { 29 ServerUtil.start(port); 30 } 31 32 public void tearDown() throws IOException { 33 ServerUtil.stop(); 34 } 35 36 41 public void testDeploy() { 42 String 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 56 public void testExceptionDeployUnsuccessfull() { 57 DeployServiceAssemblyTask deployServiceAssemblyTask = new DeployServiceAssemblyTask(); 58 String 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 72 public void testExceptionFileNull() { 73 DeployServiceAssemblyTask deployServiceAssemblyTask = new DeployServiceAssemblyTask(); 74 deployServiceAssemblyTask.setPort("" + port); 75 try { 76 deployServiceAssemblyTask.execute(); 77 fail(); 78 } catch (Exception e) { 79 80 } 81 } 82 83 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 e) { 95 } 96 } 97 98 102 public void testExceptionProblemServerJMX() { 103 DeployServiceAssemblyTask deployServiceAssemblyTask = new DeployServiceAssemblyTask(); 104 String 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 e) { 115 116 } 117 } 118 119 123 public void testExceptionXMLOutput() { 124 ListServiceAssembliesTask listServiceAssembliesTask = new ListServiceAssembliesTask(); 125 listServiceAssembliesTask.setPort("" + port); 126 listServiceAssembliesTask.setXmlOutput("output"); 127 listServiceAssembliesTask.execute(); 128 } 129 130 134 public void testExceptionNameNull() { 135 StartServiceAssemblyTask startServiceAssemblyTask = new StartServiceAssemblyTask(); 136 startServiceAssemblyTask.setPort("" + port); 137 try { 138 startServiceAssemblyTask.execute(); 139 fail(); 140 } catch (Exception e) { 141 142 } 143 } 144 145 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 160 public void testList() { 161 testDeploy(); 162 ListServiceAssembliesTask listServiceAssembliesTask = new ListServiceAssembliesTask(); 163 listServiceAssembliesTask.setPort("" + port); 164 listServiceAssembliesTask.execute(); 165 } 166 167 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 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 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 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 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 |