ManagementClientTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_WindowsAzure
  17. * @subpackage UnitTests
  18. * @version $Id$
  19. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. date_default_timezone_set('UTC');
  23. if (!defined('PHPUnit_MAIN_METHOD')) {
  24. define('PHPUnit_MAIN_METHOD', 'Zend_Service_SqlAzure_Management_ManagementClientTest::main');
  25. }
  26. /**
  27. * Test helpers
  28. */
  29. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  30. require_once dirname(__FILE__) . '/../../../../TestConfiguration.php.dist';
  31. require_once 'PHPUnit/Framework/TestCase.php';
  32. /** Zend_Service_SqlAzure_Management_Client */
  33. require_once 'Zend/Service/SqlAzure/Management/Client.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Service_SqlAzure
  37. * @subpackage UnitTests
  38. * @version $Id$
  39. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  40. * @license http://framework.zend.com/license/new-bsd New BSD License
  41. */
  42. class Zend_Service_SqlAzure_Management_ManagementClientTest extends PHPUnit_Framework_TestCase
  43. {
  44. static $path;
  45. static $debug = true;
  46. static $serverName = '';
  47. public function __construct()
  48. {
  49. self::$path = dirname(__FILE__).'/_files/';
  50. }
  51. public static function main()
  52. {
  53. if (TESTS_ZEND_SERVICE_WINDOWSAZURE_SQLMANAGEMENT_RUNTESTS) {
  54. $suite = new PHPUnit_Framework_TestSuite("Zend_Service_SqlAzure_Management_ManagementClientTest");
  55. $result = PHPUnit_TextUI_TestRunner::run($suite);
  56. }
  57. }
  58. /**
  59. * Test teardown
  60. */
  61. protected function tearDown()
  62. {
  63. // Clean up server
  64. $managementClient = $this->createManagementClient();
  65. // Remove server
  66. try { $managementClient->dropServer(self::$serverName); } catch (Exception $ex) { }
  67. }
  68. protected function createManagementClient()
  69. {
  70. return new Zend_Service_SqlAzure_Management_Client(
  71. TESTS_ZEND_SERVICE_WINDOWSAZURE_SQLMANAGEMENT_SUBSCRIPTIONID, self::$path . '/management.pem', TESTS_ZEND_SERVICE_WINDOWSAZURE_SQLMANAGEMENT_CERTIFICATEPASSWORD);
  72. }
  73. protected function log($message)
  74. {
  75. if (self::$debug) {
  76. echo date('Y-m-d H:i:s') . ' - ' . $message . "\r\n";
  77. }
  78. }
  79. /**
  80. * Test create and configure server
  81. */
  82. public function testCreateAndConfigureServer()
  83. {
  84. if (TESTS_ZEND_SERVICE_WINDOWSAZURE_SQLMANAGEMENT_RUNTESTS) {
  85. // Create a management client
  86. $managementClient = $this->createManagementClient();
  87. // ** Step 1: create a server
  88. $this->log('Creating server...');
  89. $server = $managementClient->createServer('sqladm', '@@cool1OO', 'West Europe');
  90. $this->assertEquals('sqladm', $server->AdministratorLogin);
  91. $this->assertEquals('West Europe', $server->Location);
  92. self::$serverName = $server->Name;
  93. $this->log('Created server.');
  94. // ** Step 2: change password
  95. $this->log('Changing password...');
  96. $managementClient->setAdministratorPassword($server->Name, '@@cool1OO11');
  97. $this->log('Changed password...');
  98. // ** Step 3: add firewall rule
  99. $this->log('Creating firewall rule...');
  100. $managementClient->createFirewallRuleForMicrosoftServices($server->Name, true);
  101. $result = $managementClient->listFirewallRules($server->Name);
  102. $this->assertEquals(1, count($result));
  103. $this->log('Created firewall rule.');
  104. // ** Step 4: remove firewall rule
  105. $this->log('Removing firewall rule...');
  106. $managementClient->createFirewallRuleForMicrosoftServices($server->Name, false);
  107. $result = $managementClient->listFirewallRules($server->Name);
  108. $this->assertEquals(0, count($result));
  109. $this->log('Removed firewall rule.');
  110. // ** Step 5: Drop server
  111. $this->log('Dropping server...');
  112. $managementClient->dropServer($server->Name);
  113. $this->log('Dropped server.');
  114. }
  115. }
  116. }
  117. // Call Zend_Service_SqlAzure_Management_ManagementClientTest::main() if this source file is executed directly.
  118. if (PHPUnit_MAIN_METHOD == "Zend_Service_SqlAzure_Management_ManagementClientTest::main") {
  119. Zend_Service_SqlAzure_Management_ManagementClientTest::main();
  120. }