ManagementClientTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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-2015 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. /** Zend_Service_SqlAzure_Management_Client */
  32. require_once 'Zend/Service/SqlAzure/Management/Client.php';
  33. /**
  34. * @category Zend
  35. * @package Zend_Service_SqlAzure
  36. * @subpackage UnitTests
  37. * @version $Id$
  38. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. class Zend_Service_SqlAzure_Management_ManagementClientTest extends PHPUnit_Framework_TestCase
  42. {
  43. static $path;
  44. static $debug = true;
  45. static $serverName = '';
  46. public function __construct()
  47. {
  48. self::$path = dirname(__FILE__).'/_files/';
  49. }
  50. public static function main()
  51. {
  52. if (TESTS_ZEND_SERVICE_WINDOWSAZURE_SQLMANAGEMENT_RUNTESTS) {
  53. $suite = new PHPUnit_Framework_TestSuite("Zend_Service_SqlAzure_Management_ManagementClientTest");
  54. $result = PHPUnit_TextUI_TestRunner::run($suite);
  55. }
  56. }
  57. /**
  58. * Test teardown
  59. */
  60. protected function tearDown()
  61. {
  62. // Clean up server
  63. $managementClient = $this->createManagementClient();
  64. // Remove server
  65. try { $managementClient->dropServer(self::$serverName); } catch (Exception $ex) { }
  66. }
  67. protected function createManagementClient()
  68. {
  69. return new Zend_Service_SqlAzure_Management_Client(
  70. TESTS_ZEND_SERVICE_WINDOWSAZURE_SQLMANAGEMENT_SUBSCRIPTIONID, self::$path . '/management.pem', TESTS_ZEND_SERVICE_WINDOWSAZURE_SQLMANAGEMENT_CERTIFICATEPASSWORD);
  71. }
  72. protected function log($message)
  73. {
  74. if (self::$debug) {
  75. echo date('Y-m-d H:i:s') . ' - ' . $message . "\r\n";
  76. }
  77. }
  78. /**
  79. * Test create and configure server
  80. */
  81. public function testCreateAndConfigureServer()
  82. {
  83. if (TESTS_ZEND_SERVICE_WINDOWSAZURE_SQLMANAGEMENT_RUNTESTS) {
  84. // Create a management client
  85. $managementClient = $this->createManagementClient();
  86. // ** Step 1: create a server
  87. $this->log('Creating server...');
  88. $server = $managementClient->createServer('sqladm', '@@cool1OO', 'West Europe');
  89. $this->assertEquals('sqladm', $server->AdministratorLogin);
  90. $this->assertEquals('West Europe', $server->Location);
  91. self::$serverName = $server->Name;
  92. $this->log('Created server.');
  93. // ** Step 2: change password
  94. $this->log('Changing password...');
  95. $managementClient->setAdministratorPassword($server->Name, '@@cool1OO11');
  96. $this->log('Changed password...');
  97. // ** Step 3: add firewall rule
  98. $this->log('Creating firewall rule...');
  99. $managementClient->createFirewallRuleForMicrosoftServices($server->Name, true);
  100. $result = $managementClient->listFirewallRules($server->Name);
  101. $this->assertEquals(1, count($result));
  102. $this->log('Created firewall rule.');
  103. // ** Step 4: remove firewall rule
  104. $this->log('Removing firewall rule...');
  105. $managementClient->createFirewallRuleForMicrosoftServices($server->Name, false);
  106. $result = $managementClient->listFirewallRules($server->Name);
  107. $this->assertEquals(0, count($result));
  108. $this->log('Removed firewall rule.');
  109. // ** Step 5: Drop server
  110. $this->log('Dropping server...');
  111. $managementClient->dropServer($server->Name);
  112. $this->log('Dropped server.');
  113. }
  114. }
  115. }
  116. // Call Zend_Service_SqlAzure_Management_ManagementClientTest::main() if this source file is executed directly.
  117. if (PHPUnit_MAIN_METHOD == "Zend_Service_SqlAzure_Management_ManagementClientTest::main") {
  118. Zend_Service_SqlAzure_Management_ManagementClientTest::main();
  119. }