diff --git a/packages/sdk/__tests__/__mocks__/CmciGetResponse.ts b/packages/sdk/__tests__/__mocks__/CmciGetResponse.ts
new file mode 100644
index 00000000..a8bebdf6
--- /dev/null
+++ b/packages/sdk/__tests__/__mocks__/CmciGetResponse.ts
@@ -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 { readFileSync } from "fs";
+import { join } from "path";
+
+export const nodataXmlResponse = readFileSync(join(__dirname, "nodata.xml")).toString();
+export const ok1RecordXmlResponse = readFileSync(join(__dirname, "ok.1_record.xml")).toString();
+export const ok2RecordsXmlResponse = readFileSync(join(__dirname, "ok.2_records.xml")).toString();
+export const okCacheXmlResponse = readFileSync(join(__dirname, "ok.cache.xml")).toString();
+
+export const okContent1Record = {
+ response: {
+ xmlns: "http://www.ibm.com/xmlns/prod/CICS/smw2int",
+ "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
+ "xsi:schemaLocation": "http://www.ibm.com/xmlns/prod/CICS/smw2int http://my.url.host:12345/CICSSystemManagement/schema/CICSSystemManagement.xsd",
+ version: "3.0",
+ connect_version: "0620",
+ resultsummary: {
+ api_response1: "1024",
+ api_response2: "0",
+ api_response1_alt: "OK",
+ api_response2_alt: "",
+ recordcount: "1",
+ displayed_recordcount: "1",
+ },
+ records: {
+ cicsmanagedregion: {
+ _keydata: "C9E8C3E6C5D7E6F1",
+ actvtime: "",
+ ainsfail: "CONTINUE",
+ applid: "REGION1",
+ autoinst: "NEVER",
+ bastrace: "00000000",
+ botrsupd: "1",
+ chetrace: "00000000",
+ cicsname: "REGION1",
+ cicssamp: "0",
+ cicsstate: "ACTIVE",
+ cmasname: "MYCMAS",
+ comtrace: "00000000",
+ connsamp: "0",
+ cpsmver: "0620",
+ dattrace: "00000000",
+ daylghtsv: "NO",
+ dbxsamp: "0",
+ desc: "my region",
+ filesamp: "0",
+ glblsamp: "0",
+ host: "",
+ jrnlsamp: "0",
+ knltrace: "00000000",
+ mastrace: "00000000",
+ mastype: "LOCAL",
+ monstatus: "NO",
+ msgtrace: "00000000",
+ mxtaction: "",
+ mxtsev: "HS",
+ networkid: "",
+ nrmaction: "",
+ nrmsev: "N_A",
+ port: "",
+ pricmas: "",
+ progsamp: "0",
+ quetrace: "00000000",
+ readrs: "200",
+ retention: "0",
+ rtastatus: "SAM",
+ rtatrace: "00000000",
+ samaction: "",
+ samsev: "VHS",
+ sdmaction: "",
+ sdmsev: "VHS",
+ secbypass: "NO",
+ seccmdchk: "NO",
+ secreschk: "NO",
+ sosaction: "",
+ sossev: "HS",
+ srvtrace: "00000000",
+ stlaction: "",
+ stlsev: "VHS",
+ tdmaction: "",
+ tdmsev: "HW",
+ tdqsamp: "0",
+ termsamp: "0",
+ tmezone: "Z",
+ tmezoneo: "0",
+ toprsupd: "5",
+ toptrace: "00000000",
+ transamp: "0",
+ tratrace: "00000000",
+ updaters: "15",
+ wlmopten: "DISABLED",
+ wlmqmode: "ALL",
+ wlmstatus: "NO",
+ wlmthrsh: "60",
+ wlmtrace: "00000000",
+ },
+ },
+ },
+};
+
+export const okCache = {
+ response: {
+ xmlns: "http://www.ibm.com/xmlns/prod/CICS/smw2int",
+ "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
+ "xsi:schemaLocation": "http://www.ibm.com/xmlns/prod/CICS/smw2int http://my.url.host:12345/CICSSystemManagement/schema/CICSSystemManagement.xsd",
+ version: "3.0",
+ connect_version: "0620",
+ resultsummary: {
+ api_response1: "1024",
+ api_response2: "0",
+ api_response1_alt: "OK",
+ api_response2_alt: "",
+ recordcount: "2",
+ cachetoken: "E046A6E795FB9E13",
+ },
+ },
+};
+
+export const okContent2Records = {
+ response: {
+ xmlns: "http://www.ibm.com/xmlns/prod/CICS/smw2int",
+ "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
+ "xsi:schemaLocation": "http://www.ibm.com/xmlns/prod/CICS/smw2int http://my.url.host:12345/CICSSystemManagement/schema/CICSSystemManagement.xsd",
+ version: "3.0",
+ connect_version: "0620",
+ resultsummary: {
+ api_response1: "1024",
+ api_response2: "0",
+ api_response1_alt: "OK",
+ api_response2_alt: "",
+ recordcount: "2",
+ displayed_recordcount: "2",
+ },
+ records: {
+ cicscicsplex: [
+ {
+ _keydata: "C3C9C3E2C5E7F6F2C9E8C3E6C5D7C3D4",
+ accesstype: "LOCAL",
+ botrsupd: "1",
+ cmasname: "REGION1",
+ mpstatus: "YES",
+ plexname: "PLEX01",
+ readrs: "200",
+ rspoolid: "DFHRSTAT",
+ status: "ACTIVE",
+ sysid: "EPCM",
+ toprsupd: "5",
+ transitcmas: "",
+ transitcnt: "0",
+ updaters: "15",
+ },
+ {
+ _keydata: "C4E4D4D4E8F9F0F7C9E8C3E6C5D7C3D4",
+ accesstype: "LOCAL",
+ botrsupd: "1",
+ cmasname: "REGION1",
+ mpstatus: "YES",
+ plexname: "PLEX02",
+ readrs: "200",
+ rspoolid: "DFHRSTAT",
+ status: "ACTIVE",
+ sysid: "EPCM",
+ toprsupd: "5",
+ transitcmas: "",
+ transitcnt: "0",
+ updaters: "15",
+ },
+ ],
+ },
+ },
+};
+
+export const nodataContent = {
+ response: {
+ xmlns: "http://www.ibm.com/xmlns/prod/CICS/smw2int",
+ "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
+ "xsi:schemaLocation": "http://www.ibm.com/xmlns/prod/CICS/smw2int http://my.url.host:12345/CICSSystemManagement/schema/CICSSystemManagement.xsd",
+ version: "3.0",
+ connect_version: "0620",
+ resultsummary: {
+ api_source: "CICSPlex SM",
+ api_function: "GET",
+ api_response1: "1027",
+ api_response2: "0",
+ api_response1_alt: "NODATA",
+ api_response2_alt: "",
+ recordcount: "0",
+ },
+ },
+};
diff --git a/packages/sdk/__tests__/__mocks__/nodata.xml b/packages/sdk/__tests__/__mocks__/nodata.xml
new file mode 100644
index 00000000..937addd4
--- /dev/null
+++ b/packages/sdk/__tests__/__mocks__/nodata.xml
@@ -0,0 +1,8 @@
+
+
+
+
diff --git a/packages/sdk/__tests__/__mocks__/ok.1_record.xml b/packages/sdk/__tests__/__mocks__/ok.1_record.xml
new file mode 100644
index 00000000..415b1173
--- /dev/null
+++ b/packages/sdk/__tests__/__mocks__/ok.1_record.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
diff --git a/packages/sdk/__tests__/__mocks__/ok.2_records.xml b/packages/sdk/__tests__/__mocks__/ok.2_records.xml
new file mode 100644
index 00000000..9bc4982a
--- /dev/null
+++ b/packages/sdk/__tests__/__mocks__/ok.2_records.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
diff --git a/packages/sdk/__tests__/__mocks__/ok.cache.xml b/packages/sdk/__tests__/__mocks__/ok.cache.xml
new file mode 100644
index 00000000..928c53ec
--- /dev/null
+++ b/packages/sdk/__tests__/__mocks__/ok.cache.xml
@@ -0,0 +1,8 @@
+
+
+
+
diff --git a/packages/sdk/__tests__/__unit__/get/Get.resource.unit.test.ts b/packages/sdk/__tests__/__unit__/get/Get.resource.unit.test.ts
index b4b1b4fa..d28db287 100644
--- a/packages/sdk/__tests__/__unit__/get/Get.resource.unit.test.ts
+++ b/packages/sdk/__tests__/__unit__/get/Get.resource.unit.test.ts
@@ -17,14 +17,14 @@ import {
ICMCIApiResponse,
IResourceParms
} from "../../../src";
+import { ok2RecordsXmlResponse, okContent2Records } from "../../__mocks__/CmciGetResponse";
describe("CMCI - Get resource", () => {
- const resource = "resource";
- const region = "region";
- const cicsPlex = "plex";
+ const resource = "CICSCICSPlex";
+ const region = "REGION1";
+ const cicsPlex = "PLEX01";
const criteria = "program=D*";
- const content = "This\nis\r\na\ntest" as unknown as ICMCIApiResponse;
const dummySession = new Session({
user: "fake",
@@ -33,8 +33,8 @@ describe("CMCI - Get resource", () => {
port: 1490
});
- let error: any;
- let response: any;
+ let error: Error | undefined;
+ let response: ICMCIApiResponse | undefined;
let endPoint: string;
let resourceParms: IResourceParms;
@@ -53,6 +53,7 @@ describe("CMCI - Get resource", () => {
it("should throw error if no parms are defined", async () => {
try {
+ // @ts-ignore - Not allowed to pass undefined here
response = await getResource(dummySession, undefined);
} catch (err) {
error = err;
@@ -60,13 +61,14 @@ describe("CMCI - Get resource", () => {
expect(response).toBeUndefined();
expect(error).toBeDefined();
- expect(error.message).toMatch(/(Cannot read).*undefined/);
+ expect(error?.message).toMatch(/(Cannot read).*undefined/);
});
it("should throw error if resource name is not defined", async () => {
try {
response = await getResource(dummySession, {
regionName: "fake",
+ // @ts-ignore - Not allowed to pass undefined here
name: undefined,
});
} catch (err) {
@@ -75,7 +77,7 @@ describe("CMCI - Get resource", () => {
expect(response).toBeUndefined();
expect(error).toBeDefined();
- expect(error.message).toContain("CICS resource name is required");
+ expect(error?.message).toContain("CICS resource name is required");
});
it("should throw error if resource name is missing", async () => {
@@ -90,13 +92,13 @@ describe("CMCI - Get resource", () => {
expect(response).toBeUndefined();
expect(error).toBeDefined();
- expect(error.message).toContain("Required parameter 'CICS Resource name' must not be blank");
+ expect(error?.message).toContain("Required parameter 'CICS Resource name' must not be blank");
});
});
describe("success scenarios", () => {
- const deleteSpy = jest.spyOn(CicsCmciRestClient, "getExpectParsedXml").mockResolvedValue(content);
+ const getExpectStringMock = jest.spyOn(CicsCmciRestClient, "getExpectString");
beforeEach(() => {
response = undefined;
@@ -107,8 +109,8 @@ describe("CMCI - Get resource", () => {
criteria: undefined,
cicsPlex: undefined
};
- deleteSpy.mockClear();
- deleteSpy.mockResolvedValue(content);
+ getExpectStringMock.mockClear();
+ getExpectStringMock.mockResolvedValue(ok2RecordsXmlResponse);
});
it("should be able to get a resource without CICS Region name being defined", async () => {
@@ -120,10 +122,10 @@ describe("CMCI - Get resource", () => {
}
endPoint = "/" + CicsCmciConstants.CICS_SYSTEM_MANAGEMENT + "/" +
- resource + "/";
+ resource + "/";
- expect(response).toContain(content);
- expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
+ expect(response).toEqual(okContent2Records);
+ expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});
it("should be able to get a resource without CICS Region name being specified", async () => {
@@ -135,54 +137,54 @@ describe("CMCI - Get resource", () => {
}
endPoint = "/" + CicsCmciConstants.CICS_SYSTEM_MANAGEMENT + "/" +
- resource + "/";
+ resource + "/";
- expect(response).toContain(content);
- expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
+ expect(response).toEqual(okContent2Records);
+ expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});
it("should be able to get a resource without cicsPlex specified", async () => {
endPoint = "/" + CicsCmciConstants.CICS_SYSTEM_MANAGEMENT + "/" + resource +
- "/" + region;
+ "/" + region;
response = await getResource(dummySession, resourceParms);
- expect(response).toContain(content);
- expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
+ expect(response).toEqual(okContent2Records);
+ expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});
it("should be able to get a resource without criteria specified", async () => {
resourceParms.criteria = undefined;
endPoint = "/" + CicsCmciConstants.CICS_SYSTEM_MANAGEMENT + "/" + resource +
- "/" + region;
+ "/" + region;
response = await getResource(dummySession, resourceParms);
- expect(response).toContain(content);
- expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
+ expect(response).toEqual(okContent2Records);
+ expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});
it("should be able to get a resource with cicsPlex specified and criteria not specified", async () => {
resourceParms.cicsPlex = cicsPlex;
resourceParms.criteria = undefined;
- endPoint = "/" + CicsCmciConstants.CICS_SYSTEM_MANAGEMENT + "/" + resource +
- "/" + cicsPlex + "/" + region;
+ endPoint = "/" + CicsCmciConstants.CICS_SYSTEM_MANAGEMENT + "/" + resource +
+ "/" + cicsPlex + "/" + region;
response = await getResource(dummySession, resourceParms);
- expect(response).toContain(content);
- expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
+ expect(response).toEqual(okContent2Records);
+ expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});
it("should be able to get a resource with criteria specified", async () => {
resourceParms.cicsPlex = undefined;
resourceParms.criteria = criteria;
- endPoint = "/" + CicsCmciConstants.CICS_SYSTEM_MANAGEMENT + "/" + resource +
- "/" + region + "?CRITERIA=(" + encodeURIComponent(resourceParms.criteria) + ")";
+ endPoint = "/" + CicsCmciConstants.CICS_SYSTEM_MANAGEMENT + "/" + resource +
+ "/" + region + "?CRITERIA=(" + encodeURIComponent(resourceParms.criteria) + ")";
response = await getResource(dummySession, resourceParms);
- expect(response).toContain(content);
- expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
+ expect(response).toEqual(okContent2Records);
+ expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});
it("should be able to get a resource with SUMMONLY specified", async () => {
@@ -194,8 +196,8 @@ describe("CMCI - Get resource", () => {
endPoint = `/${CicsCmciConstants.CICS_SYSTEM_MANAGEMENT}/${resource}/plex1/reg1?SUMMONLY`;
response = await getResource(dummySession, resourceParms);
- expect(response).toContain(content);
- expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
+ expect(response).toEqual(okContent2Records);
+ expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});
it("should be able to get a resource with NODISCARD specified", async () => {
@@ -207,8 +209,8 @@ describe("CMCI - Get resource", () => {
endPoint = `/${CicsCmciConstants.CICS_SYSTEM_MANAGEMENT}/${resource}/plex1/reg1?NODISCARD`;
response = await getResource(dummySession, resourceParms);
- expect(response).toContain(content);
- expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
+ expect(response).toEqual(okContent2Records);
+ expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});
it("should be able to get a resource with OVERRIDEWARNINGCOUNT specified", async () => {
@@ -220,8 +222,8 @@ describe("CMCI - Get resource", () => {
endPoint = `/${CicsCmciConstants.CICS_SYSTEM_MANAGEMENT}/${resource}/plex1/reg1?OVERRIDEWARNINGCOUNT`;
response = await getResource(dummySession, resourceParms);
- expect(response).toContain(content);
- expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
+ expect(response).toEqual(okContent2Records);
+ expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});
it("should be able to get a resource with all query params specified", async () => {
@@ -235,8 +237,8 @@ describe("CMCI - Get resource", () => {
endPoint = `/${CicsCmciConstants.CICS_SYSTEM_MANAGEMENT}/${resource}/plex1/reg1?SUMMONLY&NODISCARD&OVERRIDEWARNINGCOUNT`;
response = await getResource(dummySession, resourceParms);
- expect(response).toContain(content);
- expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
+ expect(response).toEqual(okContent2Records);
+ expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});
it("should be able to get a resource with no context and all query params specified", async () => {
@@ -250,8 +252,8 @@ describe("CMCI - Get resource", () => {
endPoint = `/${CicsCmciConstants.CICS_SYSTEM_MANAGEMENT}/${resource}/?SUMMONLY&NODISCARD&OVERRIDEWARNINGCOUNT`;
response = await getResource(dummySession, resourceParms);
- expect(response).toContain(content);
- expect(deleteSpy).toHaveBeenCalledWith(dummySession, endPoint, []);
+ expect(response).toEqual(okContent2Records);
+ expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});
});
});