InstanceWindowsTest.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. require_once 'Zend/Service/Amazon/Ec2/Instance/Windows.php';
  3. require_once 'Zend/Http/Client.php';
  4. require_once 'Zend/Http/Client/Adapter/Test.php';
  5. require_once 'PHPUnit/Framework/TestCase.php';
  6. /**
  7. * Zend_Service_Amazon_Ec2_Instance_Windows test case.
  8. */
  9. class InstanceWindowsTest extends PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * @var Zend_Service_Amazon_Ec2_Instance_Windows
  13. */
  14. private $Zend_Service_Amazon_Ec2_Instance_Windows;
  15. /**
  16. * Prepares the environment before running a test.
  17. */
  18. protected function setUp()
  19. {
  20. parent::setUp();
  21. $this->Zend_Service_Amazon_Ec2_Instance_Windows = new Zend_Service_Amazon_Ec2_Instance_Windows('access_key', 'secret_access_key');
  22. $adapter = new Zend_Http_Client_Adapter_Test();
  23. $client = new Zend_Http_Client(null, array(
  24. 'adapter' => $adapter
  25. ));
  26. $this->adapter = $adapter;
  27. Zend_Service_Amazon_Ec2_Instance_Windows::setHttpClient($client);
  28. }
  29. /**
  30. * Cleans up the environment after running a test.
  31. */
  32. protected function tearDown()
  33. {
  34. unset($this->adapter);
  35. $this->Zend_Service_Amazon_Ec2_Instance_Windows = null;
  36. parent::tearDown();
  37. }
  38. /**
  39. * Tests Zend_Service_Amazon_Ec2_Instance_Windows->bundle()
  40. */
  41. public function testBundle()
  42. {
  43. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  44. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  45. . "Server: hi\r\n"
  46. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  47. . "Status: 200 OK\r\n"
  48. . "Content-type: application/xml; charset=utf-8\r\n"
  49. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  50. . "Connection: close\r\n"
  51. . "\r\n"
  52. ."<BundleInstanceResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  53. ." <requestId>bun-c1a540a8</requestId>\r\n"
  54. ." <bundleInstanceTask>\r\n"
  55. ." <instanceId>i-12345678</instanceId>\r\n"
  56. ." <bundleId>bun-cla322b9</bundleId>\r\n"
  57. ." <state>bundling</state>\r\n"
  58. ." <startTime>2008-10-07T11:41:50.000Z</startTime>\r\n"
  59. ." <updateTime>2008-10-07T11:51:50.000Z</updateTime>\r\n"
  60. ." <progress>20%</progress>\r\n"
  61. ." <storage>\r\n"
  62. ." <S3>\r\n"
  63. ." <bucket>my-bucket</bucket>\r\n"
  64. ." <prefix>my-new-image</prefix>\r\n"
  65. ." </S3>\r\n"
  66. ." </storage>\r\n"
  67. ." </bundleInstanceTask>\r\n"
  68. ."</BundleInstanceResponse>";
  69. $this->adapter->setResponse($rawHttpResponse);
  70. $return = $this->Zend_Service_Amazon_Ec2_Instance_Windows->bundle('i-12345678', 'my-bucket', 'my-new-image');
  71. print_r($return);
  72. $arrReturn = array(
  73. "instanceId" => "i-12345678",
  74. "bundleId" => "bun-cla322b9",
  75. "state" => "bundling",
  76. "startTime" => "2008-10-07T11:41:50.000Z",
  77. "updateTime" => "2008-10-07T11:51:50.000Z",
  78. "progress" => "20%",
  79. "storage" => array(
  80. "s3" => array
  81. (
  82. "bucket" => "my-bucket",
  83. "prefix" => "my-new-image"
  84. )
  85. )
  86. );
  87. $this->assertSame($arrReturn, $return);
  88. }
  89. /**
  90. * Tests Zend_Service_Amazon_Ec2_Instance_Windows->cancelBundle()
  91. */
  92. public function testCancelBundle()
  93. {
  94. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  95. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  96. . "Server: hi\r\n"
  97. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  98. . "Status: 200 OK\r\n"
  99. . "Content-type: application/xml; charset=utf-8\r\n"
  100. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  101. . "Connection: close\r\n"
  102. . "\r\n"
  103. ."<CancelBundleTaskResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  104. ." <bundleInstanceTask>\r\n"
  105. ." <instanceId>i-12345678</instanceId>\r\n"
  106. ." <bundleId>bun-cla322b9</bundleId>\r\n"
  107. ." <state>canceling</state>\r\n"
  108. ." <startTime>2008-10-07T11:41:50.000Z</startTime>\r\n"
  109. ." <updateTime>2008-10-07T11:51:50.000Z</updateTime>\r\n"
  110. ." <progress>20%</progress>\r\n"
  111. ." <storage>\r\n"
  112. ." <S3>\r\n"
  113. ." <bucket>my-bucket</bucket>\r\n"
  114. ." <prefix>my-new-image</prefix>\r\n"
  115. ." </S3>\r\n"
  116. ." </storage>\r\n"
  117. ." </bundleInstanceTask>\r\n"
  118. ."</CancelBundleTaskResponse>";
  119. $this->adapter->setResponse($rawHttpResponse);
  120. $return = $this->Zend_Service_Amazon_Ec2_Instance_Windows->cancelBundle('bun-cla322b9');
  121. $arrReturn = array( "instanceId" => "i-12345678",
  122. "bundleId" => "bun-cla322b9",
  123. "state" => "canceling",
  124. "startTime" => "2008-10-07T11:41:50.000Z",
  125. "updateTime" => "2008-10-07T11:51:50.000Z",
  126. "progress" => "20%",
  127. "storage" => array(
  128. "s3" => array
  129. (
  130. "bucket" => "my-bucket",
  131. "prefix" => "my-new-image"
  132. )
  133. )
  134. );
  135. $this->assertSame($arrReturn, $return);
  136. }
  137. /**
  138. * Tests Zend_Service_Amazon_Ec2_Instance_Windows->describeBundle()
  139. */
  140. public function testDescribeBundle()
  141. {
  142. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  143. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  144. . "Server: hi\r\n"
  145. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  146. . "Status: 200 OK\r\n"
  147. . "Content-type: application/xml; charset=utf-8\r\n"
  148. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  149. . "Connection: close\r\n"
  150. . "\r\n"
  151. ."<DescribeBundleTasksResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  152. ." <bundleInstanceTasksSet>\r\n"
  153. ." <item>\r\n"
  154. ." <instanceId>i-12345678</instanceId>\r\n"
  155. ." <bundleId>bun-cla322b9</bundleId>\r\n"
  156. ." <state>bundling</state>\r\n"
  157. ." <startTime>2008-10-07T11:41:50.000Z</startTime>\r\n"
  158. ." <updateTime>2008-10-07T11:51:50.000Z</updateTime>\r\n"
  159. ." <progress>20%</progress>\r\n"
  160. ." <storage>\r\n"
  161. ." <S3>\r\n"
  162. ." <bucket>my-bucket</bucket>\r\n"
  163. ." <prefix>my-new-image</prefix>\r\n"
  164. ." </S3>\r\n"
  165. ." </storage>\r\n"
  166. ." </item>\r\n"
  167. ." </bundleInstanceTasksSet>\r\n"
  168. ."</DescribeBundleTasksResponse>";
  169. $this->adapter->setResponse($rawHttpResponse);
  170. $return = $this->Zend_Service_Amazon_Ec2_Instance_Windows->describeBundle('bun-cla322b9');
  171. $arrReturn = array(
  172. array(
  173. "instanceId" => "i-12345678",
  174. "bundleId" => "bun-cla322b9",
  175. "state" => "bundling",
  176. "startTime" => "2008-10-07T11:41:50.000Z",
  177. "updateTime" => "2008-10-07T11:51:50.000Z",
  178. "progress" => "20%",
  179. "storage" => array(
  180. "s3" => array
  181. (
  182. "bucket" => "my-bucket",
  183. "prefix" => "my-new-image"
  184. )
  185. )
  186. )
  187. );
  188. $this->assertSame($arrReturn, $return);
  189. }
  190. }