-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
555 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Test\VCloud\Helpers\Functional; | ||
|
||
class ExceptionTestCase extends \PHPUnit_Framework_TestCase | ||
{ | ||
protected $config; | ||
protected $service; | ||
protected $e; | ||
protected $id; | ||
|
||
public function setUp() | ||
{ | ||
global $service, $config; | ||
$this->config = $config; | ||
$this->service = $service; | ||
$this->id = $this->config->unknownOrganization; | ||
|
||
$reference = new \VMware_VCloud_API_ReferenceType(); | ||
$reference->set_href('https://' . $this->config->host . '/api/org/' . $this->id); | ||
$reference->set_type('application/vnd.vmware.vcloud.org+xml'); | ||
|
||
$unknownOrganization = $service->createSdkObj($reference); | ||
|
||
try { | ||
$unknownOrganization->getOrg(); | ||
throw new \RuntimeException( | ||
'Failed generating SDK Exception during setup, organization "' | ||
. $this->id . '" exists where it shouldn\'t' | ||
); | ||
} catch (\VMware_VCloud_SDK_Exception $e) { | ||
$this->e = $e; | ||
} | ||
} | ||
|
||
public function testGetOriginalException() | ||
{ | ||
$this->assertEquals($this->e, \VCloud\Helpers\Exception::create($this->e)->getOriginalException()); | ||
} | ||
|
||
public function testGetMessage() | ||
{ | ||
$this->assertEquals( | ||
'The VCD entity com.vmware.vcloud.entity.org:' . $this->id . ' does not exist.', | ||
\VCloud\Helpers\Exception::create($this->e)->getMessage() | ||
); | ||
} | ||
|
||
public function testGetMajorErrorCode() | ||
{ | ||
$this->assertEquals( | ||
'403', | ||
\VCloud\Helpers\Exception::create($this->e)->getMajorErrorCode() | ||
); | ||
} | ||
|
||
public function testGetMinorErrorCode() | ||
{ | ||
$this->assertEquals( | ||
'ACCESS_TO_RESOURCE_IS_FORBIDDEN', | ||
\VCloud\Helpers\Exception::create($this->e)->getMinorErrorCode() | ||
); | ||
} | ||
|
||
public function testGetStackTrace() | ||
{ | ||
$this->assertEquals( | ||
158, | ||
count(explode("\n", \VCloud\Helpers\Exception::create($this->e)->getStackTrace())) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
require_once dirname(__FILE__) . '/../../vendor/autoload.php'; | ||
|
||
/** | ||
* Setup autoloading | ||
*/ | ||
include __DIR__ . '/../_autoload.php'; | ||
|
||
/** | ||
* Read config | ||
*/ | ||
$config = new \Zend\Config\Config(include dirname(__FILE__) . '/../config.php'); | ||
|
||
/** | ||
* Log in against vCloud Director | ||
*/ | ||
$service = VMware_VCloud_SDK_Service::getService(); | ||
$service->login( | ||
$config->host, | ||
array( | ||
'username' => $config->users->administrator->username . '@' . $config->users->administrator->organization, | ||
'password' => $config->users->administrator->password, | ||
), | ||
array( | ||
'proxy_host' => null, | ||
'proxy_port' => null, | ||
'proxy_user' => null, | ||
'proxy_password' => null, | ||
'ssl_verify_peer' => false, | ||
'ssl_verify_host' => false, | ||
'ssl_cafile' => null, | ||
), | ||
$config->apiVersion | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Test\VCloud\Helpers\Unit; | ||
|
||
class ExceptionTestCase extends \PHPUnit_Framework_TestCase | ||
{ | ||
protected $e; | ||
|
||
public function setUp() | ||
{ | ||
$this->e = new \VMware_VCloud_SDK_Exception(file_get_contents(__DIR__ . '/_files/Error.xml')); | ||
} | ||
|
||
public function testGetOriginalException() | ||
{ | ||
$this->assertEquals($this->e, \VCloud\Helpers\Exception::create($this->e)->getOriginalException()); | ||
} | ||
|
||
public function testGetMessage() | ||
{ | ||
$this->assertEquals( | ||
'The requested operation could not be executed because media ' | ||
. '"reconfMedia-vm-69cfa436-a55c-4045-be62-f110bbb5801d_1372317643" ' | ||
. 'is mounted by VM(s): "__e2cLBHA__Production_m_1372316882". Please ' | ||
. 'eject media from the VM(s) before deleting media.', | ||
\VCloud\Helpers\Exception::create($this->e)->getMessage() | ||
); | ||
} | ||
|
||
public function testGetMajorErrorCode() | ||
{ | ||
$this->assertEquals( | ||
'400', | ||
\VCloud\Helpers\Exception::create($this->e)->getMajorErrorCode() | ||
); | ||
} | ||
|
||
public function testGetMinorErrorCode() | ||
{ | ||
$this->assertEquals( | ||
'BAD_REQUEST', | ||
\VCloud\Helpers\Exception::create($this->e)->getMinorErrorCode() | ||
); | ||
} | ||
|
||
public function testGetStackTrace() | ||
{ | ||
$this->assertEquals( | ||
175, | ||
count(explode("\n", \VCloud\Helpers\Exception::create($this->e)->getStackTrace())) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Test\VCloud\Helpers\Unit; | ||
|
||
class QueryTestCase extends \PHPUnit_Framework_TestCase | ||
{ | ||
protected $queryService; | ||
|
||
public function setUp() | ||
{ | ||
$this->queryService = new Stub\QueryService(); | ||
} | ||
|
||
public function testQueryRecords() | ||
{ | ||
$queryRecords = \VCloud\Helpers\Query::create($this->queryService)->queryRecords('adminUser'); | ||
$this->assertEquals( | ||
86, | ||
count($queryRecords) | ||
); | ||
} | ||
|
||
public function testQueryRecord() | ||
{ | ||
$queryRecord = \VCloud\Helpers\Query::create($this->queryService)->queryRecord( | ||
'adminUser', | ||
'href==https://vcloud-director.local/api/admin/user/23d6deb1-1778-4325-8289-2f150d122674' | ||
); | ||
$this->assertEquals( | ||
'VMware_VCloud_API_QueryResultAdminUserRecordType', | ||
get_class($queryRecord) | ||
); | ||
} | ||
|
||
public function testQueryRecordNotFound() | ||
{ | ||
$queryRecord = \VCloud\Helpers\Query::create($this->queryService)->queryRecord( | ||
'adminUser', | ||
'href==tupeuxpastest' | ||
); | ||
$this->assertEquals( | ||
false, | ||
$queryRecord | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Test\VCloud\Helpers\Unit\Stub; | ||
|
||
class QueryService extends \VMware_VCloud_SDK_Query | ||
{ | ||
public function __construct() | ||
{ | ||
} | ||
|
||
public function queryRecords($type, $params = null) | ||
{ | ||
$paramsArray = $params->getParams(); | ||
$filename = __DIR__ . '/../_files/'; | ||
switch ($paramsArray['filter']) { | ||
case null: | ||
$filename .= 'Query' . $paramsArray['page'] . '.xml'; | ||
break; | ||
case 'href==https://vcloud-director.local/api/admin/user/23d6deb1-1778-4325-8289-2f150d122674': | ||
$filename .= 'QueryFilter.xml'; | ||
break; | ||
default: | ||
$filename .= 'QueryFilterNoResult.xml'; | ||
break; | ||
} | ||
|
||
$xml = file_get_contents($filename); | ||
if (!$xml) { | ||
throw new \Exception('Failed reading XML from file ' . $filename); | ||
} | ||
|
||
$records = \VMware_VCloud_API_Helper::parseString($xml, $type = '\VMware_VCloud_API_QueryResultRecordsType'); | ||
return $records; | ||
} | ||
} |
Oops, something went wrong.