Zend_Service_Amazon_Ec2_Elasticip = new Zend_Service_Amazon_Ec2_Elasticip('access_key', 'secret_access_key'); $adapter = new Zend_Http_Client_Adapter_Test(); $client = new Zend_Http_Client(null, array( 'adapter' => $adapter )); $this->adapter = $adapter; Zend_Service_Amazon_Ec2_Elasticip::setHttpClient($client); } /** * Cleans up the environment after running a test. */ protected function tearDown() { unset($this->adapter); $this->Zend_Service_Amazon_Ec2_Elasticip = null; parent::tearDown(); } public function testAllocateNewElasticIp() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . " 67.202.55.255\r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $ipAddress = $this->Zend_Service_Amazon_Ec2_Elasticip->allocate(); $this->assertEquals('67.202.55.255', $ipAddress); } public function testAssociateElasticIpWithInstanceReturnsTrue() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . " true\r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $return = $this->Zend_Service_Amazon_Ec2_Elasticip->associate('67.202.55.255', 'i-ag8ga0a'); $this->assertTrue($return); } /** * Tests Zend_Service_Amazon_Ec2_Elasticip->describe() */ public function testDescribeSingleElasticIp() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . " \r\n" . " \r\n" . " 67.202.55.255\r\n" . " i-ag8ga0a\r\n" . " \r\n" . " \r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $response = $this->Zend_Service_Amazon_Ec2_Elasticip->describe('67.202.55.255'); $arrIp = array( 'publicIp' => '67.202.55.255', 'instanceId' => 'i-ag8ga0a' ); $this->assertSame($arrIp, $response[0]); } public function testDescribeMultipleElasticIp() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . " \r\n" . " \r\n" . " 67.202.55.255\r\n" . " i-ag8ga0a\r\n" . " \r\n" . " \r\n" . " 67.202.55.200\r\n" . " i-aauoi9g\r\n" . " \r\n" . " \r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $response = $this->Zend_Service_Amazon_Ec2_Elasticip->describe(array('67.202.55.255', '67.202.55.200')); $arrIps = array( array( 'publicIp' => '67.202.55.255', 'instanceId' => 'i-ag8ga0a' ), array( 'publicIp' => '67.202.55.200', 'instanceId' => 'i-aauoi9g' ) ); foreach($response as $k => $r) { $this->assertSame($arrIps[$k], $r); } } /** * Tests Zend_Service_Amazon_Ec2_Elasticip->disassocate() */ public function testDisassocateElasticIpFromInstance() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . " true\r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $return = $this->Zend_Service_Amazon_Ec2_Elasticip->disassocate('67.202.55.255'); $this->assertTrue($return); } /** * Tests Zend_Service_Amazon_Ec2_Elasticip->release() */ public function testReleaseElasticIp() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . " true\r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $return = $this->Zend_Service_Amazon_Ec2_Elasticip->release('67.202.55.255'); $this->assertTrue($return); } }