Zend_Service_Amazon_Ec2_Image = new Zend_Service_Amazon_Ec2_Image('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_Image::setHttpClient($client);
}
protected function tearDown()
{
$this->Zend_Service_Amazon_Ec2_Image = null;
parent::tearDown();
}
public function testDeregister()
{
$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"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Image->deregister('ami-61a54008');
$this->assertTrue($return);
}
public function testDescribeSingleImageMultipleImagesByIds()
{
$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"
. " ami-be3adfd7\r\n"
. " ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml\r\n"
. " available\r\n"
. " 206029621532\r\n"
. " false\r\n"
. " i386\r\n"
. " machine\r\n"
. " aki-4438dd2d\r\n"
. " ari-4538dd2c\r\n"
. "
\r\n"
. " - \r\n"
. " ami-be3adfd6\r\n"
. " ec2-public-images/ubuntu-8.10-i386-base-v1.04.manifest.xml\r\n"
. " available\r\n"
. " 206029621532\r\n"
. " true\r\n"
. " i386\r\n"
. " machine\r\n"
. " aki-4438dd2d\r\n"
. " ari-4538dd2c\r\n"
. "
\r\n"
. " \r\n"
. "";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Image->describe(array('ami-be3adfd7', 'ami-be3adfd6'));
$arrImage = array(
array(
'imageId' => 'ami-be3adfd7',
'imageLocation' => 'ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml',
'imageState' => 'available',
'imageOwnerId' => '206029621532',
'isPublic' => 'false',
'architecture' => 'i386',
'imageType' => 'machine',
'kernelId' => 'aki-4438dd2d',
'ramdiskId' => 'ari-4538dd2c',
'platform' => '',
),
array(
'imageId' => 'ami-be3adfd6',
'imageLocation' => 'ec2-public-images/ubuntu-8.10-i386-base-v1.04.manifest.xml',
'imageState' => 'available',
'imageOwnerId' => '206029621532',
'isPublic' => 'true',
'architecture' => 'i386',
'imageType' => 'machine',
'kernelId' => 'aki-4438dd2d',
'ramdiskId' => 'ari-4538dd2c',
'platform' => '',
)
);
$this->assertSame($arrImage, $return);
}
public function testDescribeSingleImageById()
{
$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"
. " ami-be3adfd7\r\n"
. " ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml\r\n"
. " available\r\n"
. " 206029621532\r\n"
. " false\r\n"
. " i386\r\n"
. " machine\r\n"
. " aki-4438dd2d\r\n"
. " ari-4538dd2c\r\n"
. "
\r\n"
. " \r\n"
. "";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Image->describe('ami-be3adfd7');
$arrImage = array(
array(
'imageId' => 'ami-be3adfd7',
'imageLocation' => 'ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml',
'imageState' => 'available',
'imageOwnerId' => '206029621532',
'isPublic' => 'false',
'architecture' => 'i386',
'imageType' => 'machine',
'kernelId' => 'aki-4438dd2d',
'ramdiskId' => 'ari-4538dd2c',
'platform' => '',
)
);
$this->assertSame($arrImage, $return);
}
public function testDescribeSingleImageMultipleImagesByOwnerId()
{
$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"
. " ami-be3adfd7\r\n"
. " ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml\r\n"
. " available\r\n"
. " 2060296256884\r\n"
. " false\r\n"
. " i386\r\n"
. " machine\r\n"
. " aki-4438dd2d\r\n"
. " ari-4538dd2c\r\n"
. "
\r\n"
. " - \r\n"
. " ami-be3adfd6\r\n"
. " ec2-public-images/ubuntu-8.10-i386-base-v1.04.manifest.xml\r\n"
. " available\r\n"
. " 206029621532\r\n"
. " true\r\n"
. " i386\r\n"
. " machine\r\n"
. " aki-4438dd2d\r\n"
. " ari-4538dd2c\r\n"
. "
\r\n"
. " \r\n"
. "";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Image->describe(null, array('2060296256884', '206029621532'));
$arrImage = array(
array(
'imageId' => 'ami-be3adfd7',
'imageLocation' => 'ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml',
'imageState' => 'available',
'imageOwnerId' => '2060296256884',
'isPublic' => 'false',
'architecture' => 'i386',
'imageType' => 'machine',
'kernelId' => 'aki-4438dd2d',
'ramdiskId' => 'ari-4538dd2c',
'platform' => '',
),
array(
'imageId' => 'ami-be3adfd6',
'imageLocation' => 'ec2-public-images/ubuntu-8.10-i386-base-v1.04.manifest.xml',
'imageState' => 'available',
'imageOwnerId' => '206029621532',
'isPublic' => 'true',
'architecture' => 'i386',
'imageType' => 'machine',
'kernelId' => 'aki-4438dd2d',
'ramdiskId' => 'ari-4538dd2c',
'platform' => '',
)
);
$this->assertSame($arrImage, $return);
}
public function testDescribeSingleImageByOwnerId()
{
$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"
. " ami-be3adfd7\r\n"
. " ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml\r\n"
. " available\r\n"
. " 206029621532\r\n"
. " false\r\n"
. " i386\r\n"
. " machine\r\n"
. " aki-4438dd2d\r\n"
. " ari-4538dd2c\r\n"
. "
\r\n"
. " \r\n"
. "";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Image->describe(null, '206029621532');
$arrImage = array(
array(
'imageId' => 'ami-be3adfd7',
'imageLocation' => 'ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml',
'imageState' => 'available',
'imageOwnerId' => '206029621532',
'isPublic' => 'false',
'architecture' => 'i386',
'imageType' => 'machine',
'kernelId' => 'aki-4438dd2d',
'ramdiskId' => 'ari-4538dd2c',
'platform' => '',
)
);
$this->assertSame($arrImage, $return);
}
public function testDescribeSingleImageMultipleImagesByExecutableBy()
{
$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"
. " ami-be3adfd7\r\n"
. " ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml\r\n"
. " available\r\n"
. " 2060296256884\r\n"
. " false\r\n"
. " i386\r\n"
. " machine\r\n"
. " aki-4438dd2d\r\n"
. " ari-4538dd2c\r\n"
. "
\r\n"
. " - \r\n"
. " ami-be3adfd6\r\n"
. " ec2-public-images/ubuntu-8.10-i386-base-v1.04.manifest.xml\r\n"
. " available\r\n"
. " 206029621532\r\n"
. " true\r\n"
. " i386\r\n"
. " machine\r\n"
. " aki-4438dd2d\r\n"
. " ari-4538dd2c\r\n"
. "
\r\n"
. " \r\n"
. "";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Image->describe(null, null, array('46361432890', '432432265322'));
$arrImage = array(
array(
'imageId' => 'ami-be3adfd7',
'imageLocation' => 'ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml',
'imageState' => 'available',
'imageOwnerId' => '2060296256884',
'isPublic' => 'false',
'architecture' => 'i386',
'imageType' => 'machine',
'kernelId' => 'aki-4438dd2d',
'ramdiskId' => 'ari-4538dd2c',
'platform' => '',
),
array(
'imageId' => 'ami-be3adfd6',
'imageLocation' => 'ec2-public-images/ubuntu-8.10-i386-base-v1.04.manifest.xml',
'imageState' => 'available',
'imageOwnerId' => '206029621532',
'isPublic' => 'true',
'architecture' => 'i386',
'imageType' => 'machine',
'kernelId' => 'aki-4438dd2d',
'ramdiskId' => 'ari-4538dd2c',
'platform' => '',
)
);
$this->assertSame($arrImage, $return);
}
public function testDescribeSingleImageByExecutableBy()
{
$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"
. " ami-be3adfd7\r\n"
. " ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml\r\n"
. " available\r\n"
. " 206029621532\r\n"
. " false\r\n"
. " i386\r\n"
. " machine\r\n"
. " aki-4438dd2d\r\n"
. " ari-4538dd2c\r\n"
. "
\r\n"
. " \r\n"
. "";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Image->describe(null, null, '46361432890');
$arrImage = array(
array(
'imageId' => 'ami-be3adfd7',
'imageLocation' => 'ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml',
'imageState' => 'available',
'imageOwnerId' => '206029621532',
'isPublic' => 'false',
'architecture' => 'i386',
'imageType' => 'machine',
'kernelId' => 'aki-4438dd2d',
'ramdiskId' => 'ari-4538dd2c',
'platform' => '',
)
);
$this->assertSame($arrImage, $return);
}
public function testDescribeAttributeLaunchPermission()
{
$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"
. " ami-61a54008\r\n"
. " \r\n"
. " - \r\n"
. " 495219933132\r\n"
. "
\r\n"
. " \r\n"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Image->describeAttribute('ami-61a54008', 'launchPermission');
$this->assertEquals('ami-61a54008', $return['imageId']);
$this->assertEquals('495219933132', $return['launchPermission'][0]);
}
public function testDescribeAttributeProductCodes()
{
$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"
. " ami-61a54008\r\n"
. " \r\n"
. " - \r\n"
. " 774F4FF8\r\n"
. "
\r\n"
. " \r\n"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Image->describeAttribute('ami-61a54008', 'productCodes');
$this->assertEquals('ami-61a54008', $return['imageId']);
$this->assertEquals('774F4FF8', $return['productCodes'][0]);
}
public function testModifyAttributeSingleLaunchPermission()
{
$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"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Image->modifyAttribute('ami-61a54008', 'launchPermission', 'add', '495219933132', 'all');
$this->assertTrue($return);
}
public function testModifyAttributeMultipleLaunchPermission()
{
$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"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Image->modifyAttribute('ami-61a54008', 'launchPermission', 'add', array('495219933132', '495219933133'), array('all', 'all'));
$this->assertTrue($return);
}
public function testModifyAttributeThrowsExceptionOnInvalidAttribute()
{
try {
$return = $this->Zend_Service_Amazon_Ec2_Image->modifyAttribute('ami-61a54008', 'invalidPermission', 'add', '495219933132', 'all');
$this->fail('An exception should be throw if you are modifying an invalid attirubte');
} catch (Zend_Service_Amazon_Ec2_Exception $zsaee) {}
}
public function testModifyAttributeProuctCodes()
{
$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"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Image->modifyAttribute('ami-61a54008', 'productCodes', null, null, null, '774F4FF8');
$this->assertTrue($return);
}
public function testRegister()
{
$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"
. " ami-61a54008\r\n"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Image->register('mybucket-myimage.manifest.xml');
$this->assertEquals('ami-61a54008', $return);
}
public function testResetAttribute()
{
$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"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Image->resetAttribute('ami-61a54008', 'launchPermission');
$this->assertTrue($return);
}
}