InstanceReservedTest.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 'Zend/Service/Amazon/Ec2/Instance/Reserved.php';
  23. require_once 'Zend/Http/Client.php';
  24. require_once 'Zend/Http/Client/Adapter/Test.php';
  25. require_once 'PHPUnit/Framework/TestCase.php';
  26. /**
  27. * Zend_Service_Amazon_Ec2_Instance_Reserved test case.
  28. * @todo Should this class be named Zend_Service_Amazon_Ec2_Instance_ReservedTest?
  29. *
  30. * @category Zend
  31. * @package Zend_Service_Amazon
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @group Zend_Service
  36. * @group Zend_Service_Amazon
  37. * @group Zend_Service_Amazon_Ec2
  38. */
  39. class InstanceReservedTest extends PHPUnit_Framework_TestCase
  40. {
  41. /**
  42. * @var Zend_Service_Amazon_Ec2_Instance_Reserved
  43. */
  44. private $Zend_Service_Amazon_Ec2_Instance_Reserved;
  45. /**
  46. * Prepares the environment before running a test.
  47. */
  48. protected function setUp()
  49. {
  50. parent::setUp();
  51. $this->Zend_Service_Amazon_Ec2_Instance_Reserved = new Zend_Service_Amazon_Ec2_Instance_Reserved('access_key', 'secret_access_key');
  52. $adapter = new Zend_Http_Client_Adapter_Test();
  53. $client = new Zend_Http_Client(null, array(
  54. 'adapter' => $adapter
  55. ));
  56. $this->adapter = $adapter;
  57. Zend_Service_Amazon_Ec2_Instance_Reserved::setHttpClient($client);
  58. }
  59. /**
  60. * Cleans up the environment after running a test.
  61. */
  62. protected function tearDown()
  63. {
  64. unset($this->adapter);
  65. $this->Zend_Service_Amazon_Ec2_Instance_Reserved = null;
  66. parent::tearDown();
  67. }
  68. /**
  69. * Tests Zend_Service_Amazon_Ec2_Instance_Reserved->describeInstances()
  70. */
  71. public function testDescribeInstances()
  72. {
  73. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  74. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  75. . "Server: hi\r\n"
  76. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  77. . "Status: 200 OK\r\n"
  78. . "Content-type: application/xml; charset=utf-8\r\n"
  79. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  80. . "Connection: close\r\n"
  81. . "\r\n"
  82. ."<DescribeReservedInstancesResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  83. ." <reservedInstancesSet>\r\n"
  84. ." <item>\r\n"
  85. ." <reservedInstancesId>4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8</reservedInstancesId>\r\n"
  86. ." <instanceType>m1.small</instanceType>\r\n"
  87. ." <availabilityZone>us-east-1a</availabilityZone>\r\n"
  88. ." <duration>12</duration>\r\n"
  89. ." <usagePrice>0.00</usagePrice>\r\n"
  90. ." <fixedPrice>0.00</fixedPrice>\r\n"
  91. ." <instanceCount>19</instanceCount>\r\n"
  92. ." <productDescription>m1.small offering in us-east-1a</productDescription>\r\n"
  93. ." <state>Active</state>\r\n"
  94. ." </item>\r\n"
  95. ." </reservedInstancesSet>\r\n"
  96. ."</DescribeReservedInstancesResponse>";
  97. $this->adapter->setResponse($rawHttpResponse);
  98. $return = $this->Zend_Service_Amazon_Ec2_Instance_Reserved->describeInstances('4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8');
  99. $arrReturn = array(
  100. array(
  101. "reservedInstancesId" => "4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8",
  102. "instanceType" => "m1.small",
  103. "availabilityZone" => "us-east-1a",
  104. "duration" => "12",
  105. "fixedPrice" => "0.00",
  106. "usagePrice" => "0.00",
  107. "productDescription" => "m1.small offering in us-east-1a",
  108. "instanceCount" => "19",
  109. "state" => "Active"
  110. )
  111. );
  112. $this->assertSame($arrReturn, $return);
  113. }
  114. /**
  115. * Tests Zend_Service_Amazon_Ec2_Instance_Reserved->describeOfferings()
  116. */
  117. public function testDescribeOfferings()
  118. {
  119. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  120. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  121. . "Server: hi\r\n"
  122. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  123. . "Status: 200 OK\r\n"
  124. . "Content-type: application/xml; charset=utf-8\r\n"
  125. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  126. . "Connection: close\r\n"
  127. . "\r\n"
  128. ."<DescribeReservedInstancesOfferingsResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  129. ." <reservedInstancesOfferingsSet>\r\n"
  130. ." <item>\r\n"
  131. ." <reservedInstancesOfferingId>4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8</reservedInstancesOfferingId>\r\n"
  132. ." <instanceType>m1.small</instanceType>\r\n"
  133. ." <availabilityZone>us-east-1a</availabilityZone>\r\n"
  134. ." <duration>12</duration>\r\n"
  135. ." <usagePrice>0.00</usagePrice>\r\n"
  136. ." <fixedPrice>0.00</fixedPrice>\r\n"
  137. ." <productDescription>m1.small offering in us-east-1a</productDescription>\r\n"
  138. ." </item>\r\n"
  139. ." </reservedInstancesOfferingsSet>\r\n"
  140. ."</DescribeReservedInstancesOfferingsResponse>";
  141. $this->adapter->setResponse($rawHttpResponse);
  142. $return = $this->Zend_Service_Amazon_Ec2_Instance_Reserved->describeOfferings();
  143. $arrReturn = array(
  144. array(
  145. "reservedInstancesOfferingId" => "4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8",
  146. "instanceType" => "m1.small",
  147. "availabilityZone" => "us-east-1a",
  148. "duration" => "12",
  149. "fixedPrice" => "0.00",
  150. "usagePrice" => "0.00",
  151. "productDescription" => "m1.small offering in us-east-1a",
  152. )
  153. );
  154. $this->assertSame($arrReturn, $return);
  155. }
  156. /**
  157. * Tests Zend_Service_Amazon_Ec2_Instance_Reserved->purchaseOffering()
  158. */
  159. public function testPurchaseOffering()
  160. {
  161. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  162. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  163. . "Server: hi\r\n"
  164. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  165. . "Status: 200 OK\r\n"
  166. . "Content-type: application/xml; charset=utf-8\r\n"
  167. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  168. . "Connection: close\r\n"
  169. . "\r\n"
  170. ."<PurchaseReservedInstancesOfferingResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  171. ." <reservedInstancesId>4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8</reservedInstancesId>\r\n"
  172. ."</PurchaseReservedInstancesOfferingResponse>";
  173. $this->adapter->setResponse($rawHttpResponse);
  174. $return = $this->Zend_Service_Amazon_Ec2_Instance_Reserved->purchaseOffering('4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8');
  175. $this->assertSame('4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8', $return);
  176. }
  177. }