Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SDK getCache method #172

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to the IBM® CICS® Plug-in for Zowe CLI will be documented
## Recent Changes

- Enhancement: Add optional query parameters on getResource SDK method. [#168](https://github.com/zowe/cics-for-zowe-client/issues/168)
- Enhancement: Add getCache method to SDK. [#169](https://github.com/zowe/cics-for-zowe-client/issues/169)

## `6.1.0`

Expand Down
189 changes: 189 additions & 0 deletions packages/sdk/__tests__/__unit__/cache/Cache.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/**
* 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 { Session } from "@zowe/imperative";
import {
CicsCmciConstants,
CicsCmciRestClient,
getCache,
ICacheParms,
ICMCIApiResponse
} from "../../../src";

describe("CMCI - Get Cache", () => {
const content: ICMCIApiResponse = {
response: {
resultsummary: {
api_response1: "1024",
api_response2: "0",
api_response1_alt: "OK",
api_response2_alt: "",
recordcount: "1",
cachetoken: "E0252A3D2292C613",
displayed_recordcount: "1",
},
records: []
}
};
const dummySession = new Session({
user: "fake",
password: "fake",
hostname: "fake",
port: 1490
});

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


describe("validation", () => {
beforeEach(() => {
response = undefined;
error = undefined;
});

it("should throw error if no parms are defined", async () => {
try {
response = await getCache(dummySession, undefined);
} catch (err) {
error = err;
}

expect(response).toBeUndefined();
expect(error).toBeDefined();
expect(error.message).toMatch(/(Cannot read).*undefined/);
});

it("should throw error if cache token is not defined", async () => {
try {
response = await getCache(dummySession, { cacheToken: undefined });
} catch (err) {
error = err;
}

expect(response).toBeUndefined();
expect(error).toBeDefined();
expect(error.message).toContain("CICS Result Cache Token is required");
});

it("should throw error if cache token is missing", async () => {
try {
response = await getCache(dummySession, { cacheToken: "" });
} catch (err) {
error = err;
}

expect(response).toBeUndefined();
expect(error).toBeDefined();
expect(error.message).toContain("Required parameter 'CICS Result Cache Token' must not be blank");
});
});

describe("success scenarios", () => {

const cmciGetSpy = jest.spyOn(CicsCmciRestClient, "getExpectParsedXml").mockResolvedValue(content);

beforeEach(() => {
response = undefined;
error = undefined;
cacheParms = {
cacheToken: "E0252A3D2292C613",
};
cmciGetSpy.mockClear();
cmciGetSpy.mockResolvedValue(content);
});

it("should be able to get a result cache", async () => {
try {
response = await getCache(dummySession, cacheParms);
} catch (err) {
error = err;
}

endPoint = "/" + CicsCmciConstants.CICS_SYSTEM_MANAGEMENT +
"/" + CicsCmciConstants.CICS_RESULT_CACHE +
"/" + cacheParms.cacheToken + "?" + CicsCmciConstants.NO_DISCARD;

expect(response).toEqual(content);
expect(cmciGetSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
});

it("should be able to get a result cache with SUMMONLY", async () => {
try {
cacheParms.summonly = true;
response = await getCache(dummySession, cacheParms);
} catch (err) {
error = err;
}

endPoint = "/" + CicsCmciConstants.CICS_SYSTEM_MANAGEMENT +
"/" + CicsCmciConstants.CICS_RESULT_CACHE +
"/" + cacheParms.cacheToken + "?" + CicsCmciConstants.NO_DISCARD +
"&" + CicsCmciConstants.SUMM_ONLY;

expect(response).toEqual(content);
expect(cmciGetSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
});

it("should be able to get a result cache with start index", async () => {
try {
cacheParms.startIndex = 10;
response = await getCache(dummySession, cacheParms);
} catch (err) {
error = err;
}

endPoint = "/" + CicsCmciConstants.CICS_SYSTEM_MANAGEMENT +
"/" + CicsCmciConstants.CICS_RESULT_CACHE +
"/" + cacheParms.cacheToken + "/" +
"10?" + CicsCmciConstants.NO_DISCARD;

expect(response).toEqual(content);
expect(cmciGetSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
});

it("should be able to get a result cache with start index and count", async () => {
try {
cacheParms.startIndex = 15;
cacheParms.count = 5;
response = await getCache(dummySession, cacheParms);
} catch (err) {
error = err;
}

endPoint = "/" + CicsCmciConstants.CICS_SYSTEM_MANAGEMENT +
"/" + CicsCmciConstants.CICS_RESULT_CACHE +
"/" + cacheParms.cacheToken + "/" +
"15/5?" + CicsCmciConstants.NO_DISCARD;

expect(response).toEqual(content);
expect(cmciGetSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
});

it("should be able to get a result cache without NODISCARD", async () => {
try {
cacheParms.nodiscard = false;
response = await getCache(dummySession, cacheParms);
} catch (err) {
error = err;
}

endPoint = "/" + CicsCmciConstants.CICS_SYSTEM_MANAGEMENT +
"/" + CicsCmciConstants.CICS_RESULT_CACHE +
"/" + cacheParms.cacheToken;

expect(response).toEqual(content);
expect(cmciGetSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
});
});
});
171 changes: 170 additions & 1 deletion packages/sdk/__tests__/__unit__/utils/Utils.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
*
*/

import { Utils } from "../../../src/utils";
import { IGetResourceUriOptions } from "../../../src";
import { IResultCacheParms } from "../../../src/doc/IResultCacheParms";
import { Utils } from "../../../src/utils";

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

Expand Down Expand Up @@ -415,3 +416,171 @@ describe('Utils - enforceParentheses', () => {
expect(output).toEqual("((()))");
});
});

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

let error: any;
let response: any;

describe("validation", () => {
beforeEach(() => {
response = undefined;
error = undefined;
});

it("should throw error if cacheToken is empty", async () => {
try {
response = Utils.getCacheUri("");
} catch (err) {
error = err;
}

expect(response).toBeUndefined();
expect(error).toBeDefined();
expect(error.message).toEqual("Expect Error: Required parameter 'CICS Results Cache Token' must not be blank");
});

it("should throw error if cacheToken is undefined", async () => {
try {
response = Utils.getCacheUri(undefined);
} catch (err) {
error = err;
}

expect(response).toBeUndefined();
expect(error).toBeDefined();
expect(error.message).toEqual("Expect Error: CICS Results Cache Token is required");
});

it("should throw error if cacheToken is null", async () => {
try {
response = Utils.getCacheUri(null);
} catch (err) {
error = err;
}

expect(response).toBeUndefined();
expect(error).toBeDefined();
expect(error.message).toEqual("Expect Error: CICS Results Cache Token is required");
});
});

describe("success scenarios", () => {

beforeEach(() => {
response = undefined;
error = undefined;
});

it("should be able to get a result cache uri with only the cache token specified", async () => {
try {
response = Utils.getCacheUri("abcdefg");
} catch (err) {
error = err;
}

expect(response).toBeDefined();
expect(error).toBeUndefined();
expect(response).toEqual("/CICSSystemManagement/CICSResultCache/abcdefg?NODISCARD");
});

it("should be able to get a result cache with the index specified", async () => {
try {

const options: IResultCacheParms = {
startIndex: 1
};

response = Utils.getCacheUri("abcdefgh", options);
} catch (err) {
error = err;
}

expect(response).toBeDefined();
expect(error).toBeUndefined();
expect(response).toEqual("/CICSSystemManagement/CICSResultCache/abcdefgh/1?NODISCARD");
});

it("should be able to get a result cache with the count specified - ignored with no index", async () => {
try {
const options: IResultCacheParms = {
count: 20
};

response = Utils.getCacheUri("cachetoken", options);
} catch (err) {
error = err;
}

expect(response).toBeDefined();
expect(error).toBeUndefined();
expect(response).toEqual("/CICSSystemManagement/CICSResultCache/cachetoken?NODISCARD");
});

it("should be able to get a result cache with the index and count specified", async () => {
try {
const options: IResultCacheParms = {
startIndex: 10,
count: 20
};

response = Utils.getCacheUri("cachetoken", options);
} catch (err) {
error = err;
}

expect(response).toBeDefined();
expect(error).toBeUndefined();
expect(response).toEqual("/CICSSystemManagement/CICSResultCache/cachetoken/10/20?NODISCARD");
});

it("should be able to get a result cache with SUMMONLY", async () => {
try {
const options: IResultCacheParms = {
summonly: true,
};

response = Utils.getCacheUri("abcdef", options);
} catch (err) {
error = err;
}

expect(response).toBeDefined();
expect(error).toBeUndefined();
expect(response).toEqual("/CICSSystemManagement/CICSResultCache/abcdef?NODISCARD&SUMMONLY");
});

it("should be able to get a result cache and with false NODISCARD", async () => {
try {
const options: IResultCacheParms = {
nodiscard: false
};

response = Utils.getCacheUri("abcdef", options);
} catch (err) {
error = err;
}

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

it("should be able to get a result cache and with summonly but not nodiscard", async () => {
try {
const options: IResultCacheParms = {
summonly: true,
nodiscard: false,
};

response = Utils.getCacheUri("abcdef", options);
} catch (err) {
error = err;
}

expect(response).toBeDefined();
expect(error).toBeUndefined();
expect(response).toEqual("/CICSSystemManagement/CICSResultCache/abcdef?SUMMONLY");
});
});
});
5 changes: 5 additions & 0 deletions packages/sdk/src/constants/CicsCmci.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export const CicsCmciConstants = {
*/
CICS_CSDGROUP_IN_LIST: "CICSCSDGroupInList",

/**
* Specifies the Result Cache part of the URI
*/
CICS_RESULT_CACHE: "CICSResultCache",

/**
* ORDERBY parameter
*/
Expand Down
Loading
Loading