itoolkit 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -8
- package/lib/CommandCall.js +2 -16
- package/lib/Connection.js +2 -17
- package/lib/Deprecated.js +5 -26
- package/lib/ProgramCall.js +4 -18
- package/lib/itoolkit.js +2 -16
- package/lib/transports/httpTransport.js +4 -18
- package/lib/transports/idbTransport.js +24 -26
- package/lib/transports/odbcTransport.js +16 -16
- package/lib/transports/sshTransport.js +5 -20
- package/package.json +23 -16
- package/.eslintrc.js +0 -13
- package/.gitattributes +0 -2
- package/.readthedocs.yml +0 -16
- package/CHANGELOG.md +0 -195
- package/contributors.txt +0 -2
- package/test/README.md +0 -46
- package/test/functional/CommandCallFunctional.js +0 -79
- package/test/functional/ProgramCallFunctional.js +0 -166
- package/test/functional/checkObjectExists.js +0 -182
- package/test/functional/config.js +0 -35
- package/test/functional/deprecated/commandsFunctional.js +0 -99
- package/test/functional/deprecated/iDataQueueFunctional.js +0 -104
- package/test/functional/deprecated/iNetworkFunctional.js +0 -160
- package/test/functional/deprecated/iObjFunctional.js +0 -350
- package/test/functional/deprecated/iPgmFunctional.js +0 -140
- package/test/functional/deprecated/iProdFunctional.js +0 -161
- package/test/functional/deprecated/iSqlFunctional.js +0 -455
- package/test/functional/deprecated/iUserSpaceFunctional.js +0 -127
- package/test/functional/deprecated/iWorkFunctional.js +0 -236
- package/test/functional/iDataQueueFunctional.js +0 -84
- package/test/functional/iNetworkFunctional.js +0 -133
- package/test/functional/iObjFunctional.js +0 -327
- package/test/functional/iProdFunctional.js +0 -135
- package/test/functional/iSqlFunctional.js +0 -449
- package/test/functional/iUserSpaceFunctional.js +0 -123
- package/test/functional/iWorkFunctional.js +0 -219
- package/test/unit/CommandCallUnit.js +0 -88
- package/test/unit/ConnectionUnit.js +0 -195
- package/test/unit/ProgamCallUnit.js +0 -279
- package/test/unit/deprecated/commandsUnit.js +0 -88
- package/test/unit/deprecated/iConnUnit.js +0 -162
- package/test/unit/deprecated/iPgmUnit.js +0 -207
- package/test/unit/deprecated/iSqlUnit.js +0 -442
- package/test/unit/deprecated/xmlToJsonUnit.js +0 -203
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
// Copyright (c) International Business Machines Corp. 2019
|
|
2
|
-
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
4
|
-
// associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
5
|
-
// including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
6
|
-
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
7
|
-
// furnished to do so, subject to the following conditions:
|
|
8
|
-
|
|
9
|
-
// The above copyright notice and this permission notice shall be included in all copies or
|
|
10
|
-
// substantial portions of the Software.
|
|
11
|
-
|
|
12
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
13
|
-
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
14
|
-
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
15
|
-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
16
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
17
|
-
|
|
18
|
-
/* eslint-env mocha */
|
|
19
|
-
/* eslint-disable new-cap */
|
|
20
|
-
|
|
21
|
-
const { expect } = require('chai');
|
|
22
|
-
const { Connection, iWork } = require('../../lib/itoolkit');
|
|
23
|
-
const { config, printConfig } = require('./config');
|
|
24
|
-
const { checkObjectExists } = require('./checkObjectExists');
|
|
25
|
-
|
|
26
|
-
describe('iWork Functional Tests', () => {
|
|
27
|
-
before(() => {
|
|
28
|
-
printConfig();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('getSysValue', () => {
|
|
32
|
-
it('returns the value of system variable', (done) => {
|
|
33
|
-
const connection = new Connection(config);
|
|
34
|
-
|
|
35
|
-
const work = new iWork(connection);
|
|
36
|
-
|
|
37
|
-
work.getSysValue('QCENTURY', (error, output) => {
|
|
38
|
-
expect(error).to.equal(null);
|
|
39
|
-
expect(output).to.be.a('string').and.to.equal('1');
|
|
40
|
-
done();
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('returns an error when the specified system value is invalid', (done) => {
|
|
45
|
-
const connection = new Connection(config);
|
|
46
|
-
|
|
47
|
-
const work = new iWork(connection);
|
|
48
|
-
|
|
49
|
-
work.getSysValue('invalid', (error) => {
|
|
50
|
-
expect(error).to.be.a('error');
|
|
51
|
-
done();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('getSysStatus', () => {
|
|
57
|
-
it('returns basic system status information about the signed-on users and batch jobs', (done) => {
|
|
58
|
-
const connection = new Connection(config);
|
|
59
|
-
const work = new iWork(connection);
|
|
60
|
-
|
|
61
|
-
work.getSysStatus((error, output) => {
|
|
62
|
-
expect(error).to.equal(null);
|
|
63
|
-
expect(output).to.be.an('Object');
|
|
64
|
-
expect(output).to.have.a.property('Current_date_and_time');
|
|
65
|
-
expect(output).to.have.a.property('System_name');
|
|
66
|
-
expect(output).to.have.a.property('Users_currently_signed_on');
|
|
67
|
-
expect(output).to.have.a.property('Users_temporarily_signed_off_(disconnected)');
|
|
68
|
-
expect(output).to.have.a.property('Users_suspended_by_system_request');
|
|
69
|
-
expect(output).to.have.a.property('Users_suspended_by_group_jobs');
|
|
70
|
-
expect(output).to.have.a.property('Users_signed_off_with_printer_output_waiting_to_print');
|
|
71
|
-
expect(output).to.have.a.property('Batch_jobs_waiting_for_messages');
|
|
72
|
-
expect(output).to.have.a.property('Batch_jobs_running');
|
|
73
|
-
expect(output).to.have.a.property('Batch_jobs_held_while_running');
|
|
74
|
-
expect(output).to.have.a.property('Batch_jobs_ending');
|
|
75
|
-
expect(output).to.have.a.property('Batch_jobs_waiting_to_run_or_already_scheduled');
|
|
76
|
-
expect(output).to.have.a.property('Batch_jobs_held_on_a_job_queue');
|
|
77
|
-
expect(output).to.have.a.property('Batch_jobs_on_a_held_job_queue');
|
|
78
|
-
expect(output).to.have.a.property('Batch_jobs_on_an_unassigned_job_queue');
|
|
79
|
-
expect(output).to.have.a.property('Batch_jobs_ended_with_printer_output_waiting_to_print');
|
|
80
|
-
done();
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('getSysStatusExt', () => {
|
|
86
|
-
it('returns more detailed system status info', (done) => {
|
|
87
|
-
const connection = new Connection(config);
|
|
88
|
-
|
|
89
|
-
const work = new iWork(connection);
|
|
90
|
-
|
|
91
|
-
work.getSysStatusExt((error, output) => {
|
|
92
|
-
expect(error).to.equal(null);
|
|
93
|
-
expect(output).to.be.an('Object');
|
|
94
|
-
expect(output).to.have.a.property('Current_date_and_time');
|
|
95
|
-
expect(output).to.have.a.property('System_name');
|
|
96
|
-
expect(output).to.have.a.property('Elapsed_time');
|
|
97
|
-
expect(output).to.have.a.property('Restricted_state_flag');
|
|
98
|
-
expect(output).to.have.a.property('%_processing_unit_used');
|
|
99
|
-
expect(output).to.have.a.property('Jobs_in_system');
|
|
100
|
-
expect(output).to.have.a.property('%_permanent_addresses');
|
|
101
|
-
expect(output).to.have.a.property('%_temporary_addresses');
|
|
102
|
-
expect(output).to.have.a.property('System_ASP');
|
|
103
|
-
expect(output).to.have.a.property('%_system_ASP_used');
|
|
104
|
-
expect(output).to.have.a.property('Total_auxiliary_storage');
|
|
105
|
-
expect(output).to.have.a.property('Current_unprotected_storage_used');
|
|
106
|
-
expect(output).to.have.a.property('Maximum_unprotected_storage_used');
|
|
107
|
-
expect(output).to.have.a.property('%_DB_capability');
|
|
108
|
-
expect(output).to.have.a.property('Main_storage_size');
|
|
109
|
-
expect(output).to.have.a.property('Number_of_partitions');
|
|
110
|
-
expect(output).to.have.a.property('Partition_identifier');
|
|
111
|
-
expect(output).to.have.a.property('Current_processing_capacity');
|
|
112
|
-
expect(output).to.have.a.property('Processor_sharing_attribute');
|
|
113
|
-
expect(output).to.have.a.property('Number_of_processors');
|
|
114
|
-
expect(output).to.have.a.property('Active_jobs_in_system');
|
|
115
|
-
expect(output).to.have.a.property('Active_threads_in_system');
|
|
116
|
-
expect(output).to.have.a.property('Maximum_jobs_in_system');
|
|
117
|
-
expect(output).to.have.a.property('%_temporary_256MB_segments_used');
|
|
118
|
-
expect(output).to.have.a.property('%_temporary_4GB_segments_used');
|
|
119
|
-
expect(output).to.have.a.property('%_permanent_256MB_segments_used');
|
|
120
|
-
expect(output).to.have.a.property('%_permanent_4GB_segments_used');
|
|
121
|
-
expect(output).to.have.a.property('%_current_interactive_performance');
|
|
122
|
-
expect(output).to.have.a.property('%_uncapped_CPU_capacity_used');
|
|
123
|
-
expect(output).to.have.a.property('%_shared_processor_pool_used');
|
|
124
|
-
expect(output).to.have.a.property('Main_storage_size_(long)');
|
|
125
|
-
done();
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe('getJobStatus', () => {
|
|
131
|
-
it('returns status of specified job', (done) => {
|
|
132
|
-
const connection = new Connection(config);
|
|
133
|
-
|
|
134
|
-
const work = new iWork(connection);
|
|
135
|
-
|
|
136
|
-
work.getJobStatus('000000', (error, output) => {
|
|
137
|
-
expect(error).to.equal(null);
|
|
138
|
-
expect(output).to.be.an('Object');
|
|
139
|
-
expect(output).to.have.a.property('Job_status');
|
|
140
|
-
expect(output).to.have.a.property('Fully_qualified_job_name');
|
|
141
|
-
done();
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
describe('getJobInfo', () => {
|
|
147
|
-
it('returns info on specfed job', (done) => {
|
|
148
|
-
const connection = new Connection(config);
|
|
149
|
-
|
|
150
|
-
const work = new iWork(connection);
|
|
151
|
-
|
|
152
|
-
work.getJobInfo('SCPF', 'QSYS', '000000', (error, output) => {
|
|
153
|
-
expect(error).to.equal(null);
|
|
154
|
-
expect(output).to.be.an('Object');
|
|
155
|
-
expect(output).to.have.a.property('Job_name');
|
|
156
|
-
expect(output).to.have.a.property('User_name');
|
|
157
|
-
expect(output).to.have.a.property('Job_number');
|
|
158
|
-
expect(output).to.have.a.property('Job_status');
|
|
159
|
-
expect(output).to.have.a.property('Job_type');
|
|
160
|
-
expect(output).to.have.a.property('Job_subtype');
|
|
161
|
-
expect(output).to.have.a.property('Subsystem_description_name');
|
|
162
|
-
expect(output).to.have.a.property('Run_priority_(job)');
|
|
163
|
-
expect(output).to.have.a.property('System_pool_identifier');
|
|
164
|
-
expect(output).to.have.a.property('Processing_unit_time_used,_if_less_than_2,147,483,647_milliseconds');
|
|
165
|
-
expect(output).to.have.a.property('Number_of_auxiliary_I/O_requests,_if_less_than_2,147,483,647');
|
|
166
|
-
expect(output).to.have.a.property('Number_of_interactive_transactions');
|
|
167
|
-
expect(output).to.have.a.property('Response_time_total');
|
|
168
|
-
expect(output).to.have.a.property('Function_type');
|
|
169
|
-
expect(output).to.have.a.property('Function_name');
|
|
170
|
-
expect(output).to.have.a.property('Active_job_status');
|
|
171
|
-
expect(output).to.have.a.property('Number_of_database_lock_waits');
|
|
172
|
-
expect(output).to.have.a.property('Number_of_internal_machine_lock_waits');
|
|
173
|
-
expect(output).to.have.a.property('Number_of_nondatabase_lock_waits');
|
|
174
|
-
expect(output).to.have.a.property('Time_spent_on_database_lock_waits');
|
|
175
|
-
expect(output).to.have.a.property('Time_spent_on_internal_machine_lock_waits');
|
|
176
|
-
expect(output).to.have.a.property('Time_spent_on_nondatabase_lock_waits');
|
|
177
|
-
expect(output).to.have.a.property('Current_system_pool_identifier');
|
|
178
|
-
expect(output).to.have.a.property('Thread_count');
|
|
179
|
-
expect(output).to.have.a.property('Processing_unit_time_used_-_total_for_the_job');
|
|
180
|
-
expect(output).to.have.a.property('Number_of_auxiliary_I/O_requests');
|
|
181
|
-
expect(output).to.have.a.property('Processing_unit_time_used_for_database_-_total_for_the_job');
|
|
182
|
-
expect(output).to.have.a.property('Page_faults');
|
|
183
|
-
expect(output).to.have.a.property('Active_job_status_for_jobs_ending');
|
|
184
|
-
expect(output).to.have.a.property('Memory_pool_name');
|
|
185
|
-
expect(output).to.have.a.property('Message_reply');
|
|
186
|
-
expect(output).to.have.a.property('Message_key,_when_active_job_waiting_for_a_message');
|
|
187
|
-
expect(output).to.have.a.property('Message_queue_name,_when_active_job_waiting_for_a_message');
|
|
188
|
-
expect(output).to.have.a.property('Message_queue_library_name,_when_active_job_waiting_for_a_message');
|
|
189
|
-
expect(output).to.have.a.property('Message_queue_library_ASP_device_name,_when_active_job_waiting_for_a_message');
|
|
190
|
-
done();
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
describe('getDataArea', () => {
|
|
196
|
-
before('check if data area exists for tests', (done) => {
|
|
197
|
-
checkObjectExists(config, 'TESTDA', '*DTAARA', (error) => {
|
|
198
|
-
if (error) { throw error; }
|
|
199
|
-
done();
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
it('returns contents of a data area', (done) => {
|
|
203
|
-
const connection = new Connection(config);
|
|
204
|
-
|
|
205
|
-
const work = new iWork(connection);
|
|
206
|
-
|
|
207
|
-
work.getDataArea('NODETKTEST', 'TESTDA', 20, (error, output) => {
|
|
208
|
-
expect(error).to.equal(null);
|
|
209
|
-
expect(output).to.be.an('Object');
|
|
210
|
-
expect(output).to.have.a.property('Type_of_value_returned');
|
|
211
|
-
expect(output).to.have.a.property('Library_name');
|
|
212
|
-
expect(output).to.have.a.property('Length_of_value_returned');
|
|
213
|
-
expect(output).to.have.a.property('Number_of_decimal_positions');
|
|
214
|
-
expect(output).to.have.a.property('Value');
|
|
215
|
-
done();
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
});
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// Copyright (c) International Business Machines Corp. 2019
|
|
2
|
-
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
4
|
-
// associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
5
|
-
// including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
6
|
-
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
7
|
-
// furnished to do so, subject to the following conditions:
|
|
8
|
-
|
|
9
|
-
// The above copyright notice and this permission notice shall be included in all copies or
|
|
10
|
-
// substantial portions of the Software.
|
|
11
|
-
|
|
12
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
13
|
-
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
14
|
-
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
15
|
-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
16
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
17
|
-
|
|
18
|
-
/* eslint-env mocha */
|
|
19
|
-
const { expect } = require('chai');
|
|
20
|
-
const { CommandCall } = require('../../lib/itoolkit');
|
|
21
|
-
|
|
22
|
-
describe('Command Call Unit Tests', () => {
|
|
23
|
-
describe('SH command tests', () => {
|
|
24
|
-
it('accepts command input and returns <sh> XML output', () => {
|
|
25
|
-
const command = new CommandCall({ command: 'ls -lah', type: 'sh' });
|
|
26
|
-
|
|
27
|
-
const expectedXML = '<sh error=\'fast\'>ls -lah</sh>';
|
|
28
|
-
|
|
29
|
-
expect(command.toXML()).to.be.a('string').and.to.equal(expectedXML);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('accepts command input and options returns <sh> with optional attributes', () => {
|
|
33
|
-
const options = {
|
|
34
|
-
error: 'on', before: '65535', after: '37', rows: 'on',
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const command = new CommandCall({ command: 'ls -lah', type: 'sh', options });
|
|
38
|
-
|
|
39
|
-
const expectedXML = '<sh rows=\'on\' before=\'65535\' after=\'37\' error=\'on\'>ls -lah</sh>';
|
|
40
|
-
|
|
41
|
-
expect(command.toXML()).to.be.a('string').and.to.equal(expectedXML);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe('CL command tests', () => {
|
|
46
|
-
it('accepts command input and returns <cmd> XML output', () => {
|
|
47
|
-
const command = new CommandCall({ command: 'RTVJOBA USRLIBL(?) SYSLIBL(?)', type: 'cl' });
|
|
48
|
-
|
|
49
|
-
const expectedXML = '<cmd exec=\'rexx\' error=\'fast\'>RTVJOBA USRLIBL(?) SYSLIBL(?)</cmd>';
|
|
50
|
-
|
|
51
|
-
expect(command.toXML()).to.be.a('string').and.to.equal(expectedXML);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('accepts command input and options returns <cmd> with optional attributes', () => {
|
|
55
|
-
const options = {
|
|
56
|
-
exec: 'cmd', error: 'on', before: '65535', after: '37', hex: 'on',
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const command = new CommandCall({ command: 'RTVJOBA USRLIBL(?) SYSLIBL(?)', type: 'cl', options });
|
|
60
|
-
|
|
61
|
-
const expectedXML = '<cmd exec=\'cmd\' hex=\'on\' before=\'65535\' after=\'37\' error=\'on\''
|
|
62
|
-
+ '>RTVJOBA USRLIBL(?) SYSLIBL(?)</cmd>';
|
|
63
|
-
|
|
64
|
-
expect(command.toXML()).to.be.a('string').and.to.equal(expectedXML);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe('QSH command tests', () => {
|
|
69
|
-
it('accepts command input and returns <qsh> XML output', () => {
|
|
70
|
-
const command = new CommandCall({ command: 'ls -lah', type: 'qsh' });
|
|
71
|
-
|
|
72
|
-
const expectedXML = '<qsh error=\'fast\'>ls -lah</qsh>';
|
|
73
|
-
|
|
74
|
-
expect(command.toXML()).to.be.a('string').and.to.equal(expectedXML);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('accepts command input and options returns <qsh> with optional attributes', () => {
|
|
78
|
-
const options = {
|
|
79
|
-
error: 'on', before: '65535', after: '37', rows: 'on',
|
|
80
|
-
};
|
|
81
|
-
const command = new CommandCall({ command: 'ls -lah', type: 'qsh', options });
|
|
82
|
-
|
|
83
|
-
const expectedXML = '<qsh rows=\'on\' before=\'65535\' after=\'37\' error=\'on\'>ls -lah</qsh>';
|
|
84
|
-
|
|
85
|
-
expect(command.toXML()).to.be.a('string').and.to.equal(expectedXML);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
});
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
// Copyright (c) International Business Machines Corp. 2019
|
|
2
|
-
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
4
|
-
// associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
5
|
-
// including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
6
|
-
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
7
|
-
// furnished to do so, subject to the following conditions:
|
|
8
|
-
|
|
9
|
-
// The above copyright notice and this permission notice shall be included in all copies or
|
|
10
|
-
// substantial portions of the Software.
|
|
11
|
-
|
|
12
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
13
|
-
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
14
|
-
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
15
|
-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
16
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
17
|
-
|
|
18
|
-
/* eslint-env mocha */
|
|
19
|
-
/* eslint-disable new-cap */
|
|
20
|
-
|
|
21
|
-
const { expect } = require('chai');
|
|
22
|
-
const sinon = require('sinon');
|
|
23
|
-
const { Connection, CommandCall } = require('../../lib/itoolkit');
|
|
24
|
-
|
|
25
|
-
describe('Connection Class Unit Tests', () => {
|
|
26
|
-
describe('constructor', () => {
|
|
27
|
-
it('creates and returns an instance of Connection with idb transport', () => {
|
|
28
|
-
const options = {
|
|
29
|
-
transport: 'idb',
|
|
30
|
-
transportOptions: {
|
|
31
|
-
database: process.env.TKDB || '*LOCAL',
|
|
32
|
-
username: process.env.TKUSER || '',
|
|
33
|
-
password: process.env.TKPASS || '',
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
const connection = new Connection(options);
|
|
37
|
-
|
|
38
|
-
expect(connection).to.be.instanceOf(Connection);
|
|
39
|
-
expect(connection.transportOptions).to.be.an('Object');
|
|
40
|
-
expect(connection.transportOptions.database).to.equal(options.transportOptions.database);
|
|
41
|
-
expect(connection.transportOptions.username).to.equal(options.transportOptions.username);
|
|
42
|
-
expect(connection.transportOptions.password).to.equal(options.transportOptions.password);
|
|
43
|
-
expect(connection.transport).to.equal('idb');
|
|
44
|
-
expect(connection.verbose).to.equal(false);
|
|
45
|
-
expect(connection.commandList).to.be.an('Array');
|
|
46
|
-
expect(connection.commandList.length).to.equal(0);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('creates and returns an instance of Connection with rest transport', () => {
|
|
50
|
-
const options = {
|
|
51
|
-
transport: 'rest',
|
|
52
|
-
transportOptions: {
|
|
53
|
-
database: process.env.TKDB || '*LOCAL',
|
|
54
|
-
username: process.env.TKUSER || '',
|
|
55
|
-
password: process.env.TKPASS || '',
|
|
56
|
-
host: process.env.TKHOST || 'localhost',
|
|
57
|
-
port: process.env.TKPORT || 80,
|
|
58
|
-
path: process.env.TKPATH || '/cgi-bin/xmlcgi.pgm',
|
|
59
|
-
xslib: 'QXMLSERV',
|
|
60
|
-
ipc: '*NA',
|
|
61
|
-
ctl: '*here',
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const connection = new Connection(options);
|
|
66
|
-
|
|
67
|
-
expect(connection).to.be.instanceOf(Connection);
|
|
68
|
-
expect(connection.transportOptions).to.be.an('Object');
|
|
69
|
-
expect(connection.transportOptions.database).to.equal(options.transportOptions.database);
|
|
70
|
-
expect(connection.transportOptions.username).to.equal(options.transportOptions.username);
|
|
71
|
-
expect(connection.transportOptions.password).to.equal(options.transportOptions.password);
|
|
72
|
-
expect(connection.transport).to.equal('rest');
|
|
73
|
-
expect(connection.transportOptions.ctl).to.equal('*here');
|
|
74
|
-
expect(connection.transportOptions.ipc).to.equal('*NA');
|
|
75
|
-
expect(connection.transportOptions.xslib).to.equal('QXMLSERV');
|
|
76
|
-
expect(connection.commandList).to.be.an('Array');
|
|
77
|
-
expect(connection.commandList.length).to.equal(0);
|
|
78
|
-
expect(connection.verbose).to.equal(false);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe('add', () => {
|
|
83
|
-
it('appends to xml service request to the command list using Connection class', () => {
|
|
84
|
-
const options = {
|
|
85
|
-
transport: 'idb',
|
|
86
|
-
transportOptions: {
|
|
87
|
-
database: process.env.TKDB || '*LOCAL',
|
|
88
|
-
username: process.env.TKUSER || '',
|
|
89
|
-
password: process.env.TKPASS || '',
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
const connection = new Connection(options);
|
|
93
|
-
|
|
94
|
-
connection.add(new CommandCall({ command: 'ls -lah', type: 'sh' }));
|
|
95
|
-
expect(connection.commandList.length).to.equal(1);
|
|
96
|
-
expect(connection.commandList[0]).to.equal('<sh error=\'fast\'>ls -lah</sh>');
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
describe('debug', () => {
|
|
102
|
-
it('turns verbose mode on/off using Connection class', () => {
|
|
103
|
-
const options = {
|
|
104
|
-
transport: 'idb',
|
|
105
|
-
transportOptions: {
|
|
106
|
-
database: process.env.TKDB || '*LOCAL',
|
|
107
|
-
username: process.env.TKUSER || '',
|
|
108
|
-
password: process.env.TKPASS || '',
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
const connection = new Connection(options);
|
|
112
|
-
|
|
113
|
-
connection.debug(true);
|
|
114
|
-
expect(connection.debug()).to.equal(true);
|
|
115
|
-
connection.debug(false);
|
|
116
|
-
expect(connection.debug()).to.equal(false);
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
describe('getTransportOptions', () => {
|
|
122
|
-
it('returns conn (object) property from Connection instance', () => {
|
|
123
|
-
const options = {
|
|
124
|
-
transport: 'rest',
|
|
125
|
-
transportOptions: {
|
|
126
|
-
database: process.env.TKDB || '*LOCAL',
|
|
127
|
-
username: process.env.TKUSER || '',
|
|
128
|
-
password: process.env.TKPASS || '',
|
|
129
|
-
host: process.env.TKHOST || 'localhost',
|
|
130
|
-
port: process.env.TKPORT || 80,
|
|
131
|
-
path: process.env.TKPATH || '/cgi-bin/xmlcgi.pgm',
|
|
132
|
-
ipc: '*NA',
|
|
133
|
-
ctl: '*here',
|
|
134
|
-
xslib: 'QXMLSERV',
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
const connection = new Connection(options);
|
|
138
|
-
|
|
139
|
-
const transportOptions = connection.getTransportOptions();
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
expect(transportOptions).to.be.an('Object');
|
|
143
|
-
expect(transportOptions.database).to.equal(options.transportOptions.database);
|
|
144
|
-
expect(transportOptions.username).to.equal(options.transportOptions.username);
|
|
145
|
-
expect(transportOptions.password).to.equal(options.transportOptions.password);
|
|
146
|
-
expect(transportOptions.ctl).to.equal('*here');
|
|
147
|
-
expect(transportOptions.ipc).to.equal('*NA');
|
|
148
|
-
expect(transportOptions.xslib).to.equal('QXMLSERV');
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
describe('run', () => {
|
|
154
|
-
it('(Connection) invokes transport to execute xml input and returns xml output in callback', () => {
|
|
155
|
-
const options = {
|
|
156
|
-
transport: 'idb',
|
|
157
|
-
transportOptions: {
|
|
158
|
-
database: process.env.TKDB || '*LOCAL',
|
|
159
|
-
username: process.env.TKUSER || '',
|
|
160
|
-
password: process.env.TKPASS || '',
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
const connection = new Connection(options);
|
|
164
|
-
const xmlOut = `<?xml version='1.0'?><myscript><sql>
|
|
165
|
-
<query error='fast' conn='conn1' stmt='stmt1'>
|
|
166
|
-
<success><![CDATA[+++ success SELECT LSTNAM, STATE FROM QIWS.QCUSTCDT]]></success>
|
|
167
|
-
</query>
|
|
168
|
-
<fetch block='all' desc='on' stmt='stmt1'>
|
|
169
|
-
<row><data desc='LSTNAM'>Henning</data><data desc='STATE'>TX</data></row>
|
|
170
|
-
<row><data desc='LSTNAM'>Jones</data><data desc='STATE'>NY</data></row>
|
|
171
|
-
<row><data desc='LSTNAM'>Vine</data><data desc='STATE'>VT</data></row>
|
|
172
|
-
<row><data desc='LSTNAM'>Johnson</data><data desc='STATE'>GA</data></row>
|
|
173
|
-
<row><data desc='LSTNAM'>Tyron</data><data desc='STATE'>NY</data></row>
|
|
174
|
-
<row><data desc='LSTNAM'>Stevens</data><data desc='STATE'>CO</data></row>
|
|
175
|
-
<row><data desc='LSTNAM'>Alison</data><data desc='STATE'>MN</data></row>
|
|
176
|
-
<row><data desc='LSTNAM'>Doe</data><data desc='STATE'>CA</data></row>
|
|
177
|
-
<row><data desc='LSTNAM'>Thomas</data><data desc='STATE'>WY</data></row>
|
|
178
|
-
<row><data desc='LSTNAM'>Williams</data><data desc='STATE'>TX</data></row>
|
|
179
|
-
<row><data desc='LSTNAM'>Lee</data><data desc='STATE'>NY</data></row>
|
|
180
|
-
<row><data desc='LSTNAM'>Abraham</data><data desc='STATE'>MN</data></row>
|
|
181
|
-
<success>+++ success stmt1</success>
|
|
182
|
-
</fetch>
|
|
183
|
-
<free><success>+++ success </success>
|
|
184
|
-
</free>
|
|
185
|
-
</sql>
|
|
186
|
-
</myscript>`;
|
|
187
|
-
|
|
188
|
-
sinon.stub(connection, 'run').yields(xmlOut);
|
|
189
|
-
|
|
190
|
-
connection.run((result) => {
|
|
191
|
-
expect(result).to.equal(xmlOut);
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|