Skip to content

Commit

Permalink
Created a Utils class and updated calls/test to use this
Browse files Browse the repository at this point in the history
Signed-off-by: EKhan <[email protected]>
  • Loading branch information
enamkhan committed Dec 13, 2024
1 parent b9596c2 commit 1da3379
Show file tree
Hide file tree
Showing 16 changed files with 341 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
*
*/

import { getResourceUri } from "../../../src/methods/common";
import { Utils } from "../../../src/utils";
import { IGetResourceUriOptions } from "../../../src";

describe("getResourceUri", () => {
describe("Utils - getResourceUri", () => {

let error: any;
let response: any;
let endPoint: string;

describe("validation", () => {
beforeEach(() => {
Expand All @@ -25,7 +25,7 @@ describe("getResourceUri", () => {

it("should throw error if resourceName is empty", async () => {
try {
response = getResourceUri("", "", "");
response = Utils.getResourceUri("");
} catch (err) {
error = err;
}
Expand All @@ -37,7 +37,7 @@ describe("getResourceUri", () => {

it("should throw error if resourceName is undefined", async () => {
try {
response = getResourceUri("", "", undefined);
response = Utils.getResourceUri(undefined);
} catch (err) {
error = err;
}
Expand All @@ -49,7 +49,7 @@ describe("getResourceUri", () => {

it("should throw error if resourceName is null", async () => {
try {
response = getResourceUri("", "", null);
response = Utils.getResourceUri(null);
} catch (err) {
error = err;
}
Expand All @@ -69,19 +69,25 @@ describe("getResourceUri", () => {

it("should be able to get a resource uri with only the resource name specified", async () => {
try {
response = getResourceUri("", "", "resource1");
response = Utils.getResourceUri("resource1");
} catch (err) {
error = err;
}

expect(response).toBeDefined();
expect(error).toBeUndefined();
expect(response).toEqual("/CICSSystemManagement/resource1//");
expect(response).toEqual("/CICSSystemManagement/resource1/");
});

it("should be able to get a resource uri with the cicsplex and resource name specified", async () => {
try {
response = getResourceUri("cicsplex1", "", "resource1");

const options: IGetResourceUriOptions = {
"cicsPlex": "cicsplex1",
"regionName": ""
};

response = Utils.getResourceUri("resource1", options);
} catch (err) {
error = err;
}
Expand All @@ -93,7 +99,12 @@ describe("getResourceUri", () => {

it("should be able to get a resource uri with the region and resource names specified", async () => {
try {
response = getResourceUri("", "region1", "resource1");
const options: IGetResourceUriOptions = {
"cicsPlex": "",
"regionName": "region1"
};

response = Utils.getResourceUri("resource1", options);
} catch (err) {
error = err;
}
Expand All @@ -105,7 +116,12 @@ describe("getResourceUri", () => {

it("should be able to get a resource uri with the plex, region and resource names specified", async () => {
try {
response = getResourceUri("cicsplex1", "region1", "resource1");
const options: IGetResourceUriOptions = {
"cicsPlex": "cicsplex1",
"regionName": "region1"
};

response = Utils.getResourceUri("resource1", options);
} catch (err) {
error = err;
}
Expand All @@ -117,7 +133,13 @@ describe("getResourceUri", () => {

it("should be able to get a resource uri with the criteria is unspecified", async () => {
try {
response = getResourceUri("cicsplex1", "region1", "resource1", "");
const options: IGetResourceUriOptions = {
"cicsPlex": "cicsplex1",
"regionName": "region1",
"criteria": ""
};

response = Utils.getResourceUri("resource1", options);
} catch (err) {
error = err;
}
Expand All @@ -129,7 +151,13 @@ describe("getResourceUri", () => {

it("should be able to get a resource uri with the criteria is specified", async () => {
try {
response = getResourceUri("cicsplex1", "region1", "resource1", "NAME=test");
const options: IGetResourceUriOptions = {
"cicsPlex": "cicsplex1",
"regionName": "region1",
"criteria": "NAME=test"
};

response = Utils.getResourceUri("resource1", options);
} catch (err) {
error = err;
}
Expand All @@ -141,7 +169,14 @@ describe("getResourceUri", () => {

it("should be able to get a resource uri with the parameter is unspecified", async () => {
try {
response = getResourceUri("cicsplex1", "region1", "resource1", "", "");
const options: IGetResourceUriOptions = {
"cicsPlex": "cicsplex1",
"regionName": "region1",
"criteria": "",
"parameter": ""
};

response = Utils.getResourceUri("resource1", options);
} catch (err) {
error = err;
}
Expand All @@ -153,7 +188,14 @@ describe("getResourceUri", () => {

it("should be able to get a resource uri with the parameter is specified", async () => {
try {
response = getResourceUri("cicsplex1", "region1", "resource1", "", "PARAM=test");
const options: IGetResourceUriOptions = {
"cicsPlex": "cicsplex1",
"regionName": "region1",
"criteria": "",
"parameter": "PARAM=test"
};

response = Utils.getResourceUri("resource1", options);
} catch (err) {
error = err;
}
Expand All @@ -165,7 +207,14 @@ describe("getResourceUri", () => {

it("should be able to get a resource uri when both criteria and parameter are specified", async () => {
try {
response = getResourceUri("cicsplex1", "region1", "resource1", "NAME=test1", "PARAM=test2");
const options: IGetResourceUriOptions = {
"cicsPlex": "cicsplex1",
"regionName": "region1",
"criteria": "NAME=test1",
"parameter": "PARAM=test2"
};

response = Utils.getResourceUri("resource1", options);
} catch (err) {
error = err;
}
Expand Down
42 changes: 42 additions & 0 deletions packages/sdk/src/doc/IGetResourceUriOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* 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 interface IGetResourceUriOptions {

/**
* CICS Plex of the program
*/
cicsPlex?: string;

/**
* The name of the CICS region of the program
*/
regionName?: string;

/**
* Criteria by which to filter the records
*
* Examples:
* "TRANID=TRAN"
* "PROGRAM=PRG*"
* "NAME=C* AND PROGRAM=D*"
*/
criteria?: string;

/**
* Parameter by which to refine the records
*
* Example:
* "CSDGROUP(GRP1)"
* "CSDGROUP(D*)"
*/
parameter?: string;
}
1 change: 1 addition & 0 deletions packages/sdk/src/doc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export * from "./IResourceParms";
export * from "./ITransactionParms";
export * from "./IURIMapParms";
export * from "./IWebServiceParms";
export * from "./IGetResourceUriOptions";
13 changes: 9 additions & 4 deletions packages/sdk/src/methods/add-to-list/AddToList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import { AbstractSession, ImperativeExpect, Logger } from "@zowe/imperative";
import { CicsCmciRestClient } from "../../rest";
import { CicsCmciConstants } from "../../constants";
import { getResourceUri } from "../common";
import { ICMCIApiResponse, ICSDGroupParms } from "../../doc";
import { Utils } from "../../utils";
import { ICMCIApiResponse, ICSDGroupParms, IGetResourceUriOptions } from "../../doc";

/**
* Add a new CSD Group resource to a CSD List in CICS through CMCI REST API
Expand All @@ -32,8 +32,13 @@ export function addCSDGroupToList(session: AbstractSession, parms: ICSDGroupParm

Logger.getAppLogger().debug("Attempting to add a CSD Group to a CSD List with the following parameters:\n%s", JSON.stringify(parms));

const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName,
CicsCmciConstants.CICS_CSDGROUP, "NAME=='" + parms.name + "'");
const options: IGetResourceUriOptions = {
"cicsPlex": parms.cicsPlex,
"regionName": parms.regionName,
"criteria": `NAME=='${parms.name}'`
};

const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_CSDGROUP, options);

const requestBody: any = {
request: {
Expand Down
49 changes: 0 additions & 49 deletions packages/sdk/src/methods/common/Common.ts

This file was deleted.

Loading

0 comments on commit 1da3379

Please sign in to comment.