ServiceTest.php
3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* Unit Tests
*
* @copyright 2012-2014 Rackspace Hosting, Inc.
* See COPYING for licensing information
*
* @version 1.0.0
* @author Glen Campbell <glen.campbell@rackspace.com>
*/
namespace OpenCloud\Tests\Common;
use OpenCloud\Common\Service\Catalog;
use OpenCloud\Common\Service\ServiceBuilder;
class ServiceTest extends \OpenCloud\Tests\OpenCloudTestCase
{
private $service;
public function setupObjects()
{
$this->service = $this->getClient()->computeService('cloudServersOpenStack', 'DFW');
}
public function testExtensions()
{
$ext = $this->service->getExtensions();
$this->assertTrue(is_array($ext));
}
public function testRegion()
{
$this->assertEquals('DFW', $this->service->region());
}
public function testName()
{
$this->assertEquals('cloudServersOpenStack', $this->service->name());
}
public function test_Endpoint()
{
$endpoint = $this->service->getEndpoint();
$this->assertInstanceOf('OpenCloud\Common\Service\Endpoint', $endpoint);
$this->assertEquals($this->service->getRegion(), $endpoint->getRegion());
}
public function test_Catalog()
{
$catalog = $this->getClient()->getCatalog();
$this->assertEquals($catalog, Catalog::factory($catalog));
foreach ($catalog->getItems() as $item) {
$this->assertNotNull($item->getName());
$this->assertNotNull($item->getType());
$this->assertNotNull($item->getEndpoints());
}
}
/**
* @expectedException OpenCloud\Common\Exceptions\EndpointError
*/
public function test_Endpoint_Error_With_Incorrect_Region()
{
$this->getClient()->computeService('cloudServersOpenStack', 'BERLIN');
}
/**
* @expectedException OpenCloud\Common\Exceptions\EndpointError
*/
public function test_NonExistent_Service()
{
$this->getClient()->computeService('fooBar', 'DFW');
}
/**
* @expectedException OpenCloud\Common\Exceptions\InvalidArgumentError
*/
public function test_Catalog_Fails_Without_Correct_Type()
{
Catalog::factory(null);
}
public function test_Service()
{
$this->assertEquals('compute', $this->service->getType());
$this->assertEquals('cloudServersOpenStack', $this->service->getName());
$this->assertNotNull($this->service->limits());
}
/**
* @expectedException OpenCloud\Common\Exceptions\EndpointError
*/
public function test_Endpoint_Error()
{
$service = $this->getClient()->computeService('testService', 'ORD');
$service->getBaseUrl();
}
public function test_Region_ServiceBuilder()
{
$dfwService = ServiceBuilder::factory($this->getClient(), 'OpenCloud\Compute\Service', array(
'name' => 'cloudServersOpenStack',
'region' => 'DFW',
'urltype' => 'publicURL'
));
$this->assertEquals('DFW', $dfwService->getEndpoint()->getRegion());
$dfwService2 = $this->getClient()->computeService('cloudServersOpenStack', 'SYD');
$this->assertEquals('SYD', $dfwService2->getEndpoint()->getREgion());
}
/**
* @expectedException \OpenCloud\Common\Exceptions\ServiceException
*/
public function test_ServiceBuilder_Fails_Without_Region()
{
$this->addMockSubscriber($this->getTestFilePath('Auth_No_Default_Region', '.'));
$client = $this->getClient();
$client->authenticate();
$client->computeService('cloudServersOpenStack');
}
public function test_ServiceBuilder_Success_Without_Region_In_Regionless_Service()
{
$this->addMockSubscriber($this->getTestFilePath('Auth_No_Default_Region', '.'));
$client = $this->getClient();
$client->authenticate();
$client->dnsService('cloudDNS');
$client->cloudMonitoringService();
}
}