InstanceReservedTest.php 8.0 KB

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