ImageTest.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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-2014 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/Http/Client.php';
  23. require_once 'Zend/Http/Client/Adapter/Test.php';
  24. require_once 'Zend/Service/Amazon/Ec2/Image.php';
  25. /**
  26. * Zend_Service_Amazon_Ec2_Image test case.
  27. *
  28. * @category Zend
  29. * @package Zend_Service_Amazon
  30. * @subpackage UnitTests
  31. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. * @group Zend_Service
  34. * @group Zend_Service_Amazon
  35. * @group Zend_Service_Amazon_Ec2
  36. */
  37. class Zend_Service_Amazon_Ec2_ImageTest extends PHPUnit_Framework_TestCase
  38. {
  39. /**
  40. * @var Zend_Service_Amazon_Ec2_Image
  41. */
  42. private $Zend_Service_Amazon_Ec2_Image;
  43. /**
  44. * Prepares the environment before running a test.
  45. */
  46. protected function setUp()
  47. {
  48. parent::setUp();
  49. $this->Zend_Service_Amazon_Ec2_Image = new Zend_Service_Amazon_Ec2_Image('access_key', 'secret_access_key');
  50. $adapter = new Zend_Http_Client_Adapter_Test();
  51. $client = new Zend_Http_Client(null, array(
  52. 'adapter' => $adapter
  53. ));
  54. $this->adapter = $adapter;
  55. Zend_Service_Amazon_Ec2_Image::setHttpClient($client);
  56. }
  57. protected function tearDown()
  58. {
  59. $this->Zend_Service_Amazon_Ec2_Image = null;
  60. parent::tearDown();
  61. }
  62. public function testDeregister()
  63. {
  64. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  65. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  66. . "Server: hi\r\n"
  67. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  68. . "Status: 200 OK\r\n"
  69. . "Content-type: application/xml; charset=utf-8\r\n"
  70. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  71. . "Connection: close\r\n"
  72. . "\r\n"
  73. . "<DeregisterImageResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  74. . " <return>true</return>\r\n"
  75. . "</DeregisterImageResponse>\r\n";
  76. $this->adapter->setResponse($rawHttpResponse);
  77. $return = $this->Zend_Service_Amazon_Ec2_Image->deregister('ami-61a54008');
  78. $this->assertTrue($return);
  79. }
  80. public function testDescribeSingleImageMultipleImagesByIds()
  81. {
  82. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  83. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  84. . "Server: hi\r\n"
  85. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  86. . "Status: 200 OK\r\n"
  87. . "Content-type: application/xml; charset=utf-8\r\n"
  88. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  89. . "Connection: close\r\n"
  90. . "\r\n"
  91. . "<DescribeImagesResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  92. . " <imagesSet>\r\n"
  93. . " <item>\r\n"
  94. . " <imageId>ami-be3adfd7</imageId>\r\n"
  95. . " <imageLocation>ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml</imageLocation>\r\n"
  96. . " <imageState>available</imageState>\r\n"
  97. . " <imageOwnerId>206029621532</imageOwnerId>\r\n"
  98. . " <isPublic>false</isPublic>\r\n"
  99. . " <architecture>i386</architecture>\r\n"
  100. . " <imageType>machine</imageType>\r\n"
  101. . " <kernelId>aki-4438dd2d</kernelId>\r\n"
  102. . " <ramdiskId>ari-4538dd2c</ramdiskId>\r\n"
  103. . " </item>\r\n"
  104. . " <item>\r\n"
  105. . " <imageId>ami-be3adfd6</imageId>\r\n"
  106. . " <imageLocation>ec2-public-images/ubuntu-8.10-i386-base-v1.04.manifest.xml</imageLocation>\r\n"
  107. . " <imageState>available</imageState>\r\n"
  108. . " <imageOwnerId>206029621532</imageOwnerId>\r\n"
  109. . " <isPublic>true</isPublic>\r\n"
  110. . " <architecture>i386</architecture>\r\n"
  111. . " <imageType>machine</imageType>\r\n"
  112. . " <kernelId>aki-4438dd2d</kernelId>\r\n"
  113. . " <ramdiskId>ari-4538dd2c</ramdiskId>\r\n"
  114. . " </item>\r\n"
  115. . " </imagesSet>\r\n"
  116. . "</DescribeImagesResponse>";
  117. $this->adapter->setResponse($rawHttpResponse);
  118. $return = $this->Zend_Service_Amazon_Ec2_Image->describe(array('ami-be3adfd7', 'ami-be3adfd6'));
  119. $arrImage = array(
  120. array(
  121. 'imageId' => 'ami-be3adfd7',
  122. 'imageLocation' => 'ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml',
  123. 'imageState' => 'available',
  124. 'imageOwnerId' => '206029621532',
  125. 'isPublic' => 'false',
  126. 'architecture' => 'i386',
  127. 'imageType' => 'machine',
  128. 'kernelId' => 'aki-4438dd2d',
  129. 'ramdiskId' => 'ari-4538dd2c',
  130. 'platform' => '',
  131. ),
  132. array(
  133. 'imageId' => 'ami-be3adfd6',
  134. 'imageLocation' => 'ec2-public-images/ubuntu-8.10-i386-base-v1.04.manifest.xml',
  135. 'imageState' => 'available',
  136. 'imageOwnerId' => '206029621532',
  137. 'isPublic' => 'true',
  138. 'architecture' => 'i386',
  139. 'imageType' => 'machine',
  140. 'kernelId' => 'aki-4438dd2d',
  141. 'ramdiskId' => 'ari-4538dd2c',
  142. 'platform' => '',
  143. )
  144. );
  145. $this->assertSame($arrImage, $return);
  146. }
  147. public function testDescribeSingleImageById()
  148. {
  149. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  150. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  151. . "Server: hi\r\n"
  152. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  153. . "Status: 200 OK\r\n"
  154. . "Content-type: application/xml; charset=utf-8\r\n"
  155. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  156. . "Connection: close\r\n"
  157. . "\r\n"
  158. . "<DescribeImagesResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  159. . " <imagesSet>\r\n"
  160. . " <item>\r\n"
  161. . " <imageId>ami-be3adfd7</imageId>\r\n"
  162. . " <imageLocation>ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml</imageLocation>\r\n"
  163. . " <imageState>available</imageState>\r\n"
  164. . " <imageOwnerId>206029621532</imageOwnerId>\r\n"
  165. . " <isPublic>false</isPublic>\r\n"
  166. . " <architecture>i386</architecture>\r\n"
  167. . " <imageType>machine</imageType>\r\n"
  168. . " <kernelId>aki-4438dd2d</kernelId>\r\n"
  169. . " <ramdiskId>ari-4538dd2c</ramdiskId>\r\n"
  170. . " </item>\r\n"
  171. . " </imagesSet>\r\n"
  172. . "</DescribeImagesResponse>";
  173. $this->adapter->setResponse($rawHttpResponse);
  174. $return = $this->Zend_Service_Amazon_Ec2_Image->describe('ami-be3adfd7');
  175. $arrImage = array(
  176. array(
  177. 'imageId' => 'ami-be3adfd7',
  178. 'imageLocation' => 'ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml',
  179. 'imageState' => 'available',
  180. 'imageOwnerId' => '206029621532',
  181. 'isPublic' => 'false',
  182. 'architecture' => 'i386',
  183. 'imageType' => 'machine',
  184. 'kernelId' => 'aki-4438dd2d',
  185. 'ramdiskId' => 'ari-4538dd2c',
  186. 'platform' => '',
  187. )
  188. );
  189. $this->assertSame($arrImage, $return);
  190. }
  191. public function testDescribeSingleImageMultipleImagesByOwnerId()
  192. {
  193. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  194. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  195. . "Server: hi\r\n"
  196. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  197. . "Status: 200 OK\r\n"
  198. . "Content-type: application/xml; charset=utf-8\r\n"
  199. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  200. . "Connection: close\r\n"
  201. . "\r\n"
  202. . "<DescribeImagesResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  203. . " <imagesSet>\r\n"
  204. . " <item>\r\n"
  205. . " <imageId>ami-be3adfd7</imageId>\r\n"
  206. . " <imageLocation>ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml</imageLocation>\r\n"
  207. . " <imageState>available</imageState>\r\n"
  208. . " <imageOwnerId>2060296256884</imageOwnerId>\r\n"
  209. . " <isPublic>false</isPublic>\r\n"
  210. . " <architecture>i386</architecture>\r\n"
  211. . " <imageType>machine</imageType>\r\n"
  212. . " <kernelId>aki-4438dd2d</kernelId>\r\n"
  213. . " <ramdiskId>ari-4538dd2c</ramdiskId>\r\n"
  214. . " </item>\r\n"
  215. . " <item>\r\n"
  216. . " <imageId>ami-be3adfd6</imageId>\r\n"
  217. . " <imageLocation>ec2-public-images/ubuntu-8.10-i386-base-v1.04.manifest.xml</imageLocation>\r\n"
  218. . " <imageState>available</imageState>\r\n"
  219. . " <imageOwnerId>206029621532</imageOwnerId>\r\n"
  220. . " <isPublic>true</isPublic>\r\n"
  221. . " <architecture>i386</architecture>\r\n"
  222. . " <imageType>machine</imageType>\r\n"
  223. . " <kernelId>aki-4438dd2d</kernelId>\r\n"
  224. . " <ramdiskId>ari-4538dd2c</ramdiskId>\r\n"
  225. . " </item>\r\n"
  226. . " </imagesSet>\r\n"
  227. . "</DescribeImagesResponse>";
  228. $this->adapter->setResponse($rawHttpResponse);
  229. $return = $this->Zend_Service_Amazon_Ec2_Image->describe(null, array('2060296256884', '206029621532'));
  230. $arrImage = array(
  231. array(
  232. 'imageId' => 'ami-be3adfd7',
  233. 'imageLocation' => 'ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml',
  234. 'imageState' => 'available',
  235. 'imageOwnerId' => '2060296256884',
  236. 'isPublic' => 'false',
  237. 'architecture' => 'i386',
  238. 'imageType' => 'machine',
  239. 'kernelId' => 'aki-4438dd2d',
  240. 'ramdiskId' => 'ari-4538dd2c',
  241. 'platform' => '',
  242. ),
  243. array(
  244. 'imageId' => 'ami-be3adfd6',
  245. 'imageLocation' => 'ec2-public-images/ubuntu-8.10-i386-base-v1.04.manifest.xml',
  246. 'imageState' => 'available',
  247. 'imageOwnerId' => '206029621532',
  248. 'isPublic' => 'true',
  249. 'architecture' => 'i386',
  250. 'imageType' => 'machine',
  251. 'kernelId' => 'aki-4438dd2d',
  252. 'ramdiskId' => 'ari-4538dd2c',
  253. 'platform' => '',
  254. )
  255. );
  256. $this->assertSame($arrImage, $return);
  257. }
  258. public function testDescribeSingleImageByOwnerId()
  259. {
  260. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  261. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  262. . "Server: hi\r\n"
  263. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  264. . "Status: 200 OK\r\n"
  265. . "Content-type: application/xml; charset=utf-8\r\n"
  266. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  267. . "Connection: close\r\n"
  268. . "\r\n"
  269. . "<DescribeImagesResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  270. . " <imagesSet>\r\n"
  271. . " <item>\r\n"
  272. . " <imageId>ami-be3adfd7</imageId>\r\n"
  273. . " <imageLocation>ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml</imageLocation>\r\n"
  274. . " <imageState>available</imageState>\r\n"
  275. . " <imageOwnerId>206029621532</imageOwnerId>\r\n"
  276. . " <isPublic>false</isPublic>\r\n"
  277. . " <architecture>i386</architecture>\r\n"
  278. . " <imageType>machine</imageType>\r\n"
  279. . " <kernelId>aki-4438dd2d</kernelId>\r\n"
  280. . " <ramdiskId>ari-4538dd2c</ramdiskId>\r\n"
  281. . " </item>\r\n"
  282. . " </imagesSet>\r\n"
  283. . "</DescribeImagesResponse>";
  284. $this->adapter->setResponse($rawHttpResponse);
  285. $return = $this->Zend_Service_Amazon_Ec2_Image->describe(null, '206029621532');
  286. $arrImage = array(
  287. array(
  288. 'imageId' => 'ami-be3adfd7',
  289. 'imageLocation' => 'ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml',
  290. 'imageState' => 'available',
  291. 'imageOwnerId' => '206029621532',
  292. 'isPublic' => 'false',
  293. 'architecture' => 'i386',
  294. 'imageType' => 'machine',
  295. 'kernelId' => 'aki-4438dd2d',
  296. 'ramdiskId' => 'ari-4538dd2c',
  297. 'platform' => '',
  298. )
  299. );
  300. $this->assertSame($arrImage, $return);
  301. }
  302. public function testDescribeSingleImageMultipleImagesByExecutableBy()
  303. {
  304. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  305. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  306. . "Server: hi\r\n"
  307. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  308. . "Status: 200 OK\r\n"
  309. . "Content-type: application/xml; charset=utf-8\r\n"
  310. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  311. . "Connection: close\r\n"
  312. . "\r\n"
  313. . "<DescribeImagesResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  314. . " <imagesSet>\r\n"
  315. . " <item>\r\n"
  316. . " <imageId>ami-be3adfd7</imageId>\r\n"
  317. . " <imageLocation>ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml</imageLocation>\r\n"
  318. . " <imageState>available</imageState>\r\n"
  319. . " <imageOwnerId>2060296256884</imageOwnerId>\r\n"
  320. . " <isPublic>false</isPublic>\r\n"
  321. . " <architecture>i386</architecture>\r\n"
  322. . " <imageType>machine</imageType>\r\n"
  323. . " <kernelId>aki-4438dd2d</kernelId>\r\n"
  324. . " <ramdiskId>ari-4538dd2c</ramdiskId>\r\n"
  325. . " </item>\r\n"
  326. . " <item>\r\n"
  327. . " <imageId>ami-be3adfd6</imageId>\r\n"
  328. . " <imageLocation>ec2-public-images/ubuntu-8.10-i386-base-v1.04.manifest.xml</imageLocation>\r\n"
  329. . " <imageState>available</imageState>\r\n"
  330. . " <imageOwnerId>206029621532</imageOwnerId>\r\n"
  331. . " <isPublic>true</isPublic>\r\n"
  332. . " <architecture>i386</architecture>\r\n"
  333. . " <imageType>machine</imageType>\r\n"
  334. . " <kernelId>aki-4438dd2d</kernelId>\r\n"
  335. . " <ramdiskId>ari-4538dd2c</ramdiskId>\r\n"
  336. . " </item>\r\n"
  337. . " </imagesSet>\r\n"
  338. . "</DescribeImagesResponse>";
  339. $this->adapter->setResponse($rawHttpResponse);
  340. $return = $this->Zend_Service_Amazon_Ec2_Image->describe(null, null, array('46361432890', '432432265322'));
  341. $arrImage = array(
  342. array(
  343. 'imageId' => 'ami-be3adfd7',
  344. 'imageLocation' => 'ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml',
  345. 'imageState' => 'available',
  346. 'imageOwnerId' => '2060296256884',
  347. 'isPublic' => 'false',
  348. 'architecture' => 'i386',
  349. 'imageType' => 'machine',
  350. 'kernelId' => 'aki-4438dd2d',
  351. 'ramdiskId' => 'ari-4538dd2c',
  352. 'platform' => '',
  353. ),
  354. array(
  355. 'imageId' => 'ami-be3adfd6',
  356. 'imageLocation' => 'ec2-public-images/ubuntu-8.10-i386-base-v1.04.manifest.xml',
  357. 'imageState' => 'available',
  358. 'imageOwnerId' => '206029621532',
  359. 'isPublic' => 'true',
  360. 'architecture' => 'i386',
  361. 'imageType' => 'machine',
  362. 'kernelId' => 'aki-4438dd2d',
  363. 'ramdiskId' => 'ari-4538dd2c',
  364. 'platform' => '',
  365. )
  366. );
  367. $this->assertSame($arrImage, $return);
  368. }
  369. public function testDescribeSingleImageByExecutableBy()
  370. {
  371. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  372. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  373. . "Server: hi\r\n"
  374. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  375. . "Status: 200 OK\r\n"
  376. . "Content-type: application/xml; charset=utf-8\r\n"
  377. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  378. . "Connection: close\r\n"
  379. . "\r\n"
  380. . "<DescribeImagesResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  381. . " <imagesSet>\r\n"
  382. . " <item>\r\n"
  383. . " <imageId>ami-be3adfd7</imageId>\r\n"
  384. . " <imageLocation>ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml</imageLocation>\r\n"
  385. . " <imageState>available</imageState>\r\n"
  386. . " <imageOwnerId>206029621532</imageOwnerId>\r\n"
  387. . " <isPublic>false</isPublic>\r\n"
  388. . " <architecture>i386</architecture>\r\n"
  389. . " <imageType>machine</imageType>\r\n"
  390. . " <kernelId>aki-4438dd2d</kernelId>\r\n"
  391. . " <ramdiskId>ari-4538dd2c</ramdiskId>\r\n"
  392. . " </item>\r\n"
  393. . " </imagesSet>\r\n"
  394. . "</DescribeImagesResponse>";
  395. $this->adapter->setResponse($rawHttpResponse);
  396. $return = $this->Zend_Service_Amazon_Ec2_Image->describe(null, null, '46361432890');
  397. $arrImage = array(
  398. array(
  399. 'imageId' => 'ami-be3adfd7',
  400. 'imageLocation' => 'ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml',
  401. 'imageState' => 'available',
  402. 'imageOwnerId' => '206029621532',
  403. 'isPublic' => 'false',
  404. 'architecture' => 'i386',
  405. 'imageType' => 'machine',
  406. 'kernelId' => 'aki-4438dd2d',
  407. 'ramdiskId' => 'ari-4538dd2c',
  408. 'platform' => '',
  409. )
  410. );
  411. $this->assertSame($arrImage, $return);
  412. }
  413. public function testDescribeAttributeLaunchPermission()
  414. {
  415. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  416. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  417. . "Server: hi\r\n"
  418. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  419. . "Status: 200 OK\r\n"
  420. . "Content-type: application/xml; charset=utf-8\r\n"
  421. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  422. . "Connection: close\r\n"
  423. . "\r\n"
  424. . "<DescribeImageAttributeResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  425. . " <imageId>ami-61a54008</imageId>\r\n"
  426. . " <launchPermission>\r\n"
  427. . " <item>\r\n"
  428. . " <userId>495219933132</userId>\r\n"
  429. . " </item>\r\n"
  430. . " </launchPermission>\r\n"
  431. . "</DescribeImageAttributeResponse>\r\n";
  432. $this->adapter->setResponse($rawHttpResponse);
  433. $return = $this->Zend_Service_Amazon_Ec2_Image->describeAttribute('ami-61a54008', 'launchPermission');
  434. $this->assertEquals('ami-61a54008', $return['imageId']);
  435. $this->assertEquals('495219933132', $return['launchPermission'][0]);
  436. }
  437. public function testDescribeAttributeProductCodes()
  438. {
  439. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  440. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  441. . "Server: hi\r\n"
  442. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  443. . "Status: 200 OK\r\n"
  444. . "Content-type: application/xml; charset=utf-8\r\n"
  445. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  446. . "Connection: close\r\n"
  447. . "\r\n"
  448. . "<DescribeImageAttributeResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  449. . " <imageId>ami-61a54008</imageId>\r\n"
  450. . " <productCodes>\r\n"
  451. . " <item>\r\n"
  452. . " <productCode>774F4FF8</productCode>\r\n"
  453. . " </item>\r\n"
  454. . " </productCodes>\r\n"
  455. . "</DescribeImageAttributeResponse>\r\n";
  456. $this->adapter->setResponse($rawHttpResponse);
  457. $return = $this->Zend_Service_Amazon_Ec2_Image->describeAttribute('ami-61a54008', 'productCodes');
  458. $this->assertEquals('ami-61a54008', $return['imageId']);
  459. $this->assertEquals('774F4FF8', $return['productCodes'][0]);
  460. }
  461. public function testModifyAttributeSingleLaunchPermission()
  462. {
  463. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  464. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  465. . "Server: hi\r\n"
  466. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  467. . "Status: 200 OK\r\n"
  468. . "Content-type: application/xml; charset=utf-8\r\n"
  469. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  470. . "Connection: close\r\n"
  471. . "\r\n"
  472. . "<ModifyImageAttributeResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  473. . " <return>true</return>\r\n"
  474. . "</ModifyImageAttributeResponse>\r\n";
  475. $this->adapter->setResponse($rawHttpResponse);
  476. $return = $this->Zend_Service_Amazon_Ec2_Image->modifyAttribute('ami-61a54008', 'launchPermission', 'add', '495219933132', 'all');
  477. $this->assertTrue($return);
  478. }
  479. public function testModifyAttributeMultipleLaunchPermission()
  480. {
  481. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  482. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  483. . "Server: hi\r\n"
  484. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  485. . "Status: 200 OK\r\n"
  486. . "Content-type: application/xml; charset=utf-8\r\n"
  487. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  488. . "Connection: close\r\n"
  489. . "\r\n"
  490. . "<ModifyImageAttributeResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  491. . " <return>true</return>\r\n"
  492. . "</ModifyImageAttributeResponse>\r\n";
  493. $this->adapter->setResponse($rawHttpResponse);
  494. $return = $this->Zend_Service_Amazon_Ec2_Image->modifyAttribute('ami-61a54008', 'launchPermission', 'add', array('495219933132', '495219933133'), array('all', 'all'));
  495. $this->assertTrue($return);
  496. }
  497. public function testModifyAttributeThrowsExceptionOnInvalidAttribute()
  498. {
  499. try {
  500. $return = $this->Zend_Service_Amazon_Ec2_Image->modifyAttribute('ami-61a54008', 'invalidPermission', 'add', '495219933132', 'all');
  501. $this->fail('An exception should be throw if you are modifying an invalid attirubte');
  502. } catch (Zend_Service_Amazon_Ec2_Exception $zsaee) {}
  503. }
  504. public function testModifyAttributeProuctCodes()
  505. {
  506. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  507. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  508. . "Server: hi\r\n"
  509. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  510. . "Status: 200 OK\r\n"
  511. . "Content-type: application/xml; charset=utf-8\r\n"
  512. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  513. . "Connection: close\r\n"
  514. . "\r\n"
  515. . "<ModifyImageAttributeResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  516. . " <return>true</return>\r\n"
  517. . "</ModifyImageAttributeResponse>\r\n";
  518. $this->adapter->setResponse($rawHttpResponse);
  519. $return = $this->Zend_Service_Amazon_Ec2_Image->modifyAttribute('ami-61a54008', 'productCodes', null, null, null, '774F4FF8');
  520. $this->assertTrue($return);
  521. }
  522. public function testRegister()
  523. {
  524. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  525. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  526. . "Server: hi\r\n"
  527. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  528. . "Status: 200 OK\r\n"
  529. . "Content-type: application/xml; charset=utf-8\r\n"
  530. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  531. . "Connection: close\r\n"
  532. . "\r\n"
  533. . "<RegisterImageResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  534. . " <imageId>ami-61a54008</imageId>\r\n"
  535. . "</RegisterImageResponse>\r\n";
  536. $this->adapter->setResponse($rawHttpResponse);
  537. $return = $this->Zend_Service_Amazon_Ec2_Image->register('mybucket-myimage.manifest.xml');
  538. $this->assertEquals('ami-61a54008', $return);
  539. }
  540. public function testResetAttribute()
  541. {
  542. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  543. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  544. . "Server: hi\r\n"
  545. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  546. . "Status: 200 OK\r\n"
  547. . "Content-type: application/xml; charset=utf-8\r\n"
  548. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  549. . "Connection: close\r\n"
  550. . "\r\n"
  551. . "<ResetImageAttributeResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  552. . " <return>true</return>\r\n"
  553. . "</ResetImageAttributeResponse>\r\n";
  554. $this->adapter->setResponse($rawHttpResponse);
  555. $return = $this->Zend_Service_Amazon_Ec2_Image->resetAttribute('ami-61a54008', 'launchPermission');
  556. $this->assertTrue($return);
  557. }
  558. }