Skip to content

Commit 19d72a8

Browse files
committed
add tests for checking types of Classes
1 parent ef7177f commit 19d72a8

File tree

2 files changed

+126
-11
lines changed

2 files changed

+126
-11
lines changed

test/checkClassesTypes.js

Lines changed: 125 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
var oracledb = require('oracledb');
3838
var should = require('should');
3939
var async = require('async');
40+
var fs = require('fs');
4041
var dbConfig = require('./dbConfig.js');
42+
var assist = require('./dataTypeAssist.js');
4143

4244
describe('61. checkClassesTypes.js', function() {
4345

@@ -79,31 +81,143 @@ describe('61. checkClassesTypes.js', function() {
7981
})
8082

8183
it('61.3 Lob Class', function(done) {
82-
var connection = null,
83-
clob = null,
84-
blob = null;
85-
84+
var connection = null;
8685
var clobTableName = "oracledb_myclobs";
87-
var blobTableName = "oracledb_myblobs";
8886

8987
async.series([
90-
function(callback) {
88+
function getConn(callback) {
9189
oracledb.getConnection(credential, function(err, conn) {
9290
should.not.exist(err);
9391
connection = conn;
9492
callback();
9593
});
9694
},
97-
function(callback) {
98-
callback();
95+
function createTab(callback) {
96+
assist.createTable(connection, clobTableName, callback);
97+
},
98+
function insertLobData(callback) {
99+
var sqlInsert = "INSERT INTO " + clobTableName + " VALUES (:n, EMPTY_CLOB()) "
100+
+ " RETURNING content INTO :clob";
101+
var bindVar = { n:1, clob: {type: oracledb.CLOB, dir: oracledb.BIND_OUT} };
102+
var clobFileName = './test/clobexample.txt';
103+
104+
connection.execute(
105+
sqlInsert,
106+
bindVar,
107+
function(err, result) {
108+
should.not.exist(err);
109+
110+
var lob = result.outBinds.clob[0];
111+
var clobStream = fs.createReadStream(clobFileName);
112+
113+
clobStream.on('error', function(err) {
114+
should.not.exist();
115+
});
116+
117+
lob.on('error', function(err) {
118+
should.not.exist(err);
119+
});
120+
121+
clobStream.on('end', function() {
122+
connection.commit( function(err) {
123+
should.not.exist(err);
124+
callback();
125+
});
126+
});
127+
128+
clobStream.pipe(lob);
129+
}
130+
);
131+
},
132+
function checking(callback) {
133+
var sqlSelect = "SELECT * FROM " + clobTableName + " WHERE num = :n";
134+
connection.execute(
135+
sqlSelect,
136+
{ n: 1 },
137+
function(err, result) {
138+
should.not.exist(err);
139+
var lob = result.rows[0][1];
140+
141+
var type = Object.prototype.toString.call(lob);
142+
type.should.eql('[object Object]');
143+
144+
callback();
145+
}
146+
);
147+
},
148+
function dropTab(callback) {
149+
connection.execute(
150+
"DROP TABLE " + clobTableName,
151+
function(err) {
152+
should.not.exist(err);
153+
callback();
154+
}
155+
);
99156
},
100-
function(callback) {
157+
function releaseConn(callback) {
101158
connection.release( function(err) {
102159
should.not.exist(err);
103160
callback();
104161
});
105162
}
106-
], done);
107-
})
163+
], done);
164+
}) // 61.3
165+
166+
it('61.4 Pool Class', function(done) {
167+
async.waterfall(
168+
[
169+
function(callback) {
170+
oracledb.createPool(credential, callback);
171+
},
172+
function(pool, callback) {
173+
var type = Object.prototype.toString.call(pool);
174+
type.should.eql('[object Pool]');
175+
176+
return callback(null, pool);
177+
},
178+
function(pool, callback) {
179+
pool.terminate(callback);
180+
}
181+
],
182+
function(err) {
183+
should.not.exist(err);
184+
done();
185+
}
186+
);
187+
}) // 61.4
188+
189+
it('61.5 ResultSet Class', function(done) {
190+
async.waterfall(
191+
[
192+
function(callback) {
193+
oracledb.getConnection(credential, callback);
194+
},
195+
function(connection, callback) {
196+
connection.execute(
197+
"SELECT 'abcde' FROM dual",
198+
[],
199+
{ resultSet: true },
200+
function(err, result) {
201+
if (err)
202+
return callback(err);
203+
else {
204+
var type = Object.prototype.toString.call(result.resultSet);
205+
type.should.eql('[object ResultSet]');
206+
return callback(null, connection);
207+
}
208+
}
209+
);
210+
},
211+
function(connection, callback) {
212+
connection.release(callback);
213+
}
214+
],
215+
function(err) {
216+
should.not.exist(err);
217+
done();
218+
}
219+
);
220+
}) // 61.5
221+
108222
})
109223

test/lobProperties.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ describe('62. lobProperties.js', function() {
451451

452452
var t1 = clob.type,
453453
t2 = blob.type;
454+
454455
t1.should.eql(oracledb.CLOB);
455456
t2.should.eql(oracledb.BLOB);
456457

0 commit comments

Comments
 (0)