PageRenderTime 29ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/functional/WindowsAzure/Queue/QueueServiceFunctionalTestData.php

https://bitbucket.org/skudatech/azure-sdk-for-php
PHP | 319 lines | 227 code | 57 blank | 35 comment | 0 complexity | 5d63a00cfc1434a9364341eb7a1615c6 MD5 | raw file
  1. <?php
  2. /**
  3. * LICENSE: Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. *
  14. * PHP version 5
  15. *
  16. * @category Microsoft
  17. * @package Tests\Functional\WindowsAzure\Queue
  18. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  19. * @copyright 2012 Microsoft Corporation
  20. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  21. * @link https://github.com/windowsazure/azure-sdk-for-php
  22. */
  23. namespace Tests\Functional\WindowsAzure\Queue;
  24. use WindowsAzure\Common\Models\Logging;
  25. use WindowsAzure\Common\Models\Metrics;
  26. use WindowsAzure\Common\Models\RetentionPolicy;
  27. use WindowsAzure\Common\Models\ServiceProperties;
  28. use WindowsAzure\Queue\Models\CreateMessageOptions;
  29. use WindowsAzure\Queue\Models\CreateQueueOptions;
  30. use WindowsAzure\Queue\Models\ListQueuesOptions;
  31. class QueueServiceFunctionalTestData
  32. {
  33. const INTERESTING_TTL = 4;
  34. public static $testUniqueId;
  35. public static $tempQueueCounter;
  36. public static $nonExistQueuePrefix;
  37. public static $testQueueNames;
  38. public static function setupData()
  39. {
  40. $rint = mt_rand(0, 1000000);
  41. self::$testUniqueId = 'qa-' . $rint . '-';
  42. self::$nonExistQueuePrefix = 'qa-' . ($rint + 1) . '-';
  43. self::$testQueueNames = array(
  44. self::$testUniqueId . 'a1',
  45. self::$testUniqueId . 'a2',
  46. self::$testUniqueId . 'b1',
  47. );
  48. self::$tempQueueCounter = 0;
  49. }
  50. public static function getInterestingQueueName()
  51. {
  52. return self::$testUniqueId . 'int-' . (self::$tempQueueCounter++);
  53. }
  54. public static function getSimpleMessageText()
  55. {
  56. return 'simple message text #' . (self::$tempQueueCounter++);
  57. }
  58. public static function getInterestingTimeoutValues()
  59. {
  60. $ret = array();
  61. array_push($ret, null);
  62. array_push($ret, -1);
  63. array_push($ret, 0);
  64. array_push($ret, 1);
  65. array_push($ret,-2147483648);
  66. array_push($ret, 2147483647);
  67. return $ret;
  68. }
  69. public static function getDefaultServiceProperties()
  70. {
  71. // This is the default that comes from the server.
  72. $rp = new RetentionPolicy();
  73. $l = new Logging();
  74. $l->setRetentionPolicy($rp);
  75. $l->setVersion('1.0');
  76. $l->setDelete(false);
  77. $l->setRead(false);
  78. $l->setWrite(false);
  79. $m = new Metrics();
  80. $m->setRetentionPolicy($rp);
  81. $m->setVersion('1.0');
  82. $m->setEnabled(false);
  83. $m->setIncludeAPIs(null);
  84. $sp = new ServiceProperties();
  85. $sp->setLogging($l);
  86. $sp->setMetrics($m);
  87. return $sp;
  88. }
  89. public static function getInterestingServiceProperties()
  90. {
  91. $ret = array();
  92. {
  93. // This is the default that comes from the server.
  94. array_push($ret, self::getDefaultServiceProperties());
  95. }
  96. {
  97. $rp = new RetentionPolicy();
  98. $rp->setEnabled(true);
  99. $rp->setDays(10);
  100. $l = new Logging();
  101. $l->setRetentionPolicy($rp);
  102. // Note: looks like only v1.0 is available now.
  103. // http://msdn.microsoft.com/en-us/library/windowsazure/hh360996.aspx
  104. $l->setVersion('1.0');
  105. $l->setDelete(true);
  106. $l->setRead(true);
  107. $l->setWrite(true);
  108. $m = new Metrics();
  109. $m->setRetentionPolicy($rp);
  110. $m->setVersion('1.0');
  111. $m->setEnabled(true);
  112. $m->setIncludeAPIs(true);
  113. $sp = new ServiceProperties();
  114. $sp->setLogging($l);
  115. $sp->setMetrics($m);
  116. array_push($ret,$sp);
  117. }
  118. {
  119. $rp = new RetentionPolicy();
  120. // The service does not accept setting days when enabled is false.
  121. $rp->setEnabled(false);
  122. $rp->setDays(null);
  123. $l = new Logging();
  124. $l->setRetentionPolicy($rp);
  125. // Note: looks like only v1.0 is available now.
  126. // http://msdn.microsoft.com/en-us/library/windowsazure/hh360996.aspx
  127. $l->setVersion('1.0');
  128. $l->setDelete(false);
  129. $l->setRead(false);
  130. $l->setWrite(false);
  131. $m = new Metrics();
  132. $m->setRetentionPolicy($rp);
  133. $m->setVersion('1.0');
  134. $m->setEnabled(true);
  135. $m->setIncludeAPIs(true);
  136. $sp = new ServiceProperties();
  137. $sp->setLogging($l);
  138. $sp->setMetrics($m);
  139. array_push($ret,$sp);
  140. }
  141. {
  142. $rp = new RetentionPolicy();
  143. $rp->setEnabled(true);
  144. // Days has to be 0 < days <= 365
  145. $rp->setDays(364);
  146. $l = new Logging();
  147. $l->setRetentionPolicy($rp);
  148. // Note: looks like only v1.0 is available now.
  149. // http://msdn.microsoft.com/en-us/library/windowsazure/hh360996.aspx
  150. $l->setVersion('1.0');
  151. $l->setDelete(false);
  152. $l->setRead(false);
  153. $l->setWrite(false);
  154. $m = new Metrics();
  155. $m->setVersion('1.0');
  156. $m->setEnabled(false);
  157. $m->setIncludeAPIs(null);
  158. $m->setRetentionPolicy($rp);
  159. $sp = new ServiceProperties();
  160. $sp->setLogging($l);
  161. $sp->setMetrics($m);
  162. array_push($ret,$sp);
  163. }
  164. return $ret;
  165. }
  166. public static function getInterestingMetadata()
  167. {
  168. $ret = self::getNiceMetadata();
  169. // Some metadata that HTTP will not like.
  170. $metadata = array('<>000' => '::::value');
  171. array_push($ret,$metadata);
  172. return $ret;
  173. }
  174. public static function getNiceMetadata()
  175. {
  176. $ret = array();
  177. array_push($ret, null);
  178. $metadata = array();
  179. array_push($ret, $metadata);
  180. $metadata = array(
  181. 'key' => 'value',
  182. 'foo' => 'bar',
  183. 'baz' => 'boo');
  184. array_push($ret, $metadata);
  185. return $ret;
  186. }
  187. public static function getInterestingCreateQueueOptions()
  188. {
  189. $ret = array();
  190. $options = new CreateQueueOptions();
  191. array_push($ret, $options);
  192. $options = new CreateQueueOptions();
  193. $options->setTimeout(10);
  194. array_push($ret, $options);
  195. $options = new CreateQueueOptions();
  196. $options->setTimeout(-10);
  197. array_push($ret, $options);
  198. $options = new CreateQueueOptions();
  199. $metadata = array();
  200. $metadata['foo'] = 'bar';
  201. $metadata['foo2'] = 'bar2';
  202. $metadata['foo3'] = 'bar3';
  203. $options->setMetadata($metadata);
  204. $options->setTimeout(10);
  205. array_push($ret, $options);
  206. $options = new CreateQueueOptions();
  207. $metadata = array('foo' => 'bar');
  208. $options->setMetadata($metadata);
  209. $options->setTimeout(-10);
  210. array_push($ret, $options);
  211. return $ret;
  212. }
  213. public static function getSimpleCreateMessageOptions()
  214. {
  215. $ret = new CreateMessageOptions();
  216. $ret->setTimeout(4);
  217. $ret->setTimeToLiveInSeconds(1000);
  218. $ret->setVisibilityTimeoutInSeconds(self::INTERESTING_TTL);
  219. return $ret;
  220. }
  221. public static function getInterestingListQueuesOptions()
  222. {
  223. $ret = array();
  224. $options = new ListQueuesOptions();
  225. array_push($ret, $options);
  226. $options = new ListQueuesOptions();
  227. $options->setMaxResults(2);
  228. $options->setMaxResults('2');
  229. array_push($ret, $options);
  230. $options = new ListQueuesOptions();
  231. $options->setTimeout(10);
  232. array_push($ret, $options);
  233. $options = new ListQueuesOptions();
  234. $options->setTimeout(-10);
  235. array_push($ret, $options);
  236. $options = new ListQueuesOptions();
  237. $options->setPrefix(self::$nonExistQueuePrefix);
  238. array_push($ret, $options);
  239. $options = new ListQueuesOptions();
  240. $options->setPrefix(self::$testUniqueId);
  241. array_push($ret, $options);
  242. $options = new ListQueuesOptions();
  243. // Cannot set Marker to arbitrary values. Must only use if the previous request returns a NextMarker.
  244. // $options->setMarker('abc');
  245. // So, add logic in listQueuesWorker to loop and setMarker if there is a NextMarker.
  246. $options->setMaxResults(2);
  247. $options->setPrefix(self::$testUniqueId);
  248. $options->setTimeout(10);
  249. array_push($ret, $options);
  250. $options = new ListQueuesOptions();
  251. $options->setMaxResults(3);
  252. $options->setPrefix(self::$testUniqueId);
  253. $options->setTimeout(10);
  254. array_push($ret, $options);
  255. $options = new ListQueuesOptions();
  256. $options->setMaxResults(4);
  257. $options->setPrefix(self::$testUniqueId);
  258. $options->setTimeout(10);
  259. array_push($ret, $options);
  260. return $ret;
  261. }
  262. }