InstanceWindowsTest.php 9.6 KB

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