Connection URI with complete options (finalized) (#22735)

* Connection URI made to include every option available instead of basic details (#22045)

* Revert "Merge remote-tracking branch 'origin' into feat/connectionUri"

This reverts commit 11b2d31bf99e216daee823f732254f69a017fee1, reversing
changes made to 36e4db8c0744f81565efdfd2f56a3ae3c0026896.

* Revert "Revert "Merge remote-tracking branch 'origin' into feat/connectionUri""

This reverts commit f439673c2693e1144c52e04c14e82cd8566c13a6.

* Added changes and fixes for feat connectionuri (#22706)

* add title generation at start

* added await to refreshConnectionTreeTitles
This commit is contained in:
Alex Ma
2023-04-18 11:08:48 -07:00
committed by GitHub
parent a9bc34acf0
commit b69e87df15
27 changed files with 1641 additions and 86 deletions

View File

@@ -77,6 +77,8 @@ export class TreeUpdateUtils {
}
const previousTreeInput = tree.getInput();
if (treeInput) {
let treeArray = TreeUpdateUtils.alterTreeChildrenTitles([treeInput]);
treeInput = treeArray[0];
await tree.setInput(treeInput);
}
if (previousTreeInput instanceof Disposable) {
@@ -94,13 +96,29 @@ export class TreeUpdateUtils {
}
}
/**
* Calls alterConnectionTitles on all levels of the Object Explorer Tree
* so that profiles in connection groups can have distinguishing titles too.
*/
public static alterTreeChildrenTitles(inputGroups: ConnectionProfileGroup[]): ConnectionProfileGroup[] {
inputGroups.forEach(group => {
group.children = this.alterTreeChildrenTitles(group.children);
let connections = group.connections;
TreeUpdateUtils.alterConnectionTitles(connections);
group.connections = connections;
});
return inputGroups;
}
/**
* Set input for the registered servers tree.
*/
public static async registeredServerUpdate(tree: ITree | AsyncServerTree, connectionManagementService: IConnectionManagementService, elementToSelect?: any): Promise<void> {
if (tree instanceof AsyncServerTree) {
const treeInput = TreeUpdateUtils.getTreeInput(connectionManagementService);
let treeInput = TreeUpdateUtils.getTreeInput(connectionManagementService);
if (treeInput) {
let treeArray = TreeUpdateUtils.alterTreeChildrenTitles([treeInput]);
treeInput = treeArray[0];
await tree.setInput(treeInput);
}
tree.rerender();
@@ -129,6 +147,8 @@ export class TreeUpdateUtils {
let treeInput = TreeUpdateUtils.getTreeInput(connectionManagementService);
if (treeInput) {
let treeArray = TreeUpdateUtils.alterTreeChildrenTitles([treeInput]);
treeInput = treeArray[0];
const originalInput = tree.getInput();
if (treeInput !== originalInput) {
return tree.setInput(treeInput).then(async () => {
@@ -375,4 +395,85 @@ export class TreeUpdateUtils {
}
return connectionProfile;
}
/**
* Change the connection title to display only the unique properties among profiles.
*/
private static alterConnectionTitles(inputList: ConnectionProfile[]): void {
let profileListMap = new Map<string, number[]>();
// Map the indices of profiles that share the same connection name.
for (let i = 0; i < inputList.length; i++) {
// do not add if the profile is still loading as that will result in erroneous entries.
if (inputList[i].hasServerCapabilities && inputList[i].hasLoaded()) {
let titleKey = inputList[i].getOriginalTitle();
if (profileListMap.has(titleKey)) {
let profilesForKey = profileListMap.get(titleKey);
profilesForKey.push(i);
profileListMap.set(titleKey, profilesForKey);
}
else {
profileListMap.set(titleKey, [i]);
}
}
}
profileListMap.forEach(function (indexes, titleString) {
if (profileListMap.get(titleString)?.length > 1) {
let combinedOptions = [];
let needSpecial = false;
if (titleString === inputList[indexes[0]].connectionName) {
// check for potential connections with the same name but technically different connections.
let listOfDuplicates = indexes.filter(item => inputList[item].getOptionsKey() !== inputList[indexes[0]].getOptionsKey());
if (listOfDuplicates.length > 0) {
// if we do find duplicates, we will need to include the special properties.
needSpecial = true;
}
}
indexes.forEach((indexValue) => {
// Add all possible options across all profiles with the same title to an option list.
let valueOptions = inputList[indexValue].getConnectionOptionsList(needSpecial, false);
combinedOptions = combinedOptions.concat(valueOptions.filter(item => combinedOptions.indexOf(item) < 0));
});
// Generate list of non default option keys for each profile that shares the same basic connection name.
let optionKeyMap = new Map<ConnectionProfile, string[]>();
let optionValueOccuranceMap = new Map<string, number>();
for (let p = 0; p < indexes.length; p++) {
optionKeyMap.set(inputList[indexes[p]], []);
for (let i = 0; i < combinedOptions.length; i++) {
// See if the option is not default for the inputList profile or is.
if (inputList[indexes[p]].getConnectionOptionsList(needSpecial, true).indexOf(combinedOptions[i]) > -1) {
let optionValue = inputList[indexes[p]].getOptionValue(combinedOptions[i].name);
let currentArray = optionKeyMap.get(inputList[indexes[p]]);
let valueString = combinedOptions[i].name + ConnectionProfile.displayNameValueSeparator + optionValue;
if (!optionValueOccuranceMap.get(valueString)) {
optionValueOccuranceMap.set(valueString, 0);
}
optionValueOccuranceMap.set(valueString, optionValueOccuranceMap.get(valueString) + 1);
currentArray.push(valueString);
optionKeyMap.set(inputList[indexes[p]], currentArray);
}
}
}
// Filter out options that are found in ALL the entries with the same basic name.
optionValueOccuranceMap.forEach(function (count, optionValue) {
optionKeyMap.forEach(function (connOptionValues, profile) {
if (count === optionKeyMap.size) {
optionKeyMap.set(profile, connOptionValues.filter(value => value !== optionValue));
}
});
});
// Generate the final unique connection string for each profile in the list.
optionKeyMap.forEach(function (connOptionValues, profile) {
let uniqueOptionString = connOptionValues.join(ConnectionProfile.displayIdSeparator);
if (uniqueOptionString.length > 0) {
profile.title += ' (' + uniqueOptionString + ')';
}
});
}
});
}
}

View File

@@ -0,0 +1,606 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
import { TreeUpdateUtils } from 'sql/workbench/services/objectExplorer/browser/treeUpdateUtils';
import * as assert from 'assert';
import * as azdata from 'azdata';
suite('treeUpdateUtils alterConnection', () => {
let capabilitiesService: TestCapabilitiesService;
const testOption1 = {
name: 'testOption1',
displayName: 'testOption1',
description: 'test description',
groupName: 'test group name',
valueType: 'string',
specialValueType: undefined,
defaultValue: '',
categoryValues: undefined,
isIdentity: false,
isRequired: false
};
const testOption2 = {
name: 'testOption2',
displayName: 'testOption2',
description: 'test description',
groupName: 'test group name',
valueType: 'number',
specialValueType: undefined,
defaultValue: '10',
categoryValues: undefined,
isIdentity: false,
isRequired: false
};
const testOption3 = {
name: 'testOption3',
displayName: 'testOption3',
description: 'test description',
groupName: 'test group name',
valueType: 'string',
specialValueType: undefined,
defaultValue: 'default',
categoryValues: undefined,
isIdentity: false,
isRequired: false
};
setup(() => {
capabilitiesService = new TestCapabilitiesService();
let mainProvider = capabilitiesService.capabilities[mssqlProviderName];
let mainProperties = mainProvider.connection;
let mainOptions = mainProperties.connectionOptions;
mainOptions.push((testOption1 as azdata.ConnectionOption));
mainOptions.push((testOption2 as azdata.ConnectionOption));
mainOptions.push((testOption3 as azdata.ConnectionOption));
mainProperties.connectionOptions = mainOptions;
mainProvider.connection = mainProperties;
capabilitiesService.capabilities['MSSQL'] = mainProvider;
});
test('Default properties should not be added to the altered title', async () => {
let profile1: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3',
groupId: 'g3',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: { testOption3: 'default', testOption2: '10' },
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let profile2: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3',
groupId: 'g3',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: { testOption3: 'nonDefault' },
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let connectionProfile1 = new ConnectionProfile(capabilitiesService, profile1);
let connectionProfile2 = new ConnectionProfile(capabilitiesService, profile2);
let connectionProfileGroup = new ConnectionProfileGroup('g3', undefined, 'g3', undefined, undefined);
connectionProfileGroup.addConnections([connectionProfile1, connectionProfile2]);
let updatedProfileGroup = TreeUpdateUtils.alterTreeChildrenTitles([connectionProfileGroup]);
let updatedTitleMap = updatedProfileGroup[0].connections.map(profile => profile.title);
assert.equal(connectionProfile1.title, updatedTitleMap[0]);
assert.equal(connectionProfile1.title + ' (testOption3=nonDefault)', updatedTitleMap[1]);
});
test('Similar connections should have different titles based on all differing properties', async () => {
let profile1: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3',
groupId: 'g3',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: { testOption2: '15', testOption1: 'test string 1', testOption3: 'nonDefault' },
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let profile2: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3',
groupId: 'g3',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: { testOption2: '50', testOption1: 'test string 1', testOption3: 'nonDefault' },
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let profile3: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3',
groupId: 'g3',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: { testOption2: '15', testOption1: 'test string 2', testOption3: 'nonDefault' },
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let profile4: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3',
groupId: 'g3',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: { testOption2: '50', testOption1: 'test string 2', testOption3: 'nonDefault' },
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let defaultProfile: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3',
groupId: 'g3',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: { testOption3: 'nonDefault' },
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let defaultConnectionProfile = new ConnectionProfile(capabilitiesService, defaultProfile);
let connectionProfile1 = new ConnectionProfile(capabilitiesService, profile1);
let connectionProfile2 = new ConnectionProfile(capabilitiesService, profile2);
let connectionProfile3 = new ConnectionProfile(capabilitiesService, profile3);
let connectionProfile4 = new ConnectionProfile(capabilitiesService, profile4);
let connectionProfileGroup = new ConnectionProfileGroup('g3', undefined, 'g3', undefined, undefined);
let originalTitle = defaultConnectionProfile.title;
connectionProfileGroup.addConnections([defaultConnectionProfile, connectionProfile1, connectionProfile2, connectionProfile3, connectionProfile4]);
let updatedProfileGroup = TreeUpdateUtils.alterTreeChildrenTitles([connectionProfileGroup]);
let updatedTitleMap = updatedProfileGroup[0].connections.map(profile => profile.title);
assert.equal(originalTitle, updatedTitleMap[0]);
assert.equal(originalTitle + ' (testOption1=test string 1; testOption2=15)', updatedTitleMap[1]);
assert.equal(originalTitle + ' (testOption1=test string 1; testOption2=50)', updatedTitleMap[2]);
assert.equal(originalTitle + ' (testOption1=test string 2; testOption2=15)', updatedTitleMap[3]);
assert.equal(originalTitle + ' (testOption1=test string 2; testOption2=50)', updatedTitleMap[4]);
});
test('identical connections should have same title if on different levels', async () => {
let profile1: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3',
groupId: 'g3',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: {},
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let profile2: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3-1',
groupId: 'g3-1',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: {},
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let profile3: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3-2',
groupId: 'g3-2',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: {},
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let connectionProfile1 = new ConnectionProfile(capabilitiesService, profile1);
let connectionProfile2 = new ConnectionProfile(capabilitiesService, profile2);
let connectionProfile3 = new ConnectionProfile(capabilitiesService, profile3);
let connectionProfileGroup = new ConnectionProfileGroup('g3', undefined, 'g3', undefined, undefined);
let childConnectionProfileGroup = new ConnectionProfileGroup('g3-1', undefined, 'g3-1', undefined, undefined);
let grandChildConnectionProfileGroup = new ConnectionProfileGroup('g3-2', undefined, 'g3-2', undefined, undefined);
childConnectionProfileGroup.addConnections([connectionProfile2]);
connectionProfileGroup.addConnections([connectionProfile1]);
grandChildConnectionProfileGroup.addConnections([connectionProfile3]);
childConnectionProfileGroup.addGroups([grandChildConnectionProfileGroup]);
connectionProfileGroup.addGroups([childConnectionProfileGroup]);
let updatedProfileGroup = TreeUpdateUtils.alterTreeChildrenTitles([connectionProfileGroup]);
let updatedTitleMap = updatedProfileGroup[0].connections.map(profile => profile.title);
let updatedChildTitleMap = updatedProfileGroup[0].children[0].connections.map(profile => profile.title);
let updatedGrandChildTitleMap = updatedProfileGroup[0].children[0].children[0].connections.map(profile => profile.title);
// Titles should be the same if they're in different levels.
assert.equal(updatedTitleMap[0], updatedChildTitleMap[0]);
assert.equal(updatedTitleMap[0], updatedGrandChildTitleMap[0]);
assert.equal(updatedChildTitleMap[0], updatedGrandChildTitleMap[0]);
});
test('connections should not affect connections on a different level', async () => {
let profile1: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3',
groupId: 'g3',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: { testOption1: 'value1' },
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let profile1a: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3',
groupId: 'g3',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: { testOption1: 'value2' },
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let profile2: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3-1',
groupId: 'g3-1',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: {},
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let connectionProfile1 = new ConnectionProfile(capabilitiesService, profile1);
let connectionProfile1a = new ConnectionProfile(capabilitiesService, profile1a);
let connectionProfile2 = new ConnectionProfile(capabilitiesService, profile2);
let connectionProfileGroup = new ConnectionProfileGroup('g3', undefined, 'g3', undefined, undefined);
let childConnectionProfileGroup = new ConnectionProfileGroup('g3-1', undefined, 'g3-1', undefined, undefined);
childConnectionProfileGroup.addConnections([connectionProfile2]);
connectionProfileGroup.addConnections([connectionProfile1, connectionProfile1a]);
connectionProfileGroup.addGroups([childConnectionProfileGroup]);
let updatedProfileGroup = TreeUpdateUtils.alterTreeChildrenTitles([connectionProfileGroup]);
let updatedTitleMap = updatedProfileGroup[0].connections.map(profile => profile.title);
let updatedChildTitleMap = updatedProfileGroup[0].children[0].connections.map(profile => profile.title);
// Titles should be altered for the first group only.
assert.equal(updatedChildTitleMap[0] + ' (testOption1=value1)', updatedTitleMap[0]);
assert.equal(updatedChildTitleMap[0] + ' (testOption1=value2)', updatedTitleMap[1]);
});
test('non default options should only be appended to the connection with non default options', async () => {
let profile1: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3',
groupId: 'g3',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: {},
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let profile2: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3',
groupId: 'g3',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: { testOption1: 'value1', testOption2: '15' },
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let connectionProfile1 = new ConnectionProfile(capabilitiesService, profile1);
let connectionProfile2 = new ConnectionProfile(capabilitiesService, profile2);
let connectionProfileGroup = new ConnectionProfileGroup('g3', undefined, 'g3', undefined, undefined);
connectionProfileGroup.addConnections([connectionProfile1, connectionProfile2]);
let updatedProfileGroup = TreeUpdateUtils.alterTreeChildrenTitles([connectionProfileGroup]);
let updatedTitleMap = updatedProfileGroup[0].connections.map(profile => profile.title);
//Title for second profile should be the same as the first but with non default options appended.
assert.equal(updatedTitleMap[0] + ' (testOption1=value1; testOption2=15)', updatedTitleMap[1]);
});
test('identical profiles added into one group and separate groups should have the same options appended', async () => {
let profile1: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3',
groupId: 'g3',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: { testOption1: 'value1', testOption2: '15' },
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let profile2: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3',
groupId: 'g3',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: { testOption1: 'value2', testOption2: '30' },
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let connectionProfile1Base = new ConnectionProfile(capabilitiesService, profile1);
let connectionProfile2Base = new ConnectionProfile(capabilitiesService, profile2);
let connectionProfileGroup = new ConnectionProfileGroup('g3', undefined, 'g3', undefined, undefined);
connectionProfileGroup.addConnections([connectionProfile1Base, connectionProfile2Base]);
profile1.groupFullName = 'g3-1';
profile1.groupId = 'g3-1';
profile2.groupFullName = 'g3-1';
profile2.groupId = 'g3-1';
let connectionProfile1Child = new ConnectionProfile(capabilitiesService, profile1);
let connectionProfile2Child = new ConnectionProfile(capabilitiesService, profile2);
let childConnectionProfileGroup = new ConnectionProfileGroup('g3-1', undefined, 'g3-1', undefined, undefined);
childConnectionProfileGroup.addConnections([connectionProfile1Child, connectionProfile2Child]);
profile1.groupFullName = 'g3-2';
profile1.groupId = 'g3-2';
profile2.groupFullName = 'g3-2';
profile2.groupId = 'g3-2';
let connectionProfile1Grandchild = new ConnectionProfile(capabilitiesService, profile1);
let connectionProfile2Grandchild = new ConnectionProfile(capabilitiesService, profile2);
let grandchildConnectionProfileGroup = new ConnectionProfileGroup('g3-2', undefined, 'g3-2', undefined, undefined);
grandchildConnectionProfileGroup.addConnections([connectionProfile1Grandchild, connectionProfile2Grandchild]);
childConnectionProfileGroup.addGroups([grandchildConnectionProfileGroup]);
connectionProfileGroup.addGroups([childConnectionProfileGroup]);
let updatedProfileGroup = TreeUpdateUtils.alterTreeChildrenTitles([connectionProfileGroup]);
let updatedTitleMap = updatedProfileGroup[0].connections.map(profile => profile.title);
let updatedChildTitleMap = updatedProfileGroup[0].children[0].connections.map(profile => profile.title);
let updatedGrandchildTitleMap = updatedProfileGroup[0].children[0].children[0].connections.map(profile => profile.title);
//Titles for the same profile in different groups should be identical
assert.equal(updatedTitleMap[0], updatedChildTitleMap[0]);
assert.equal(updatedTitleMap[0], updatedGrandchildTitleMap[0]);
assert.equal(updatedTitleMap[1], updatedChildTitleMap[1]);
assert.equal(updatedTitleMap[1], updatedGrandchildTitleMap[1]);
});
test('profiles in adjacent groups on the same layer should not affect titles on nearby groups', async () => {
let profile1: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3a',
groupId: 'g3a',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: {},
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let profile2: IConnectionProfile = {
serverName: 'server3',
databaseName: 'database',
userName: 'user',
password: 'password',
authenticationType: '',
savePassword: true,
groupFullName: 'g3a',
groupId: 'g3a',
getOptionsKey: undefined!,
matches: undefined!,
providerName: 'MSSQL',
options: { testOption1: 'value2', testOption2: '30' },
saveProfile: true,
id: undefined!,
connectionName: undefined!
};
let connectionProfile1a = new ConnectionProfile(capabilitiesService, profile1);
let connectionProfile2a = new ConnectionProfile(capabilitiesService, profile2);
let connectionProfileGroup = new ConnectionProfileGroup('g3', undefined, 'g3', undefined, undefined);
let childConnectionProfileGroup1 = new ConnectionProfileGroup('g3a', undefined, 'g3a', undefined, undefined);
childConnectionProfileGroup1.addConnections([connectionProfile1a, connectionProfile2a]);
profile1.groupFullName = 'g3b';
profile1.groupId = 'g3b';
profile2.groupFullName = 'g3b';
profile2.groupId = 'g3b';
let connectionProfile1b = new ConnectionProfile(capabilitiesService, profile1);
let connectionProfile2b = new ConnectionProfile(capabilitiesService, profile2);
let childConnectionProfileGroup2 = new ConnectionProfileGroup('g3b', undefined, 'g3b', undefined, undefined);
childConnectionProfileGroup2.addConnections([connectionProfile1b, connectionProfile2b]);
connectionProfileGroup.addGroups([childConnectionProfileGroup1]);
connectionProfileGroup.addGroups([childConnectionProfileGroup2]);
let updatedProfileGroup = TreeUpdateUtils.alterTreeChildrenTitles([connectionProfileGroup]);
let updatedChildATitleMap = updatedProfileGroup[0].children[0].connections.map(profile => profile.title);
let updatedChildBTitleMap = updatedProfileGroup[0].children[1].connections.map(profile => profile.title);
//Check that titles are generated properly for the first group.
assert.equal(updatedChildATitleMap[0] + ' (testOption1=value2; testOption2=30)', updatedChildATitleMap[1]);
//Titles for the same profile in adjacent groups should be identical
assert.equal(updatedChildATitleMap[0], updatedChildBTitleMap[0]);
assert.equal(updatedChildATitleMap[1], updatedChildBTitleMap[1]);
});
});