Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Merge branch 'sqlserver' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Rodrigues committed Jan 23, 2013
2 parents 00e3b7e + 9a00f20 commit 8e95416
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 5 deletions.
10 changes: 9 additions & 1 deletion lib/services/core/serviceclient.js
Expand Up @@ -117,6 +117,8 @@ function ServiceClient(host, authenticationProvider) {
this.proxyProtocol = 'http:'
this.authenticationProvider = authenticationProvider;
this.logger = new Logger(Logger.LogLevels.INFO);

this.xml2jsVersion = '0.2';
}

util.inherits(ServiceClient, events.EventEmitter);
Expand Down Expand Up @@ -493,7 +495,13 @@ ServiceClient.prototype._parseResponse = function (response) {
parsedBody = { parsingError: error };
}
} else {
var parser = new xml2js.Parser({normalize: false, trim: false});
var settings = xml2js.defaults[this.xml2jsVersion];
settings.normalize = false;
settings.trim = false;
settings.attrkey = Constants.XML_METADATA_MARKER;
settings.charkey = Constants.XML_VALUE_MARKER;

var parser = new xml2js.Parser(settings);
var parseError = null;
parser.on('error', function (e) { parseError = e; });
parser.parseString(response.body);
Expand Down
4 changes: 2 additions & 2 deletions lib/services/serviceManagement/models/parseserverresponse.js
Expand Up @@ -29,7 +29,7 @@ function parseResult(body) {
return;
}

var result = null;
var result = body;

if( _.isArray(body)) {
if (body.length === 1 && !_.isUndefined(body[0]) && !_.isObject(body[0])) {
Expand All @@ -41,7 +41,7 @@ function parseResult(body) {
result.push(parseResult(entry));
});
}
} else {
} else if (_.isObject(body)) {
result = { };
_.each(_.keys(body), function (entry) {
if (entry !== Constants.XML_METADATA_MARKER) {
Expand Down
5 changes: 3 additions & 2 deletions lib/services/serviceManagement/servicemanagementservice.js
Expand Up @@ -55,6 +55,7 @@ function ServiceManagementService(subscriptionId, authentication, hostOptions) {

this.subscriptionId = subscriptionId;
this.serialize = new ServiceManagementSerialize();
this.xml2jsVersion = '0.1';
}

util.inherits(ServiceManagementService, ServiceManagementClient);
Expand Down Expand Up @@ -1366,8 +1367,8 @@ ServiceManagementService.prototype.addCertificate = function(serviceName, data,
* Deletes a specified certificate.
*
* @param {string} serviceName The name of the hosted service. Required.
* @param {string} serviceName Certificate thumbprint algorithm. Required.
* @param {string} serviceName Certificate thumbprint. Required.
* @param {string} algorithm Certificate thumbprint algorithm. Required.
* @param {string} thumbprint Certificate thumbprint. Required.
* @param {function} callback The callback function called on completion. Required.
*/
ServiceManagementService.prototype.deleteCertificate = function(serviceName, algorithm, thumbprint, callback) {
Expand Down
175 changes: 175 additions & 0 deletions test/services/serviceManagement/servicemanagementservice-tests.js
@@ -0,0 +1,175 @@
/**
* Copyright (c) Microsoft. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var should = require('should');
var mocha = require('mocha');
var uuid = require('node-uuid');

var testutil = require('../../util/util');

var azure = testutil.libRequire('azure');

describe('Service Management', function () {
var service;

before(function () {
var subscriptionId = process.env['AZURE_SUBSCRIPTION_ID'];
var auth = { keyvalue: process.env['AZURE_CERTIFICATE_KEY'], certvalue: process.env['AZURE_CERTIFICATE'] };
service = azure.createServiceManagementService(
subscriptionId, auth,
{ serializetype: 'XML'});
});

describe('list locations', function () {
it('should list all locations', function (done) {
service.listLocations(function (err, response) {
should.exist(response.body);
should.exist(response.body.filter(function (location) {
return location.DisplayName === 'West Europe' &&
location.Name === 'West Europe' &&
location.AvailableServices !== undefined &&
location.AvailableServices.AvailableService !== undefined &&
location.AvailableServices.AvailableService.length === 3
}));

done(err);
});
});
});

describe('hosted services', function () {
var originalHostedServices;
var hostedServiceName = 'xplatcli-' + uuid.v4().substr(0, 8);
var hostedServiceLocation = 'West US';

before(function (done) {
service.listHostedServices(function (err, response) {
originalHostedServices = response;

service.createHostedService(hostedServiceName, { Location: hostedServiceLocation }, done);
});
});

after(function (done) {
service.deleteHostedService(hostedServiceName, done);
});

it('should list created hosted service', function (done) {
service.listHostedServices(function (err, response) {
should.not.exist(err);
should.exist(response.body.filter(function (hostedService) {
return hostedService.ServiceName === hostedServiceName;
}));

done(err);
});
});

it('should get created hosted service', function (done) {
service.getHostedService(hostedServiceName, function (err, response) {
should.not.exist(err);

response.body.ServiceName.should.equal(hostedServiceName);
response.body.HostedServiceProperties.Description.should.equal('Service host');
response.body.HostedServiceProperties.Location.should.equal(hostedServiceLocation);
response.body.HostedServiceProperties.Status.should.equal('Created');

done(err);
});
});

it('should get created hosted service properties', function (done) {
service.getHostedServiceProperties(hostedServiceName, function (err, response) {
should.not.exist(err);

response.body.ServiceName.should.equal(hostedServiceName);
response.body.HostedServiceProperties.Description.should.equal('Service host');
response.body.HostedServiceProperties.Location.should.equal(hostedServiceLocation);
response.body.HostedServiceProperties.Status.should.equal('Created');

done(err);
});
});

it('should get created hosted service properties', function (done) {
service.getHostedServiceProperties(hostedServiceName, function (err, response) {
should.not.exist(err);

response.body.ServiceName.should.equal(hostedServiceName);
response.body.HostedServiceProperties.Description.should.equal('Service host');
response.body.HostedServiceProperties.Location.should.equal(hostedServiceLocation);
response.body.HostedServiceProperties.Status.should.equal('Created');

done(err);
});
});
});

describe('storage accounts', function () {
var originalStorageAccounts;
var storageAccountName = 'xplatcli' + uuid.v4().substr(0, 8).replace(/-/g, '');
var storageAccountLocation = 'West US';

before(function (done) {
service.listStorageAccounts(function (err, response) {
originalStorageAccounts = response;

service.createStorageAccount(storageAccountName, { Location: storageAccountLocation }, done);
});
});

after(function (done) {
service.deleteStorageAccount(storageAccountName, done);
});

it('should list storage accounts', function (done) {
service.listStorageAccounts(function (err, response) {
should.not.exist(err);

should.exist(response.body.filter(function (storageAccount) {
return storageAccount.ServiceName === storageAccountName;
}));

done(err);
});
});

it('should get created storage account properties', function (done) {
service.getStorageAccountProperties(storageAccountName, function (err, response) {
should.not.exist(err);

response.body.ServiceName.should.equal(storageAccountName);

// TODO: fix issue with handling null values for description
// response.body.StorageServiceProperties.Description.should.be.null

response.body.StorageServiceProperties.Location.should.equal(storageAccountLocation);

done(err);
});
});

it('should get created storage account keys', function (done) {
service.getStorageAccountKeys(storageAccountName, function (err, response) {
should.not.exist(err);

response.body.StorageServiceKeys.Primary.should.not.be.null;
response.body.StorageServiceKeys.Secondary.should.not.be.null;

done(err);
});
});
});
});
1 change: 1 addition & 0 deletions test/testlist.txt
Expand Up @@ -22,6 +22,7 @@ services/table/sharedkeylitetable-tests.js
services/serviceBus/servicebusservice-tests.js
services/serviceBus/wrapservice-tests.js
services/serviceBus/wraptokenmanager-tests.js
services/serviceManagement/servicemanagementservice-tests.js
services/serviceManagement/sqldatabaseservice-tests.js
services/table/tablequery-tests.js
services/table/tableservice-batch-tests.js
Expand Down

0 comments on commit 8e95416

Please sign in to comment.