2
0

ImageTest.php 28 KB

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