PageRenderTime 131ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/com/phenix/pct/PCTASBrokerTest.java

https://code.google.com/p/pct/
Java | 258 lines | 160 code | 32 blank | 66 comment | 2 complexity | 5f92a3c3c9c8228433b296fa9bc453b2 MD5 | raw file
  1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 2002 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "Ant" and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. */
  54. package com.phenix.pct;
  55. import static org.testng.Assert.assertFalse;
  56. import static org.testng.Assert.assertEquals;
  57. import static org.testng.Assert.assertNotNull;
  58. import static org.testng.Assert.assertNull;
  59. import static org.testng.Assert.assertTrue;
  60. import org.apache.tools.ant.BuildException;
  61. import org.ini4j.Ini;
  62. import org.ini4j.Profile.Section;
  63. import org.ini4j.InvalidFileFormatException;
  64. import org.testng.annotations.Test;
  65. import java.io.File;
  66. import java.io.IOException;
  67. /**
  68. * Class for testing PCTASBroker task
  69. *
  70. * @author <a href="mailto:g.querret+PCT@gmail.com">Gilles QUERRET</a>
  71. */
  72. public class PCTASBrokerTest extends BuildFileTestNg {
  73. @Test(groups = {"all"}, expectedExceptions = BuildException.class)
  74. public void testFailure1() {
  75. configureProject("PCTASBroker/test1/build.xml");
  76. executeTarget("test");
  77. }
  78. @Test(groups = {"all"}, expectedExceptions = BuildException.class)
  79. public void testFailure2() {
  80. configureProject("PCTASBroker/test2/build.xml");
  81. executeTarget("test");
  82. }
  83. @Test(groups = {"all"})
  84. public void testSimplestTest() throws InvalidFileFormatException, IOException {
  85. configureProject("PCTASBroker/test3/build.xml");
  86. executeTarget("test");
  87. Ini ini = new Ini(new File("PCTASBroker/test3/ubroker.properties"));
  88. assertNotNull(ini.get("UBroker.AS.Test"));
  89. }
  90. @Test(groups = {"all"})
  91. public void testUidNone() throws InvalidFileFormatException, IOException {
  92. configureProject("PCTASBroker/test4/build.xml");
  93. executeTarget("test");
  94. Ini ini = new Ini(new File("PCTASBroker/test4/ubroker.properties"));
  95. Section section = ini.get("UBroker.AS.Test");
  96. assertNotNull(section);
  97. assertFalse(section.containsKey("uuid"));
  98. }
  99. @Test(groups = {"all"})
  100. public void testUidAuto() throws InvalidFileFormatException, IOException {
  101. configureProject("PCTASBroker/test5/build.xml");
  102. executeTarget("test");
  103. Ini ini = new Ini(new File("PCTASBroker/test5/ubroker.properties"));
  104. Section section = ini.get("UBroker.AS.Test");
  105. assertNotNull(section);
  106. assertTrue(section.containsKey("uuid"));
  107. assertNotNull(section.get("uuid"), "Null uuid");
  108. assertTrue((section.get("uuid", String.class).length() < 30), "Weird UUID pattern...");
  109. }
  110. @Test(groups = {"all"})
  111. public void testUid() throws InvalidFileFormatException, IOException {
  112. configureProject("PCTASBroker/test6/build.xml");
  113. executeTarget("test");
  114. Ini ini = new Ini(new File("PCTASBroker/test6/ubroker.properties"));
  115. Section section = ini.get("UBroker.AS.Test");
  116. assertNotNull(section);
  117. assertTrue(section.containsKey("uuid"));
  118. assertNotNull(section.get("uuid"), "Null uuid");
  119. assertTrue(
  120. section.get("uuid", String.class).equals(
  121. "3fb5744ad58ca1b0:239137:10a178402e4:-8000"), "Wrong UUID");
  122. }
  123. @Test(groups = {"all"})
  124. public void testLogging() throws InvalidFileFormatException, IOException {
  125. configureProject("PCTASBroker/test7/build.xml");
  126. executeTarget("test");
  127. Ini ini = new Ini(new File("PCTASBroker/test7/ubroker.properties"));
  128. Section section = ini.get("UBroker.AS.Test");
  129. assertNotNull(section.get("brokerLogFile"));
  130. assertNotNull(section.get("brkrLoggingLevel"));
  131. assertNotNull(section.get("srvrLoggingLevel"));
  132. assertNotNull(section.get("srvrLogFile"));
  133. }
  134. @Test(groups = {"all"})
  135. public void testApsvDelete() throws InvalidFileFormatException, IOException {
  136. configureProject("PCTASBroker/test8/build.xml");
  137. executeTarget("test");
  138. Ini ini = new Ini(new File("PCTASBroker/test8/ubroker.properties"));
  139. assertNull(ini.get("UBroker.AS.Test"));
  140. }
  141. @Test(groups = {"all"})
  142. public void testApsvUpdate() throws InvalidFileFormatException, IOException {
  143. configureProject("PCTASBroker/test9/build.xml");
  144. executeTarget("test1");
  145. Ini ini = new Ini(new File("PCTASBroker/test9/ubroker.properties"));
  146. Section section = ini.get("UBroker.AS.Test");
  147. assertNotNull(section);
  148. assertTrue("12345".equals(section.get("portNumber")));
  149. ini = null;
  150. executeTarget("test2");
  151. ini = new Ini(new File("PCTASBroker/test9/ubroker.properties"));
  152. section = ini.get("UBroker.AS.Test");
  153. assertNotNull(section);
  154. assertTrue("12346".equals(section.get("portNumber")));
  155. }
  156. @Test(groups = {"all"})
  157. public void testAttributes1() throws InvalidFileFormatException, IOException {
  158. configureProject("PCTASBroker/test10/build.xml");
  159. executeTarget("test");
  160. Ini ini = new Ini(new File("PCTASBroker/test10/ubroker.properties"));
  161. Section section = ini.get("UBroker.AS.Test");
  162. assertNotNull(section);
  163. assertEquals(section.get("operatingMode", String.class), "State-reset");
  164. assertEquals(section.get("autoStart", String.class), "1");
  165. assertEquals(section.get("initialSrvrInstance", String.class), "4");
  166. assertEquals(section.get("minSrvrInstance", String.class), "3");
  167. assertEquals(section.get("maxSrvrInstance", String.class), "5");
  168. assertEquals(section.get("registerNameServer", String.class), "1");
  169. assertEquals(section.get("appserviceNameList", String.class), "Test");
  170. assertEquals(section.get("registrationMode", String.class), "Register-IP");
  171. assertEquals(section.get("controllingNameServer", String.class), "NS1");
  172. assertEquals(section.get("brkrLogAppend", String.class), "1");
  173. assertEquals(section.get("srvrLogAppend", String.class), "0");
  174. }
  175. @Test
  176. public void testAttributes2() throws InvalidFileFormatException, IOException {
  177. configureProject("PCTASBroker/test11/build.xml");
  178. executeTarget("test");
  179. Ini ini = new Ini(new File("PCTASBroker/test11/ubroker.properties"));
  180. Section section = ini.get("UBroker.AS.Test");
  181. assertNotNull(section);
  182. assertEquals(section.get("srvrActivateProc", String.class), "activate.p");
  183. assertEquals(section.get("srvrDeactivateProc", String.class), "deactivate.p");
  184. assertEquals(section.get("srvrConnectProc", String.class), "connect.p");
  185. assertEquals(section.get("srvrDisconnProc", String.class), "disconnect.p");
  186. assertEquals(section.get("srvrStartupProc", String.class), "startup.p");
  187. assertEquals(section.get("srvrShutdownProc", String.class), "shutdown.p");
  188. // Checking PROPATH
  189. // XXX Ini4J escapes strings with \ so this doesn't work on Win
  190. // String propath = section.get("PROPATH", String.class);
  191. // StringTokenizer tokenizer = new StringTokenizer(propath,
  192. // Character.toString(File.pathSeparatorChar));
  193. // assertEquals(tokenizer.countTokens(), 2, "Wrong number of entries in PROPATH");
  194. // assertTrue((tokenizer.nextToken().endsWith("build")), "First entry should be build");
  195. // assertTrue((tokenizer.nextToken().endsWith("build2")), "Second entry should be build2");
  196. String startup = section.get("srvrStartupParam", String.class);
  197. assertTrue((startup.indexOf("-db myDB") != -1), "Unable to find myDB connection");
  198. assertTrue((startup.indexOf("-db myDB2") != -1), "Unable to find myDB2 connection");
  199. }
  200. @Test(expectedExceptions = BuildException.class)
  201. public void testForbiddenAttributes1() {
  202. configureProject("PCTASBroker/test12/build.xml");
  203. executeTarget("test");
  204. }
  205. @Test(expectedExceptions = BuildException.class)
  206. public void testForbiddenAttributes2() {
  207. configureProject("PCTASBroker/test13/build.xml");
  208. executeTarget("test");
  209. }
  210. @Test(expectedExceptions = BuildException.class)
  211. public void testForbiddenAttributes3() {
  212. configureProject("PCTASBroker/test14/build.xml");
  213. executeTarget("test");
  214. }
  215. @Test(expectedExceptions = BuildException.class)
  216. public void testForbiddenAttributes4() {
  217. configureProject("PCTASBroker/test15/build.xml");
  218. executeTarget("test");
  219. }
  220. @Test(expectedExceptions = BuildException.class)
  221. public void testDoubleCreate() {
  222. configureProject("PCTASBroker/test16/build.xml");
  223. executeTarget("test1");
  224. executeTarget("test2");
  225. }
  226. }