-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: EKhan <[email protected]>
- Loading branch information
Showing
3 changed files
with
253 additions
and
3 deletions.
There are no files selected for viewing
200 changes: 200 additions & 0 deletions
200
packages/vsce/__tests__/__unit__/utils/plexUtils.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
/** | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
* | ||
*/ | ||
|
||
import * as profileUtils from "../../../src/utils/plexUtils"; | ||
|
||
describe("Profile Utils tests", () => { | ||
describe("compareCicsplexes", () => { | ||
it("should return 0 as both are the same", () => { | ||
const plex1 = { | ||
status: "ACTIVE", | ||
mpstatus: "YES", | ||
accesstype: "LOCAL" | ||
}; | ||
|
||
const plex2 = { | ||
status: "ACTIVE", | ||
mpstatus: "YES", | ||
accesstype: "LOCAL" | ||
}; | ||
|
||
const response = profileUtils.compareCicsplexes(plex1, plex2); | ||
expect(response).toEqual(0); | ||
}); | ||
|
||
it("should return -1 as plex1 has INACTIVE status", () => { | ||
const plex1 = { | ||
status: "INACTIVE", | ||
mpstatus: "YES", | ||
accesstype: "LOCAL" | ||
}; | ||
|
||
const plex2 = { | ||
status: "ACTIVE", | ||
mpstatus: "YES", | ||
accesstype: "LOCAL" | ||
}; | ||
|
||
const response = profileUtils.compareCicsplexes(plex1, plex2); | ||
expect(response).toEqual(-1); | ||
}); | ||
|
||
it("should return -1 as plex1 has mpstatus NO", () => { | ||
const plex1 = { | ||
status: "ACTIVE", | ||
mpstatus: "NO", | ||
accesstype: "LOCAL" | ||
}; | ||
|
||
const plex2 = { | ||
status: "ACTIVE", | ||
mpstatus: "YES", | ||
accesstype: "LOCAL" | ||
}; | ||
|
||
const response = profileUtils.compareCicsplexes(plex1, plex2); | ||
expect(response).toEqual(-1); | ||
}); | ||
|
||
it("should return -1 as plex1 has accesstype ADJACENT", () => { | ||
const plex1 = { | ||
status: "ACTIVE", | ||
mpstatus: "YES", | ||
accesstype: "ADJACENT" | ||
}; | ||
|
||
const plex2 = { | ||
status: "ACTIVE", | ||
mpstatus: "YES", | ||
accesstype: "LOCAL" | ||
}; | ||
|
||
const response = profileUtils.compareCicsplexes(plex1, plex2); | ||
expect(response).toEqual(-1); | ||
}); | ||
|
||
it("should return 1 as plex2 has INACTIVE status", () => { | ||
const plex1 = { | ||
status: "ACTIVE", | ||
mpstatus: "YES", | ||
accesstype: "LOCAL" | ||
}; | ||
|
||
const plex2 = { | ||
status: "INACTIVE", | ||
mpstatus: "YES", | ||
accesstype: "LOCAL" | ||
}; | ||
|
||
const response = profileUtils.compareCicsplexes(plex1, plex2); | ||
expect(response).toEqual(1); | ||
}); | ||
|
||
it("should return 1 as plex2 has mpstatus NO", () => { | ||
const plex1 = { | ||
status: "ACTIVE", | ||
mpstatus: "YES", | ||
accesstype: "LOCAL" | ||
}; | ||
|
||
const plex2 = { | ||
status: "ACTIVE", | ||
mpstatus: "NO", | ||
accesstype: "LOCAL" | ||
}; | ||
|
||
const response = profileUtils.compareCicsplexes(plex1, plex2); | ||
expect(response).toEqual(1); | ||
}); | ||
|
||
it("should return 1 as plex2 has accesstype ADJACENT", () => { | ||
const plex1 = { | ||
status: "ACTIVE", | ||
mpstatus: "YES", | ||
accesstype: "LOCAL" | ||
}; | ||
|
||
const plex2 = { | ||
status: "ACTIVE", | ||
mpstatus: "YES", | ||
accesstype: "ADJACENT" | ||
}; | ||
|
||
const response = profileUtils.compareCicsplexes(plex1, plex2); | ||
expect(response).toEqual(1); | ||
}); | ||
}); | ||
|
||
describe("filterCicsplexByConstraints", () => { | ||
it("should return an array of 2 plexes as both are valid", () => { | ||
const plexes = [ | ||
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX1', status: 'ACTIVE'}, | ||
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX2', status: 'ACTIVE'} | ||
]; | ||
const allplexes = profileUtils.filterCicsplexByConstraints(plexes); | ||
expect(allplexes.size).toEqual(2); | ||
}); | ||
|
||
|
||
it("should return an array of 1 plex as one in inactive both are valid", () => { | ||
const plexes = [ | ||
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX1', status: 'INACTIVE'}, | ||
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX1', status: 'ACTIVE'} | ||
]; | ||
const allplexes = profileUtils.filterCicsplexByConstraints(plexes); | ||
expect(allplexes.size).toEqual(1); | ||
}); | ||
|
||
|
||
it("should return an array of 1 plex even though both are inactive", () => { | ||
const plexes = [ | ||
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX1', status: 'INACTIVE'}, | ||
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX1', status: 'INACTIVE'} | ||
]; | ||
const allplexes = profileUtils.filterCicsplexByConstraints(plexes); | ||
expect(allplexes.size).toEqual(1); | ||
}); | ||
|
||
|
||
it("should return an array of 1 plex as one of the plexes has mpstatus NO", () => { | ||
const plexes = [ | ||
{accesstype: 'LOCAL', mpstatus: 'NO', plexname: 'PLEX1', status: 'ACTIVE'}, | ||
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX1', status: 'ACTIVE'} | ||
]; | ||
const allplexes = profileUtils.filterCicsplexByConstraints(plexes); | ||
expect(allplexes.size).toEqual(1); | ||
}); | ||
|
||
it("should return an array of 1 plex as one of the plexes has accesstype ADJACENT", () => { | ||
const plexes = [ | ||
{accesstype: 'ADJACENT', mpstatus: 'YES', plexname: 'PLEX1', status: 'ACTIVE'}, | ||
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX1', status: 'ACTIVE'} | ||
]; | ||
const allplexes = profileUtils.filterCicsplexByConstraints(plexes); | ||
expect(allplexes.size).toEqual(1); | ||
}); | ||
|
||
|
||
it("should return an array of 3 plex", () => { | ||
const plexes = [ | ||
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX1', status: 'ACTIVE'}, | ||
{accesstype: 'LOCAL', mpstatus: 'NO', plexname: 'PLEX2#', status: 'ACTIVE'}, | ||
{accesstype: 'ADJACENT', mpstatus: 'YES', plexname: 'PLEX2#', status: 'ACTIVE'}, | ||
{accesstype: 'LOCAL', mpstatus: 'NO', plexname: 'PLEX3#', status: 'ACTIVE'}, | ||
{accesstype: 'ADJACENT', mpstatus: 'YES', plexname: 'PLEX3#', status: 'ACTIVE'} | ||
]; | ||
|
||
const allplexes = profileUtils.filterCicsplexByConstraints(plexes); | ||
expect(allplexes.size).toEqual(3); | ||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
* | ||
*/ | ||
|
||
export function compareCicsplexes(plex1: any, plex2: any): number { | ||
const compare = function(val1: boolean, val2: boolean): Number { | ||
return Number(val1) - Number(val2); | ||
}; | ||
|
||
let result = (compare(plex1["status"] === "ACTIVE", plex2["status"] === "ACTIVE")); | ||
if (result != 0) { | ||
return result.valueOf(); | ||
} | ||
result = (compare(plex1["mpstatus"] === "YES", plex2["mpstatus"] == "YES")); | ||
if (result != 0) { | ||
return result.valueOf(); | ||
} | ||
result = (compare(plex1["accesstype"] === "LOCAL", plex2["accesstype"] === "LOCAL")); | ||
return result.valueOf(); | ||
} | ||
|
||
export function filterCicsplexByConstraints(cicscicsplex: any[]) { | ||
|
||
let allcicsplexes = new Map<string, {}>(); | ||
|
||
for (const plex of cicscicsplex) { | ||
let plexname: string = plex["plexname"]; | ||
|
||
let old = allcicsplexes.get(plexname); | ||
if (old) { | ||
if (compareCicsplexes(plex, old) > 0) { | ||
allcicsplexes.set(plexname, plex); | ||
} | ||
} else { | ||
allcicsplexes.set(plexname, plex); | ||
} | ||
} | ||
return allcicsplexes; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters