3
* Copyright 2012-2014 Rackspace US, Inc.
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
namespace OpenCloud\Tests\Image\Resource;
20
use Guzzle\Http\Message\Response;
21
use OpenCloud\Image\Resource\Image;
22
use OpenCloud\Image\Resource\Schema\Schema;
23
use OpenCloud\Tests\OpenCloudTestCase;
25
class ImageTest extends OpenCloudTestCase
27
public function setupObjects()
29
$this->image = new Image($this->getClient()->imageService('cloudImages', 'IAD'));
32
protected function getSchemaData()
34
return json_decode(file_get_contents(__DIR__ . '/Schema/image.json'), true);
37
public function test_Update()
39
$schema = Schema::factory($this->getSchemaData());
41
'visibility' => 'private',
45
$response = $this->image->update($config, $schema);
47
$this->assertInstanceOf('Guzzle\Http\Message\Response', $response);
50
public function test_Updating_AddProperty()
52
$schema = Schema::factory($this->getSchemaData());
57
$response = $this->image->update($config, $schema);
59
$this->assertInstanceOf('Guzzle\Http\Message\Response', $response);
63
* @expectedException \RuntimeException
65
public function test_Update_Fails_With_AddProperties()
67
$data = $this->getSchemaData();
68
unset($data['additionalProperties']);
70
$schema = Schema::factory($data);
75
$response = $this->image->update($config, $schema);
77
$this->assertInstanceOf('Guzzle\Http\Message\Response', $response);
80
public function test_Refresh()
82
$this->addMockSubscriber($this->makeResponse('{"id":"da3b75d9-3f4a-40e7-8a2c-bfab23927dea","name":"cirros-0.3.0-x86_64-uec-ramdisk","status":"active","visibility":"public","size":2254249,"checksum":"2cec138d7dae2aa59038ef8c9aec2390","tags":["ping","pong"],"created_at":"2012-08-10T19:23:50Z","updated_at":"2012-08-10T19:23:50Z","self":"/v2/images/da3b75d9-3f4a-40e7-8a2c-bfab23927dea","file":"/v2/images/da3b75d9-3f4a-40e7-8a2c-bfab23927dea/file","schema":"/v2/schemas/image"}'));
84
$this->assertInstanceOf('Guzzle\Http\Message\Response', $this->image->refresh());
87
public function test_Delete()
89
$this->addMockSubscriber(new Response(204));
91
$this->assertInstanceOf('Guzzle\Http\Message\Response', $this->image->delete());
94
public function test_List_Members()
97
{"members":[{"created_at":"2013-10-07T17:58:03Z","image_id":"dbc999e3-c52f-4200-bedd-3b18fe7f87fe","member_id":"123456789","schema":"/v2/schemas/member","status":"pending","updated_at":"2013-10-07T17:58:03Z"},{"created_at":"2013-10-07T17:58:55Z","image_id":"dbc999e3-c52f-4200-bedd-3b18fe7f87fe","member_id":"987654321","schema":"/v2/schemas/member","status":"accepted","updated_at":"2013-10-08T12:08:55Z"}],"schema":"/v2/schemas/members"}
100
$this->addMockSubscriber($this->makeResponse($json));
102
$members = $this->image->listMembers();
104
$this->assertInstanceOf('OpenCloud\Common\Collection\PaginatedIterator', $members);
105
$this->assertInstanceOf('OpenCloud\Image\Resource\Member', $members->getElement(0));
108
public function test_Get_Member()
110
$this->addMockSubscriber(new Response(200));
112
$this->assertInstanceOf('OpenCloud\Image\Resource\Member', $this->image->getMember('foo'));
115
public function test_Create_Member()
117
$this->addMockSubscriber(new Response(201));
119
$this->assertInstanceOf('Guzzle\Http\Message\Response', $this->image->createMember(12345));
122
public function test_Delete_Member()
124
$this->addMockSubscriber(new Response(201));
126
$this->assertInstanceOf('Guzzle\Http\Message\Response', $this->image->deleteMember(12345));
129
public function test_Create_Tag()
131
$this->addMockSubscriber(new Response(201));
133
$this->assertInstanceOf('Guzzle\Http\Message\Response', $this->image->addTag(12345));
136
public function test_Delete_Tag()
138
$this->addMockSubscriber(new Response(204));
140
$this->assertInstanceOf('Guzzle\Http\Message\Response', $this->image->deleteTag(12345));
b'\\ No newline at end of file'