Skip to content

Commit 1e78481

Browse files
committed
Add tests for oracledb.fetchArraySize
1 parent 73f27ab commit 1e78481

File tree

7 files changed

+2057
-1
lines changed

7 files changed

+2057
-1
lines changed

test/fetchArraySize1.js

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
/* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. */
2+
3+
/******************************************************************************
4+
*
5+
* You may not use the identified files except in compliance with the Apache
6+
* License, Version 2.0 (the "License.")
7+
*
8+
* You may obtain a copy of the License at
9+
* http://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
*
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* The node-oracledb test suite uses 'mocha', 'should' and 'async'.
19+
* See LICENSE.md for relevant licenses.
20+
*
21+
* NAME
22+
* 148. fetchArraySize1.js
23+
*
24+
* DESCRIPTION
25+
* Check the value settings of "fetchArraySize" property.
26+
*
27+
* NUMBERING RULE
28+
* Test numbers follow this numbering rule:
29+
* 1 - 20 are reserved for basic functional tests
30+
* 21 - 50 are reserved for data type supporting tests
31+
* 51 onwards are for other tests
32+
*
33+
*****************************************************************************/
34+
'use strict';
35+
36+
var oracledb = require('oracledb');
37+
var should = require('should');
38+
var dbConfig = require('./dbconfig.js');
39+
40+
describe("148. fetchArraySize1.js", function() {
41+
42+
var connection = null;
43+
var defaultVal = oracledb.fetchArraySize;
44+
45+
before(function(done) {
46+
oracledb.getConnection(dbConfig, function(err, conn) {
47+
should.strictEqual(defaultVal, 100);
48+
should.not.exist(err);
49+
connection = conn;
50+
done();
51+
});
52+
});
53+
54+
after(function(done) {
55+
connection.close(function(err) {
56+
should.not.exist(err);
57+
done();
58+
});
59+
});
60+
61+
describe("148.1 oracledb.fetchArraySize", function() {
62+
63+
afterEach(function(done) {
64+
oracledb.fetchArraySize = defaultVal;
65+
done();
66+
});
67+
68+
it("148.1.1 oracledb.fetchArraySize = 0", function(done) {
69+
checkError(0, done);
70+
});
71+
72+
it("148.1.2 oracledb.fetchArraySize = 1", function(done) {
73+
checkGlobalOptionValue(1, 1, done);
74+
});
75+
76+
it("148.1.3 Negative: oracledb.fetchArraySize = undefined", function(done) {
77+
checkError(undefined, done);
78+
});
79+
80+
it("148.1.4 Negative: oracledb.fetchArraySize = null", function(done) {
81+
checkError(null, done);
82+
});
83+
84+
it("148.1.5 Negative: oracledb.fetchArraySize = random string", function(done) {
85+
checkError("random string", done);
86+
});
87+
88+
it("148.1.6 Negative: oracledb.fetchArraySize = Boolean", function(done) {
89+
checkError(true, done);
90+
});
91+
92+
it("148.1.7 Negative: oracledb.fetchArraySize = NaN", function(done) {
93+
checkError(NaN, done);
94+
});
95+
96+
it("148.1.8 oracledb.fetchArraySize = big number", function(done) {
97+
checkGlobalOptionValue(1000000, 1000000, done);
98+
});
99+
100+
});
101+
102+
describe("148.2 execute() option fetchArraySize", function() {
103+
104+
it("148.2.1 fetchArraySize = 0", function(done) {
105+
queryExpectsError(0, done);
106+
});
107+
108+
it("148.2.2 fetchArraySize = 1", function(done) {
109+
checkExecOptionValue(1, done);
110+
});
111+
112+
it("148.2.3 fetchArraySize = undefined works as default value 100", function(done) {
113+
checkExecOptionValue(undefined, done);
114+
});
115+
116+
it("148.2.4 Negative: fetchArraySize = null", function(done) {
117+
queryExpectsError(null, done);
118+
});
119+
120+
it("148.2.5 Negative: fetchArraySize = random string", function(done) {
121+
queryExpectsError("random string", done);
122+
});
123+
124+
it("148.2.6 Negative: fetchArraySize = Boolean", function(done) {
125+
queryExpectsError(false, done);
126+
});
127+
128+
it("148.2.7 Negative: fetchArraySize = NaN", function(done) {
129+
queryExpectsError(NaN, done);
130+
});
131+
132+
it("148.2.8 fetchArraySize = big number", function(done) {
133+
checkExecOptionValue(1000000, done);
134+
});
135+
136+
});
137+
138+
var checkGlobalOptionValue = function(values, expectedFetchArraySize, cb) {
139+
should.doesNotThrow(
140+
function() {
141+
oracledb.fetchArraySize = values;
142+
}
143+
);
144+
145+
connection.execute(
146+
"select 'oracledb.fetchArraySize' from dual",
147+
function(err, result) {
148+
should.not.exist(err);
149+
should.strictEqual(result.rows[0][0], "oracledb.fetchArraySize");
150+
should.strictEqual(oracledb.fetchArraySize, expectedFetchArraySize);
151+
cb();
152+
}
153+
);
154+
};
155+
156+
var checkError = function(values, cb) {
157+
should.throws(
158+
function() {
159+
oracledb.fetchArraySize = values;
160+
},
161+
/NJS-004: invalid value for property fetchArraySize/
162+
);
163+
cb();
164+
};
165+
166+
var checkExecOptionValue = function(values, cb) {
167+
connection.execute(
168+
"select 'fetchArraySize' from dual",
169+
[],
170+
{ fetchArraySize: values },
171+
function(err, result) {
172+
should.not.exist(err);
173+
should.strictEqual(oracledb.fetchArraySize, 100);
174+
should.strictEqual(result.rows[0][0], "fetchArraySize");
175+
cb();
176+
}
177+
);
178+
};
179+
180+
var queryExpectsError = function(values, cb) {
181+
connection.execute(
182+
"select 'fetchArraySize' from dual",
183+
[],
184+
{ fetchArraySize: values },
185+
function(err, result) {
186+
should.exist(err);
187+
should.not.exist(result);
188+
if( values === "random string" || values === false ) {
189+
should.strictEqual(err.message, "NJS-008: invalid type for \"fetchArraySize\" in parameter 3");
190+
} else {
191+
should.strictEqual(err.message, "NJS-007: invalid value for \"fetchArraySize\" in parameter 3");
192+
}
193+
cb();
194+
}
195+
);
196+
};
197+
198+
});

0 commit comments

Comments
 (0)