Permalink
Browse files

Adding more UT

  • Loading branch information...
1 parent c43007a commit fc16eff0f77d5c73353d147d5742a7073ee5f01e Andre Rodrigues committed Oct 12, 2012
Showing with 81 additions and 12 deletions.
  1. +1 −0 lib/azure.js
  2. +8 −12 lib/services/core/servicebussettings.js
  3. +71 −0 test/services/core/servicebussettings-tests.js
  4. +1 −0 test/testlist.txt
View
1 lib/azure.js
@@ -152,6 +152,7 @@ exports.Logger = require('./diagnostics/logger');
exports.ConnectionStringParser = require('./services/core/connectionstringparser');
exports.ServiceSettings = require('./services/core/servicesettings');
exports.StorageServiceSettings = require('./services/core/storageservicesettings');
+exports.ServiceBusSettings = require('./services/core/servicebussettings');
exports.Validate = require('./util/validate');
/*
View
20 lib/services/core/servicebussettings.js
@@ -45,8 +45,8 @@ var validKeys = [
*/
function ServiceBusSettings(serviceBusEndpointUri, namespace, wrapName, wrapPassword) {
this._namespace = namespace;
- this._serviceBusEndpointUri = serviceBusEndpoint;
- this._wrapEndpointUri = 'https://' + namespace + '.accesscontrol.windows.net/WRAPv0.9';
+ this._serviceBusEndpointUri = serviceBusEndpointUri;
+ this._wrapEndpointUri = 'https://' + namespace + '-sb.accesscontrol.windows.net/WRAPv0.9';
this._wrapName = wrapName;
this._wrapPassword = wrapPassword;
}
@@ -59,7 +59,7 @@ function ServiceBusSettings(serviceBusEndpointUri, namespace, wrapName, wrapPass
* @return {ServiceBusSettings}
*/
ServiceBusSettings.createFromConnectionString = function (connectionString) {
- var tokenizedSettings = ServiceSettings.parseAndValidateKeys(connectionString);
+ var tokenizedSettings = ServiceSettings.parseAndValidateKeys(connectionString, validKeys);
var matchedSpecs = ServiceSettings.matchedSpecification(
tokenizedSettings,
@@ -71,23 +71,21 @@ ServiceBusSettings.createFromConnectionString = function (connectionString) {
);
if (matchedSpecs) {
- endpoint = util.tryGetValueInsensitive(
+ var endpoint = util.tryGetValueInsensitive(
ConnectionStringKeys.SERVICE_BUS_ENDPOINT_NAME,
tokenizedSettings
);
// Parse the namespace part from the URI
-
- // TODO: to be implemented
- // var namespace = explode('.', parse_url(endpoint, PHP_URL_HOST));
- var namespace = namespace[0];
+ var parsedUrl = url.parse(endpoint);
+ var namespace = parsedUrl.host.split('.')[0];
var issuerName = util.tryGetValueInsensitive(
ConnectionStringKeys.SHARED_SECRET_ISSUER_NAME,
tokenizedSettings
);
- var issuerValue = Utilities::tryGetValueInsensitive(
+ var issuerValue = util.tryGetValueInsensitive(
ConnectionStringKeys.SHARED_SECRET_VALUE_NAME,
tokenizedSettings
);
@@ -101,6 +99,4 @@ ServiceBusSettings.createFromConnectionString = function (connectionString) {
}
ServiceSettings.noMatch(connectionString);
-}
-
-
+};
View
71 test/services/core/servicebussettings-tests.js
@@ -13,3 +13,74 @@
* limitations under the License.
*/
+var should = require('should');
+var url = require('url');
+
+var testutil = require('../../util/util');
+var azure = testutil.libRequire('azure');
+var Constants = azure.Constants;
+var ConnectionStringKeys = Constants.ConnectionStringKeys;
+var ServiceBusSettings = azure.ServiceBusSettings;
+
+suite('storageservicesettings-tests', function () {
+ test('testCreateFromConnectionStringWithServiceBusAutomaticCase', function () {
+ // Setup
+ var expectedNamespace = 'mynamespace';
+ var expectedServiceBusEndpoint = 'https://' + expectedNamespace + '.servicebus.windows.net';
+ var expectedWrapName = 'myname';
+ var expectedWrapPassword = 'mypassword';
+ var expectedWrapEndpointUri = 'https://' + expectedNamespace + '-sb.accesscontrol.windows.net/WRAPv0.9';
+ var connectionString = 'Endpoint=' + expectedServiceBusEndpoint + ';SharedSecretIssuer=' + expectedWrapName + ';SharedSecretValue=' + expectedWrapPassword;
+
+ // Test
+ var actual = ServiceBusSettings.createFromConnectionString(connectionString);
+
+ // Assert
+ actual._namespace.should.equal(expectedNamespace);
+ actual._serviceBusEndpointUri.should.equal(expectedServiceBusEndpoint);
+ actual._wrapName.should.equal(expectedWrapName);
+ actual._wrapPassword.should.equal(expectedWrapPassword);
+ actual._wrapEndpointUri.should.equal(expectedWrapEndpointUri);
+ });
+
+ test('testCreateFromConnectionStringWithMissingServiceBusEndpointFail', function () {
+ // Setup
+ var connectionString = 'SharedSecretIssuer=name;SharedSecretValue=password';
+
+ // Test
+ (function() {
+ ServiceBusSettings.createFromConnectionString(connectionString);
+ }).should.throw('The provided connection string ' + connectionString + ' does not have complete configuration settings.');
+ });
+
+ test('testCreateFromConnectionStringWithInvalidServiceBusKeyFail', function () {
+ // Setup
+ var invalidKey = 'InvalidKey';
+ var connectionString = invalidKey + '=value;SharedSecretIssuer=name;SharedSecretValue=password';
+
+ // Test
+ (function() {
+ ServiceBusSettings.createFromConnectionString(connectionString);
+ }).should.throw('Invalid connection string setting key ' + invalidKey.toLowerCase());
+ });
+
+ test('testCreateFromConnectionStringWithCaseInvesitive', function () {
+ // Setup
+ var expectedNamespace = 'mynamespace';
+ var expectedServiceBusEndpoint = 'https://' + expectedNamespace + '.servicebus.windows.net';
+ var expectedWrapName = 'myname';
+ var expectedWrapPassword = 'mypassword';
+ var expectedWrapEndpointUri = 'https://' + expectedNamespace + '-sb.accesscontrol.windows.net/WRAPv0.9';
+ var connectionString = 'eNdPoinT=' + expectedServiceBusEndpoint + ';sHarEdsecRetiSsuer=' + expectedWrapName + ';shArEdsecrEtvAluE=' + expectedWrapPassword;
+
+ // Test
+ var actual = ServiceBusSettings.createFromConnectionString(connectionString);
+
+ // Assert
+ actual._namespace.should.equal(expectedNamespace);
+ actual._serviceBusEndpointUri.should.equal(expectedServiceBusEndpoint);
+ actual._wrapName.should.equal(expectedWrapName);
+ actual._wrapPassword.should.equal(expectedWrapPassword);
+ actual._wrapEndpointUri.should.equal(expectedWrapEndpointUri);
+ });
+});
View
1 test/testlist.txt
@@ -12,6 +12,7 @@ services/core/serviceclient-tests.js
services/core/exponentialretrypolicyfilter-tests.js
services/core/linearretrypolicyfilter-tests.js
services/core/servicesettings-tests.js
+services/core/servicebussettings-tests.js
services/core/storageservicesettings-tests.js
services/queue/queueservice-tests.js
services/table/batchserviceclient-tests.js

0 comments on commit fc16eff

Please sign in to comment.