node-oracledb/test/properties.js

404 lines
11 KiB
JavaScript
Raw Normal View History

2015-09-25 16:46:56 +08:00
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
/******************************************************************************
*
* You may not use the identified files except in compliance with the Apache
* License, Version 2.0 (the "License.")
*
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
* The node-oracledb test suite uses 'mocha', 'should' and 'async'.
* See LICENSE.md for relevant licenses.
*
* NAME
* 58. properties.js
*
* DESCRIPTION
* Testing getters and setters for oracledb and pool classes.
* This test aims to increase the code coverage rate.
*
* NUMBERING RULE
* Test numbers follow this numbering rule:
* 1 - 20 are reserved for basic functional tests
* 21 - 50 are reserved for data type supporting tests
* 51 onwards are for other tests
*
*****************************************************************************/
"use strict"
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
describe('58. properties.js', function() {
if(dbConfig.externalAuth){
var credential = { externalAuth: true, connectString: dbConfig.connectString };
} else {
var credential = dbConfig;
}
describe('58.1 oracledb properties', function() {
var defaultValues = {};
before('save the default values', function() {
defaultValues.poolMin = oracledb.poolMin;
defaultValues.poolMax = oracledb.poolMax;
defaultValues.poolIncrement = oracledb.poolIncrement;
defaultValues.poolTimeout = oracledb.poolTimeout;
defaultValues.maxRows = oracledb.maxRows;
defaultValues.prefetchRows = oracledb.prefetchRows;
defaultValues.autoCommit = oracledb.autoCommit;
defaultValues.version = oracledb.version;
defaultValues.connClass = oracledb.connClass;
defaultValues.externalAuth = oracledb.externalAuth;
defaultValues.fetchAsString = oracledb.fetchAsString;
defaultValues.outFormat = oracledb.outFormat;
defaultValues.lobPrefetchSize = oracledb.lobPrefetchSize;
/*
* lobPrefetchSize property is currently disabled.
* Resetting it to default will lead to uncaught error "NJS-021: invalid type for conversion specified"
*/
})
after('restore the values', function() {
oracledb.poolMin = defaultValues.poolMin;
oracledb.poolMax = defaultValues.poolMax;
oracledb.poolIncrement = defaultValues.poolIncrement;
oracledb.poolTimeout = defaultValues.poolTimeout;
oracledb.maxRows = defaultValues.maxRows;
oracledb.prefetchRows = defaultValues.prefetchRows;
oracledb.autoCommit = defaultValues.autoCommit;
// oracledb.version = defaultValues.version; // version is a read-only property
oracledb.connClass = defaultValues.connClass;
oracledb.externalAuth = defaultValues.externalAuth;
oracledb.fetchAsString = defaultValues.fetchAsString;
oracledb.outFormat = defaultValues.outFormat;
oracledb.lobPrefetchSize = defaultValues.lobPrefetchSize;
})
it('58.1.1 poolMin', function() {
var t = oracledb.poolMin;
oracledb.poolMin = t + 1;
t.should.eql(defaultValues.poolMin);
(oracledb.poolMin).should.eql(defaultValues.poolMin + 1);
})
it('58.1.2 poolMax', function() {
var t = oracledb.poolMax;
oracledb.poolMax = t + 1;
t.should.eql(defaultValues.poolMax);
(oracledb.poolMax).should.eql(defaultValues.poolMax + 1);
})
it('58.1.3 poolIncrement', function() {
var t = oracledb.poolIncrement;
oracledb.poolIncrement = t + 1;
t.should.eql(defaultValues.poolIncrement);
(oracledb.poolIncrement).should.eql(defaultValues.poolIncrement + 1);
})
it('58.1.4 poolTimeout', function() {
var t = oracledb.poolTimeout;
oracledb.poolTimeout = t + 1;
t.should.eql(defaultValues.poolTimeout);
(oracledb.poolTimeout).should.eql(defaultValues.poolTimeout + 1);
})
it('58.1.5 maxRows', function() {
var t = oracledb.maxRows;
oracledb.maxRows = t + 1;
t.should.eql(defaultValues.maxRows);
(oracledb.maxRows).should.eql(defaultValues.maxRows + 1);
})
it('58.1.6 prefetchRows', function() {
var t = oracledb.prefetchRows;
oracledb.prefetchRows = t + 1;
t.should.eql(defaultValues.prefetchRows);
(oracledb.prefetchRows).should.eql(defaultValues.prefetchRows + 1);
})
it('58.1.7 autoCommit', function() {
var t = oracledb.autoCommit;
oracledb.autoCommit = !t;
t.should.eql(defaultValues.autoCommit);
(oracledb.autoCommit).should.eql( !defaultValues.autoCommit );
})
2015-10-15 09:49:10 +08:00
it('58.1.8 version (read-only)', function() {
2015-09-25 16:46:56 +08:00
(oracledb.version).should.be.a.Number;
try {
oracledb.version = 5;
} catch(err) {
should.exist(err);
// console.log(err.message);
(err.message).should.startWith('NJS-014');
}
})
it('58.1.9 connClass', function() {
oracledb.connClass = "cc";
(oracledb.connClass).should.be.a.String;
})
it('58.1.10 externalAuth', function() {
var t = oracledb.externalAuth;
oracledb.externalAuth = !t;
t.should.eql(defaultValues.externalAuth);
(oracledb.externalAuth).should.eql( !defaultValues.externalAuth );
})
it('58.1.11 fetchAsString', function() {
var t = oracledb.fetchAsString;
oracledb.fetchAsString = [oracledb.DATE];
t.should.eql(defaultValues.fetchAsString);
(oracledb.fetchAsString).should.not.eql(defaultValues.fetchAsString);
})
it('58.1.12 outFormat', function() {
var t = oracledb.outFormat;
oracledb.outFormat = oracledb.OBJECT;
t.should.eql(oracledb.ARRAY);
(oracledb.outFormat).should.not.eql(defaultValues.outFormat);
})
it('58.1.13 lobPrefetchSize', function() {
var t = oracledb.lobPrefetchSize;
oracledb.lobPrefetchSize = t + 1;
t.should.eql(defaultValues.lobPrefetchSize);
(oracledb.lobPrefetchSize).should.eql(defaultValues.lobPrefetchSize + 1);
})
2015-10-15 09:49:10 +08:00
it('58.1.14 oracleClientVersion (read-only)', function () {
var t = oracledb.oracleClientVersion ;
t.should.be.a.Number;
try {
oracledb.oracleClientVersion++;
} catch(err) {
should.exist(err);
(err.message).should.startWith('NJS-014');
}
} );
2015-09-25 16:46:56 +08:00
}) // 58.1
describe('58.2 pool properties', function() {
var pool = null;
before(function(done) {
oracledb.createPool(
dbConfig,
function(err, p) {
should.not.exist(err);
pool = p;
done();
}
);
})
after(function(done) {
pool.terminate(function(err) {
should.not.exist(err);
done();
});
})
it('58.2.1 poolMin', function() {
var t = pool.poolMin;
t.should.be.a.Number;
try {
pool.poolMin++;
} catch(err) {
should.exist(err);
(err.message).should.startWith('NJS-014');
}
})
it('58.2.2 poolMax', function() {
var t = pool.poolMax;
t.should.be.a.Number;
try {
pool.poolMax++;
} catch(err) {
should.exist(err);
(err.message).should.startWith('NJS-014');
}
})
it('58.2.3 poolIncrement', function() {
var t = pool.poolIncrement;
t.should.be.a.Number;
try {
pool.poolIncrement++;
} catch(err) {
should.exist(err);
(err.message).should.startWith('NJS-014');
}
})
it('58.2.4 poolTimeout', function() {
var t = pool.poolTimeout;
t.should.be.a.Number;
try {
pool.poolTimeout++;
} catch(err) {
should.exist(err);
(err.message).should.startWith('NJS-014');
}
})
it('58.2.5 stmtCacheSize', function() {
var t = pool.stmtCacheSize;
t.should.be.a.Number;
try {
pool.stmtCacheSize++;
} catch(err) {
should.exist(err);
(err.message).should.startWith('NJS-014');
}
})
}) // 58.2
describe('58.3 connection properties', function() {
var connection = null;
before('get one connection', function(done) {
oracledb.getConnection(credential, function(err, conn) {
should.not.exist(err);
connection = conn;
done();
});
})
after('release connection', function(done) {
connection.release( function(err) {
should.not.exist(err);
done();
});
})
2015-10-15 09:49:10 +08:00
it('58.3.1 Connection object initial toString values', function() {
2015-09-25 16:46:56 +08:00
connection.should.be.an.Object;
should.equal(connection.action, null);
should.equal(connection.module, null);
should.equal(connection.clientId, null);
(connection.stmtCacheSize).should.be.a.Number;
(connection.stmtCacheSize).should.be.greaterThan(0);
})
2015-10-15 09:49:10 +08:00
it('58.3.2 stmtCacheSize (read-only)', function() {
2015-09-25 16:46:56 +08:00
var t = connection.stmtCacheSize;
t.should.be.a.Number;
try {
connection.stmtCacheSize++;
} catch(err) {
should.exist(err);
(err.message).should.startWith('NJS-014');
}
})
2015-10-15 09:49:10 +08:00
it('58.3.3 clientId (write-only)', function() {
2015-09-25 16:46:56 +08:00
try {
var t = connection.clientId;
} catch(err) {
should.exist(err);
(err.message).should.startWith('NJS-015'); // write-only
}
try {
connection.clientId = 4;
} catch(err) {
should.exist(err);
(err.message).should.startWith('NJS-004'); // invalid value
}
connection.clientId = "103.3";
})
2015-10-15 09:49:10 +08:00
it('58.3.4 action (write-only)', function() {
2015-09-25 16:46:56 +08:00
try {
var t = connection.action;
} catch(err) {
should.exist(err);
(err.message).should.startWith('NJS-015');
}
try {
connection.action = 4;
} catch(err) {
should.exist(err);
(err.message).should.startWith('NJS-004'); // invalid value
}
connection.action = "103.3 action";
})
2015-10-15 09:49:10 +08:00
it('58.3.5 module (write-only)', function() {
2015-09-25 16:46:56 +08:00
try {
var t = connection.module;
} catch(err) {
should.exist(err);
(err.message).should.startWith('NJS-015');
}
try {
connection.module = 4;
} catch(err) {
should.exist(err);
(err.message).should.startWith('NJS-004'); // invalid value
}
connection.module = "103.3 module";
})
2015-10-15 09:49:10 +08:00
it('58.3.6 oracleServerVersion (read-only)', function () {
var t = connection.oracleServerVersion;
t.should.be.a.Number;
try {
2015-10-15 09:49:10 +08:00
connection.oracleServerVersion++;
}
2015-10-15 09:49:10 +08:00
catch (err) {
should.exist ( err );
2015-10-15 09:49:10 +08:00
(err.message).should.startWith('NJS-014');
}
});
2015-09-25 16:46:56 +08:00
}) // 58.3
})