InstanceWindowsTest.php 9.7 KB

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