2
0

ImageTest.php 28 KB

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