InstanceReservedTest.php 8.1 KB

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