ImageTest.php 28 KB

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