PageRenderTime 90ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/unit/WindowsAzure/Common/Internal/ServiceBusSettingsTest.php

https://bitbucket.org/kurniawanchan83/azure-sdk-for-php
PHP | 250 lines | 98 code | 28 blank | 124 comment | 0 complexity | dd5b4a96209d20df9ee3c3d3d5e6eb14 MD5 | raw file
  1. <?php
  2. /**
  3. * LICENSE: Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. *
  14. * PHP version 5
  15. *
  16. * @category Microsoft
  17. * @package Tests\Unit\WindowsAzure\Common\Internal
  18. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  19. * @copyright 2012 Microsoft Corporation
  20. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  21. * @link https://github.com/windowsazure/azure-sdk-for-php
  22. */
  23. namespace Tests\Unit\WindowsAzure\Common\Internal;
  24. use WindowsAzure\Common\Internal\ServiceBusSettings;
  25. use WindowsAzure\Common\Internal\Resources;
  26. /**
  27. * Unit tests for class ServiceBusSettings
  28. *
  29. * @category Microsoft
  30. * @package Tests\Unit\WindowsAzure\Common\Internal
  31. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  32. * @copyright 2012 Microsoft Corporation
  33. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  34. * @version Release: @package_version@
  35. * @link https://github.com/windowsazure/azure-sdk-for-php
  36. */
  37. class ServiceBusSettingsTest extends \PHPUnit_Framework_TestCase
  38. {
  39. public function setUp()
  40. {
  41. $property = new \ReflectionProperty('WindowsAzure\Common\Internal\ServiceBusSettings', 'isInitialized');
  42. $property->setAccessible(true);
  43. $property->setValue(false);
  44. }
  45. /**
  46. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::createFromConnectionString
  47. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::init
  48. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::__construct
  49. * @covers WindowsAzure\Common\Internal\ServiceSettings::getValidator
  50. * @covers WindowsAzure\Common\Internal\ServiceSettings::optional
  51. * @covers WindowsAzure\Common\Internal\ServiceSettings::allRequired
  52. * @covers WindowsAzure\Common\Internal\ServiceSettings::setting
  53. * @covers WindowsAzure\Common\Internal\ServiceSettings::settingWithFunc
  54. * @covers WindowsAzure\Common\Internal\ServiceSettings::matchedSpecification
  55. * @covers WindowsAzure\Common\Internal\ServiceSettings::parseAndValidateKeys
  56. * @covers WindowsAzure\Common\Internal\ServiceSettings::noMatch
  57. */
  58. public function testCreateFromConnectionStringWithServiceBusAutomaticCase()
  59. {
  60. // Setup
  61. $expectedNamespace = 'mynamespace';
  62. $expectedServiceBusEndpoint = "https://$expectedNamespace.servicebus.windows.net";
  63. $expectedWrapName = 'myname';
  64. $expectedWrapPassword = 'mypassword';
  65. $expectedWrapEndpointUri = "https://$expectedNamespace-sb.accesscontrol.windows.net/WRAPv0.9";
  66. $connectionString = "Endpoint=$expectedServiceBusEndpoint;SharedSecretIssuer=$expectedWrapName;SharedSecretValue=$expectedWrapPassword";
  67. // Test
  68. $actual = ServiceBusSettings::createFromConnectionString($connectionString);
  69. // Assert
  70. $this->assertEquals($expectedNamespace, $actual->getNamespace());
  71. $this->assertEquals($expectedServiceBusEndpoint, $actual->getServiceBusEndpointUri());
  72. $this->assertEquals($expectedWrapName, $actual->getWrapName());
  73. $this->assertEquals($expectedWrapPassword, $actual->getWrapPassword());
  74. $this->assertEquals($expectedWrapEndpointUri, $actual->getWrapEndpointUri());
  75. }
  76. /**
  77. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::createFromConnectionString
  78. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::init
  79. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::__construct
  80. * @covers WindowsAzure\Common\Internal\ServiceSettings::getValidator
  81. * @covers WindowsAzure\Common\Internal\ServiceSettings::optional
  82. * @covers WindowsAzure\Common\Internal\ServiceSettings::allRequired
  83. * @covers WindowsAzure\Common\Internal\ServiceSettings::setting
  84. * @covers WindowsAzure\Common\Internal\ServiceSettings::settingWithFunc
  85. * @covers WindowsAzure\Common\Internal\ServiceSettings::matchedSpecification
  86. * @covers WindowsAzure\Common\Internal\ServiceSettings::parseAndValidateKeys
  87. * @covers WindowsAzure\Common\Internal\ServiceSettings::noMatch
  88. */
  89. public function testCreateFromConnectionStringWithMissingServiceBusEndpointFail()
  90. {
  91. // Setup
  92. $connectionString = "SharedSecretIssuer=name;SharedSecretValue=password";
  93. $expectedMsg = sprintf(Resources::MISSING_CONNECTION_STRING_SETTINGS, $connectionString);
  94. $this->setExpectedException('\RuntimeException', $expectedMsg);
  95. // Test
  96. ServiceBusSettings::createFromConnectionString($connectionString);
  97. }
  98. /**
  99. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::createFromConnectionString
  100. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::init
  101. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::__construct
  102. * @covers WindowsAzure\Common\Internal\ServiceSettings::getValidator
  103. * @covers WindowsAzure\Common\Internal\ServiceSettings::optional
  104. * @covers WindowsAzure\Common\Internal\ServiceSettings::allRequired
  105. * @covers WindowsAzure\Common\Internal\ServiceSettings::setting
  106. * @covers WindowsAzure\Common\Internal\ServiceSettings::settingWithFunc
  107. * @covers WindowsAzure\Common\Internal\ServiceSettings::matchedSpecification
  108. * @covers WindowsAzure\Common\Internal\ServiceSettings::parseAndValidateKeys
  109. * @covers WindowsAzure\Common\Internal\ServiceSettings::noMatch
  110. */
  111. public function testCreateFromConnectionStringWithInvalidServiceBusKeyFail()
  112. {
  113. // Setup
  114. $invalidKey = 'InvalidKey';
  115. $connectionString = "$invalidKey=value;SharedSecretIssuer=name;SharedSecretValue=password";
  116. $expectedMsg = sprintf(
  117. Resources::INVALID_CONNECTION_STRING_SETTING_KEY,
  118. $invalidKey,
  119. implode("\n", array('Endpoint', 'SharedSecretIssuer', 'SharedSecretValue'))
  120. );
  121. $this->setExpectedException('\RuntimeException', $expectedMsg);
  122. // Test
  123. ServiceBusSettings::createFromConnectionString($connectionString);
  124. }
  125. /**
  126. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::getServiceBusEndpointUri
  127. */
  128. public function testGetServiceBusEndpointUri()
  129. {
  130. // Setup
  131. $expected = 'serviceBusEndpointUri';
  132. $setting = new ServiceBusSettings($expected, null, null, null);
  133. // Test
  134. $actual = $setting->getServiceBusEndpointUri();
  135. // Assert
  136. $this->assertEquals($expected, $actual);
  137. }
  138. /**
  139. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::getNamespace
  140. */
  141. public function testGetNamespace()
  142. {
  143. // Setup
  144. $expected = 'namespace';
  145. $setting = new ServiceBusSettings(null, $expected, null, null);
  146. // Test
  147. $actual = $setting->getNamespace();
  148. // Assert
  149. $this->assertEquals($expected, $actual);
  150. }
  151. /**
  152. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::getWrapName
  153. */
  154. public function testGetWrapName()
  155. {
  156. // Setup
  157. $expected = 'wrapname';
  158. $setting = new ServiceBusSettings(null, null, $expected, null);
  159. // Test
  160. $actual = $setting->getWrapName();
  161. // Assert
  162. $this->assertEquals($expected, $actual);
  163. }
  164. /**
  165. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::getWrapPassword
  166. */
  167. public function testGetWrapPassword()
  168. {
  169. // Setup
  170. $expected = 'wrappassword';
  171. $setting = new ServiceBusSettings(null, null, null, $expected);
  172. // Test
  173. $actual = $setting->getWrapPassword();
  174. // Assert
  175. $this->assertEquals($expected, $actual);
  176. }
  177. /**
  178. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::getWrapEndpointUri
  179. */
  180. public function testGetWrapEndpointUri()
  181. {
  182. // Setup
  183. $namespace = 'wrapendpoint';
  184. $expected = "https://$namespace-sb.accesscontrol.windows.net/WRAPv0.9";
  185. $setting = new ServiceBusSettings(null, $namespace, null, null);
  186. // Test
  187. $actual = $setting->getWrapEndpointUri();
  188. // Assert
  189. $this->assertEquals($expected, $actual);
  190. }
  191. /**
  192. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::createFromConnectionString
  193. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::init
  194. * @covers WindowsAzure\Common\Internal\ServiceBusSettings::__construct
  195. * @covers WindowsAzure\Common\Internal\ServiceSettings::getValidator
  196. * @covers WindowsAzure\Common\Internal\ServiceSettings::optional
  197. * @covers WindowsAzure\Common\Internal\ServiceSettings::allRequired
  198. * @covers WindowsAzure\Common\Internal\ServiceSettings::setting
  199. * @covers WindowsAzure\Common\Internal\ServiceSettings::settingWithFunc
  200. * @covers WindowsAzure\Common\Internal\ServiceSettings::matchedSpecification
  201. * @covers WindowsAzure\Common\Internal\ServiceSettings::parseAndValidateKeys
  202. * @covers WindowsAzure\Common\Internal\ServiceSettings::noMatch
  203. */
  204. public function testCreateFromConnectionStringWithCaseInvesitive()
  205. {
  206. // Setup
  207. $expectedNamespace = 'mynamespace';
  208. $expectedServiceBusEndpoint = "https://$expectedNamespace.servicebus.windows.net";
  209. $expectedWrapName = 'myname';
  210. $expectedWrapPassword = 'mypassword';
  211. $expectedWrapEndpointUri = "https://$expectedNamespace-sb.accesscontrol.windows.net/WRAPv0.9";
  212. $connectionString = "eNdPoinT=$expectedServiceBusEndpoint;sHarEdsecRetiSsuer=$expectedWrapName;shArEdsecrEtvAluE=$expectedWrapPassword";
  213. // Test
  214. $actual = ServiceBusSettings::createFromConnectionString($connectionString);
  215. // Assert
  216. $this->assertEquals($expectedNamespace, $actual->getNamespace());
  217. $this->assertEquals($expectedServiceBusEndpoint, $actual->getServiceBusEndpointUri());
  218. $this->assertEquals($expectedWrapName, $actual->getWrapName());
  219. $this->assertEquals($expectedWrapPassword, $actual->getWrapPassword());
  220. $this->assertEquals($expectedWrapEndpointUri, $actual->getWrapEndpointUri());
  221. }
  222. }