-
Notifications
You must be signed in to change notification settings - Fork 85
/
TsoValidator.ts
132 lines (117 loc) · 4.67 KB
/
TsoValidator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* 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 { AbstractSession, ImperativeExpect, TextUtils } from "@zowe/imperative";
import { noSessionTso, noTsoIssueInput, noTsoStartInput, noTsoStopInput, noZosmfResponse } from "./TsoConstants";
import { IStartTsoParms } from "./doc/input/IStartTsoParms";
import { IStopTsoParms } from "./doc/input/IStopTsoParms";
import { IIssueTsoParms } from "./doc/input/IIssueTsoParms";
import { IZosmfPingResponse } from "./doc/zosmf/IZosmfPingResponse";
import { IZosmfTsoResponse } from "./doc/zosmf/IZosmfTsoResponse";
/**
* Class validates parameters for TSO commands
* @export
* @class TsoValidator
*/
export class TsoValidator {
/**
* Validate session
* @static
* @param {AbstractSession} session - z/OSMF connection info
* @memberof TsoValidator
*/
public static validateSession(session: AbstractSession) {
ImperativeExpect.toNotBeNullOrUndefined(session,
TextUtils.formatMessage(noSessionTso.message));
}
/**
* Validate TSO start command parameters
* @param {IStartTsoParms} parms - object with required parameters, @see {IStartTsoParms}
* @memberof TsoValidator
*/
public static validateStartParams(parms: IStartTsoParms) {
ImperativeExpect.toNotBeNullOrUndefined(parms, noTsoStartInput.message);
}
/**
* Validate TSO issue command parameters
* @param {IStartTsoParms} parms - object with required parameters, @see {IIssueTsoParms}
* @memberof TsoValidator
*/
public static validateIssueParams(parms: IIssueTsoParms) {
ImperativeExpect.toNotBeNullOrUndefined(parms, noTsoIssueInput.message);
}
/**
* Validate TSO stop command parameters
* @param {IStopTsoParms} parms - object with required parameters, @see {IStopTsoParms}
* @memberof TsoValidator
*/
public static validateStopParams(parms: IStopTsoParms) {
ImperativeExpect.toNotBeNullOrUndefined(parms, noTsoStopInput.message);
}
/**
* Validate z/OSMF response, needed for service and filtering servlet key
* @param {IZosmfTsoResponse} parms - object response from z/OSMF, @see {IZosmfTsoResponse}
* @memberof TsoValidator
*/
public static validateStartZosmfResponse(parms: IZosmfTsoResponse) {
ImperativeExpect.toNotBeNullOrUndefined(parms, noZosmfResponse.message);
}
/**
* Validate supplied parameters
* @static
* @param {AbstractSession} session - representing connection to this api
* @param {string} text - string to check if not empty or undefined
* @param {string} errorMsg - message to show in text case validation fails
* @memberof TsoValidator
*/
public static validatePingParms(session: AbstractSession, text: string, errorMsg: string) {
this.validateSession(session);
this.validateNotEmptyString(text, errorMsg);
}
/**
* Validate supplied parameters
* @static
* @param {string} text - string to check if not null or undefined
* @param {string} errorMsg - message to show in text case validation fails
* @memberof TsoValidator
*/
public static validateString(text: string, errorMsg: string) {
ImperativeExpect.toNotBeNullOrUndefined(text, errorMsg);
}
/**
* Validate supplied parameters
* @static
* @param {string} text - string to check if empty
* @param {string} errorMsg - message to show in text case validation fails
* @memberof TsoValidator
*/
public static validateNotEmptyString(text: string, errorMsg: string) {
ImperativeExpect.toNotBeEqual("", text, errorMsg);
TsoValidator.validateString(text, errorMsg);
}
/**
* Validate z/OSMF response
* @param {IZosmfPingResponse} parms - object response from z/OSMF, @see {IZosmfPingResponse}
* @memberof TsoValidator
*/
public static validatePingZosmfResponse(parms: IZosmfPingResponse) {
ImperativeExpect.toNotBeNullOrUndefined(parms, noZosmfResponse.message);
}
/**
* Validate z/OSMF response for errors
* @param {IZosmfTsoResponse} zosmfResponse - object response from z/OSMF, @see {IZosmfTsoResponse}
* @memberof TsoValidator
*/
public static validateErrorMessageFromZosmf(zosmfResponse: IZosmfTsoResponse) {
if (zosmfResponse.msgData) {
ImperativeExpect.toBeEqual(zosmfResponse.msgData, "undefined", zosmfResponse.msgData[0].messageText);
}
}
}