InstanceWindowsTest.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_Amazon
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once 'Zend/Service/Amazon/Ec2/Instance/Windows.php';
  23. require_once 'Zend/Http/Client.php';
  24. require_once 'Zend/Http/Client/Adapter/Test.php';
  25. /**
  26. * Zend_Service_Amazon_Ec2_Instance_Windows test case.
  27. *
  28. * @todo: Should this class be named Zend_Service_Amazon_Ec2_Instance_WindowsTest?
  29. *
  30. * @category Zend
  31. * @package Zend_Service_Amazon
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @group Zend_Service
  36. * @group Zend_Service_Amazon
  37. * @group Zend_Service_Amazon_Ec2
  38. */
  39. class InstanceWindowsTest extends PHPUnit_Framework_TestCase
  40. {
  41. /**
  42. * @var Zend_Service_Amazon_Ec2_Instance_Windows
  43. */
  44. private $Zend_Service_Amazon_Ec2_Instance_Windows;
  45. /**
  46. * Prepares the environment before running a test.
  47. */
  48. protected function setUp()
  49. {
  50. parent::setUp();
  51. $this->Zend_Service_Amazon_Ec2_Instance_Windows = new Zend_Service_Amazon_Ec2_Instance_Windows('access_key', 'secret_access_key');
  52. $adapter = new Zend_Http_Client_Adapter_Test();
  53. $client = new Zend_Http_Client(null, array(
  54. 'adapter' => $adapter
  55. ));
  56. $this->adapter = $adapter;
  57. Zend_Service_Amazon_Ec2_Instance_Windows::setHttpClient($client);
  58. }
  59. /**
  60. * Cleans up the environment after running a test.
  61. */
  62. protected function tearDown()
  63. {
  64. unset($this->adapter);
  65. $this->Zend_Service_Amazon_Ec2_Instance_Windows = null;
  66. parent::tearDown();
  67. }
  68. /**
  69. * Tests Zend_Service_Amazon_Ec2_Instance_Windows->bundle()
  70. */
  71. public function testBundle()
  72. {
  73. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  74. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  75. . "Server: hi\r\n"
  76. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  77. . "Status: 200 OK\r\n"
  78. . "Content-type: application/xml; charset=utf-8\r\n"
  79. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  80. . "Connection: close\r\n"
  81. . "\r\n"
  82. ."<BundleInstanceResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  83. ." <requestId>bun-c1a540a8</requestId>\r\n"
  84. ." <bundleInstanceTask>\r\n"
  85. ." <instanceId>i-12345678</instanceId>\r\n"
  86. ." <bundleId>bun-cla322b9</bundleId>\r\n"
  87. ." <state>bundling</state>\r\n"
  88. ." <startTime>2008-10-07T11:41:50.000Z</startTime>\r\n"
  89. ." <updateTime>2008-10-07T11:51:50.000Z</updateTime>\r\n"
  90. ." <progress>20%</progress>\r\n"
  91. ." <storage>\r\n"
  92. ." <S3>\r\n"
  93. ." <bucket>my-bucket</bucket>\r\n"
  94. ." <prefix>my-new-image</prefix>\r\n"
  95. ." </S3>\r\n"
  96. ." </storage>\r\n"
  97. ." </bundleInstanceTask>\r\n"
  98. ."</BundleInstanceResponse>";
  99. $this->adapter->setResponse($rawHttpResponse);
  100. $return = $this->Zend_Service_Amazon_Ec2_Instance_Windows->bundle('i-12345678', 'my-bucket', 'my-new-image');
  101. print_r($return);
  102. $arrReturn = array(
  103. "instanceId" => "i-12345678",
  104. "bundleId" => "bun-cla322b9",
  105. "state" => "bundling",
  106. "startTime" => "2008-10-07T11:41:50.000Z",
  107. "updateTime" => "2008-10-07T11:51:50.000Z",
  108. "progress" => "20%",
  109. "storage" => array(
  110. "s3" => array
  111. (
  112. "bucket" => "my-bucket",
  113. "prefix" => "my-new-image"
  114. )
  115. )
  116. );
  117. $this->assertSame($arrReturn, $return);
  118. }
  119. /**
  120. * Tests Zend_Service_Amazon_Ec2_Instance_Windows->cancelBundle()
  121. */
  122. public function testCancelBundle()
  123. {
  124. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  125. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  126. . "Server: hi\r\n"
  127. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  128. . "Status: 200 OK\r\n"
  129. . "Content-type: application/xml; charset=utf-8\r\n"
  130. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  131. . "Connection: close\r\n"
  132. . "\r\n"
  133. ."<CancelBundleTaskResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  134. ." <bundleInstanceTask>\r\n"
  135. ." <instanceId>i-12345678</instanceId>\r\n"
  136. ." <bundleId>bun-cla322b9</bundleId>\r\n"
  137. ." <state>canceling</state>\r\n"
  138. ." <startTime>2008-10-07T11:41:50.000Z</startTime>\r\n"
  139. ." <updateTime>2008-10-07T11:51:50.000Z</updateTime>\r\n"
  140. ." <progress>20%</progress>\r\n"
  141. ." <storage>\r\n"
  142. ." <S3>\r\n"
  143. ." <bucket>my-bucket</bucket>\r\n"
  144. ." <prefix>my-new-image</prefix>\r\n"
  145. ." </S3>\r\n"
  146. ." </storage>\r\n"
  147. ." </bundleInstanceTask>\r\n"
  148. ."</CancelBundleTaskResponse>";
  149. $this->adapter->setResponse($rawHttpResponse);
  150. $return = $this->Zend_Service_Amazon_Ec2_Instance_Windows->cancelBundle('bun-cla322b9');
  151. $arrReturn = array( "instanceId" => "i-12345678",
  152. "bundleId" => "bun-cla322b9",
  153. "state" => "canceling",
  154. "startTime" => "2008-10-07T11:41:50.000Z",
  155. "updateTime" => "2008-10-07T11:51:50.000Z",
  156. "progress" => "20%",
  157. "storage" => array(
  158. "s3" => array
  159. (
  160. "bucket" => "my-bucket",
  161. "prefix" => "my-new-image"
  162. )
  163. )
  164. );
  165. $this->assertSame($arrReturn, $return);
  166. }
  167. /**
  168. * Tests Zend_Service_Amazon_Ec2_Instance_Windows->describeBundle()
  169. */
  170. public function testDescribeBundle()
  171. {
  172. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  173. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  174. . "Server: hi\r\n"
  175. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  176. . "Status: 200 OK\r\n"
  177. . "Content-type: application/xml; charset=utf-8\r\n"
  178. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  179. . "Connection: close\r\n"
  180. . "\r\n"
  181. ."<DescribeBundleTasksResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  182. ." <bundleInstanceTasksSet>\r\n"
  183. ." <item>\r\n"
  184. ." <instanceId>i-12345678</instanceId>\r\n"
  185. ." <bundleId>bun-cla322b9</bundleId>\r\n"
  186. ." <state>bundling</state>\r\n"
  187. ." <startTime>2008-10-07T11:41:50.000Z</startTime>\r\n"
  188. ." <updateTime>2008-10-07T11:51:50.000Z</updateTime>\r\n"
  189. ." <progress>20%</progress>\r\n"
  190. ." <storage>\r\n"
  191. ." <S3>\r\n"
  192. ." <bucket>my-bucket</bucket>\r\n"
  193. ." <prefix>my-new-image</prefix>\r\n"
  194. ." </S3>\r\n"
  195. ." </storage>\r\n"
  196. ." </item>\r\n"
  197. ." </bundleInstanceTasksSet>\r\n"
  198. ."</DescribeBundleTasksResponse>";
  199. $this->adapter->setResponse($rawHttpResponse);
  200. $return = $this->Zend_Service_Amazon_Ec2_Instance_Windows->describeBundle('bun-cla322b9');
  201. $arrReturn = array(
  202. array(
  203. "instanceId" => "i-12345678",
  204. "bundleId" => "bun-cla322b9",
  205. "state" => "bundling",
  206. "startTime" => "2008-10-07T11:41:50.000Z",
  207. "updateTime" => "2008-10-07T11:51:50.000Z",
  208. "progress" => "20%",
  209. "storage" => array(
  210. "s3" => array
  211. (
  212. "bucket" => "my-bucket",
  213. "prefix" => "my-new-image"
  214. )
  215. )
  216. )
  217. );
  218. $this->assertSame($arrReturn, $return);
  219. }
  220. }