Initial SODA tests

This commit is contained in:
Christopher Jones 2018-09-30 22:25:54 +10:00
parent e0eb7530f2
commit 58e4fe01ee
9 changed files with 1803 additions and 0 deletions

View File

@ -4163,6 +4163,55 @@ Overview of node-oracledb functional tests
163.14 Negative - set numIterations to be string 163.14 Negative - set numIterations to be string
163.15 Negative - set numIterations to be negative value 163.15 Negative - set numIterations to be negative value
164. soda1.js
164.1 getSodaDatabase() creates a sodaDatabase Object
164.2 createCollection() creates a collection
164.3 openCollection() opens an existing colleciton
164.4 getCollectionNames() gets an array of collection names
164.5 create collection with metadata
164.6 the operation status of collection.drop()
164.7 Negative: the operation status of collection.drop()
164.8 get one document
164.9 get multiple documents
164.10 create index
164.11 the examples/soda1.js case
165. soda2.js
165.1 create two sodaDatabase objects which point to the same instance
165.2 create two sodaDatabase objects from two connections
165.3 creating a collection with the existing name will open this collection
165.4 create collection with metadata
165.5 Negative - create collection with an invalid metadata
165.6 throw error when creating collection with the existing name and different metadata
165.7 Negative - createCollection() when collection name is empty string
166. sodaCallback.js
166.1 create a collection, then drop it
166.2 the callback version of "examples/soda1.js" case
167 soda3.js
167.1 get collection names
167.2 getCollectionNames() - limit option
167.3 getCollectionNames() - limit is "undefined"
167.4 getCollectionNames() - limit is 0
167.5 getCollectionNames() - limit is null
167.6 getCollectionNames() - limit is an empty string
167.7 getCollectionNames() - limit is a negative number
167.8 starsWith option - basic test
167.9 starsWith is case sensitive
167.10 starsWith is an empyt string
167.11 starsWith is null
167.12 Negative - starsWith is invalid type, a Number
167.13 openCollection() basic case 1
167.14 openCollection() basic case 2
167.15 the returned value is null if the requested collection does not exist
167.16 the requested collection name is case sensitive
168. soda4.js
168.1 insertOneAndGet() method
168.2 customize the key value
168.3 content is null
170. poolDrain.js 170. poolDrain.js
170.1 close pool with force flag, and prevent new connection 170.1 close pool with force flag, and prevent new connection
170.2 close pool without force flag (will give out an error ), and prevent new connections 170.2 close pool without force flag (will give out an error ), and prevent new connections

View File

@ -192,3 +192,9 @@ test/getStmtInfo.js
test/executeMany.js test/executeMany.js
test/poolDrain.js test/poolDrain.js
test/soda1.js
test/soda2.js
test/soda3.js
test/sodaCallback.js
test/soda4.js

View File

@ -189,3 +189,5 @@ test/editionTest.js
test/changePassword.js test/changePassword.js
test/getStmtInfo.js test/getStmtInfo.js
test/executeMany.js test/executeMany.js
test/sodaCallback.js

479
test/soda1.js Normal file
View File

@ -0,0 +1,479 @@
/* Copyright (c) 2018, 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
* 164. soda1.js
*
* DESCRIPTION
* Some basic tests of SODA.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const should = require('should');
const dbconfig = require('./dbconfig.js');
const sodaUtil = require('./sodaUtil.js');
describe('164. soda1.js', () => {
before(async function() {
const runnable = await sodaUtil.checkPrerequisites();
if (!runnable) this.skip();
await sodaUtil.cleanup();
});
it('164.1 getSodaDatabase() creates a sodaDatabase Object', async () => {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
should.exist(sd);
} catch(err) {
should.not.exist(err);
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 164.1
it('164.2 createCollection() creates a collection', async () => {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let collName = "soda_test_164_2";
let coll = await sd.createCollection(collName);
await coll.drop();
} catch(err) {
should.not.exist(err);
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
});// 164.2
it('164.3 openCollection() opens an existing colleciton', async () => {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let collName = "soda_test_164_3";
let coll = await sd.createCollection(collName);
await conn.commit();
let newColl = await sd.openCollection(collName);
should.strictEqual(newColl.name, coll.name);
await newColl.drop();
} catch(err) {
should.not.exist(err);
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 164.3
it('164.4 getCollectionNames() gets an array of collection names', async () => {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let collNames = [
"soda_test_164_4_1",
"soda_test_164_4_2",
"soda_test_164_4_3",
"soda_test_164_4_4",
"soda_test_164_4_5"
];
let collections = await Promise.all(
collNames.map(function(name) {
return sd.createCollection(name);
})
);
let cNames = await sd.getCollectionNames();
should.deepEqual(cNames, collNames);
let opResults = await Promise.all(
collections.map(function(coll) {
return coll.drop();
})
);
opResults.forEach(function(res) {
should.strictEqual(res.dropped, true);
});
} catch(err) {
should.not.exist(err);
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 164.4
it('164.5 create collection with metadata', async () => {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let metadata = {
"schemaName" : dbconfig.user.toUpperCase(),
"tableName" : "nodb_tab_164_5",
"keyColumn" :
{
"name" : "ID",
"sqlType" : "VARCHAR2",
"maxLength" : 255,
"assignmentMethod" : "UUID"
},
"contentColumn" :
{
"name" : "JSON_DOCUMENTS",
"sqlType" : "BLOB",
"compress" : "NONE",
"cache" : true,
"encrypt" : "NONE",
"validation" : "STRICT"
},
"versionColumn" :
{
"name" : "VERSION",
"type":"String",
"method":"SHA256"
},
"lastModifiedColumn" :
{
"name":"LAST_MODIFIED"
},
"creationTimeColumn":
{
"name":"CREATED_ON"
},
"readOnly": false
};
let t_collname = "soda_test_164_5";
let options = { metaData: metadata };
let coll = await sd.createCollection(t_collname, options);
await conn.commit();
should.strictEqual(coll.name, t_collname);
await coll.drop();
} catch(err) {
should.not.exist(err);
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 164.5
it('164.6 the operation status of collection.drop()', async () => {
let conn, coll;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let collName = "soda_test_164_6";
coll = await sd.createCollection(collName);
} catch(err) {
should.not.exist(err);
} finally {
if (coll) {
let res = await coll.drop();
should.strictEqual(res.dropped, true);
}
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 164.6
it('164.7 Negative: the operation status of collection.drop()', async () => {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let collName = "soda_test_164_7";
let coll = await sd.createCollection(collName);
await coll.drop();
let res = await coll.drop();
should.strictEqual(res.dropped, false);
} catch(err) {
should.not.exist(err);
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 164.7
it('164.8 get one document', async () => {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let collectionName = 'soda_test_164_8';
let coll = await sd.createCollection(collectionName);
await coll.find().remove();
// Insert a new document
let myContent = { name: "Sally", address: {city: "Melbourne"} };
await coll.insertOne(myContent);
let docs = await coll.find().getDocuments();
//console.log(docs);
should.strictEqual(docs.length, 1);
docs.forEach(function(element) {
let content = element.getContent();
should.strictEqual(content.name, myContent.name);
should.strictEqual(content.address.city, myContent.address.city);
});
await conn.commit();
let res = await coll.drop();
should.strictEqual(res.dropped, true);
} catch(err) {
should.not.exist(err);
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 164.8
it('164.9 get multiple documents', async () => {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let collectionName = 'soda_test_164_9';
let coll = await sd.createCollection(collectionName);
let myContents = [
{ name: "Sally", address: {city: "Melbourne"} },
{ name: "Venkat", address: {city: "Bangalore"} },
{ name: "Changjie", address: {city: "Shenzhen"} }
];
await Promise.all(
myContents.map(function(con) {
return coll.insertOne(con);
})
);
let docs = await coll.find().getDocuments();
should.strictEqual(docs.length, 3);
docs.forEach(function(element) {
let content = element.getContent();
myContents.should.containEql(content);
});
await conn.commit();
let res = await coll.drop();
should.strictEqual(res.dropped, true);
} catch(err) {
should.not.exist(err);
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 164.9
it('164.10 create index', async () => {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let collectionName = 'soda_test_164_10';
let coll = await sd.createCollection(collectionName);
var index =
{
name : "nameIndex",
fields : [ { path: "name" }]
};
await coll.createIndex(index);
await conn.commit();
await coll.drop();
} catch(err) {
should.not.exist(err);
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 164.10
it('164.11 the "examples/soda1.js" case', async () => {
let conn, collection;
try {
conn = await oracledb.getConnection(dbconfig);
// Create the parent object for SODA
let soda = conn.getSodaDatabase();
// Create a new SODA collection and index
collection = await soda.createCollection("soda_test_164_11");
let indexSpec = {
"name": "CITY_IDX",
"fields": [
{
"path": "address.city",
"datatype": "string",
"order": "asc"
}
]
};
await collection.createIndex(indexSpec);
// Insert a document
// A system generated key is created by default
let content1 = { name: "Matilda", address: {city: "Melbourne"} };
let doc1 = await collection.insertOneAndGet(content1);
let myKey = doc1.key;
should.exist(myKey);
(myKey).should.be.a.String();
// Fetch the document back
let doc2 = await collection.find().key(myKey).getOne();
let content2 = doc2.getContent(); // A JavaScript object
should.deepEqual(content2, content1);
let content3 = doc2.getContentAsString(); // A JSON string
(content3).should.be.a.String();
should.strictEqual( JSON.stringify(content2), content3 );
// Replace document contents
let content4 = { name: "Matilda", address: {city: "Sydney"} };
await collection.find().key(myKey).replaceOne(content4);
// Insert some more documents without caring about their keys
let content5 = { name: "Venkat", address: {city: "Bengaluru"} };
await collection.insertOne(content5);
let content6 = { name: "May", address: {city: "London"} };
await collection.insertOne(content6);
let content7 = { name: "Sally-Ann", address: {city: "San Francisco"} };
await collection.insertOne(content7);
// Find all documents with city names starting with 'S'
let documents = await collection.find()
.filter({"address.city": {"$like": "S%"}})
.getDocuments();
for (let i = 0; i < documents.length; i++) {
let content = documents[i].getContent();
(['Sydney', 'San Francisco']).should.containEql(content.address.city);
}
// Count all documents
let res1 = await collection.find().count();
should.strictEqual(res1.count, 4);
// Remove documents with cities containing 'o'
let res2 = await collection.find().filter({"address.city": {"$regex": ".*o.*"}}).remove();
should.strictEqual(res2.count, 2);
// Count all documents
let res3 = await collection.find().count();
should.strictEqual(res3.count, 2);
// Commit changes
await conn.commit();
} catch(err) {
should.not.exist(err);
} finally {
// Drop the collection
if (collection) {
let res = await collection.drop();
should.strictEqual(res.dropped, true);
}
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 164.11
});

392
test/soda2.js Normal file
View File

@ -0,0 +1,392 @@
/* Copyright (c) 2018, 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
* 165. soda2.js
*
* DESCRIPTION
* Some more tests of sodaDatabase object and createCollection() method.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const should = require('should');
const dbconfig = require('./dbconfig.js');
const sodaUtil = require('./sodaUtil.js');
describe('165. soda2.js', () => {
before(async function() {
const runnable = await sodaUtil.checkPrerequisites();
if (!runnable) this.skip();
await sodaUtil.cleanup();
});
it('165.1 create two sodaDatabase objects which point to the same instance', async () => {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd1 = conn.getSodaDatabase();
let sd2 = conn.getSodaDatabase();
// sd1 creates the collection
let collName = "soda_test_165_1";
let coll_create = await sd1.createCollection(collName);
// sd2 opens the collection
let coll_open = await sd2.openCollection(collName);
should.exist(coll_open);
await coll_create.drop();
} catch(err) {
should.not.exist(err);
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 165.1
it('165.2 create two sodaDatabase objects from two connections', async () => {
let conn1, conn2;
try {
conn1 = await oracledb.getConnection(dbconfig);
let sd1 = conn1.getSodaDatabase();
conn2 = await oracledb.getConnection(dbconfig);
let sd2 = conn1.getSodaDatabase();
let t_collname = "soda_test_165_2";
let coll = await sd1.createCollection(t_collname);
let cNames = await sd2.getCollectionNames();
should.deepEqual(cNames, [ t_collname ] );
await coll.drop();
} catch(err) {
should.not.exist(err);
} finally {
if (conn1) {
try {
await conn1.close();
} catch(err) {
should.not.exist(err);
}
}
if (conn2) {
try {
await conn2.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 165.2
it('165.3 creating a collection with the existing name will open this collection', async () => {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let t_collname = "soda_test_165_3";
await sd.createCollection(t_collname);
let coll = await sd.createCollection(t_collname);
let cNames = await sd.getCollectionNames();
should.deepEqual(cNames, [ t_collname ] );
await coll.drop();
} catch(err) {
should.not.exist(err);
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 165.3
// The reason of skipping this case is that the returned metaData
// is String type rather than JSON object according to FS
it.skip('165.4 create collection with metadata', async () => {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let t_metadata = {
"schemaName" : dbconfig.user.toUpperCase(),
"tableName" : "myTableName",
"keyColumn" :
{
"name" : "ID",
"sqlType" : "VARCHAR2",
"maxLength" : 255,
"assignmentMethod" : "UUID"
},
"contentColumn" :
{
"name" : "JSON_DOCUMENT",
"sqlType" : "BLOB",
"compress" : "NONE",
"cache" : true,
"encrypt" : "NONE",
"validation" : "STANDARD"
},
"versionColumn" :
{
"name" : "VERSION",
"method" : "SHA256"
},
"lastModifiedColumn" :
{
"name" : "LAST_MODIFIED"
},
"creationTimeColumn" :
{
"name" : "CREATED_ON"
},
"readOnly" : true
};
let t_collname = "soda_test_165_4";
let options = { metaData: t_metadata };
let coll = await sd.createCollection(t_collname, options);
await conn.commit();
should.strictEqual(coll.name, t_collname);
//should.strictEqual(coll.metaData.schemaName, t_metadata.schemaName);
console.log(typeof coll.metaData);
console.log(t_metadata);
await coll.drop();
} catch(err) {
should.not.exist(err);
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 165.4
it('165.5 Negative - create collection with an invalid metadata', async () => {
let conn, coll;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let t_metadata = {
"schemaName" : "nonexistent",
"tableName" : "bar",
"keyColumn" :
{
"name" : "ID",
"sqlType" : "VARCHAR2",
"maxLength" : 255,
"assignmentMethod" : "UUID"
},
"contentColumn" :
{
"name" : "JSON_DOCUMENT",
"sqlType" : "BLOB",
"compress" : "NONE",
"cache" : true,
"encrypt" : "NONE",
"validation" : "STANDARD"
},
"versionColumn" :
{
"name" : "VERSION",
"method" : "SHA256"
},
"lastModifiedColumn" :
{
"name" : "LAST_MODIFIED"
},
"creationTimeColumn" :
{
"name" : "CREATED_ON"
},
"readOnly" : false
};
let t_collname = "soda_test_165_5";
let options = { metaData: t_metadata };
coll = await sd.createCollection(t_collname, options);
} catch(err) {
// ORA-01918: user \'nonexistent\' does not exist
should.exist(err);
(err.message).should.startWith('ORA-01918:');
} finally {
should.not.exist(coll);
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 165.5
it('165.6 throw error when creating collection with the existing name and different metadata', async () => {
let conn;
let collection1, collection2;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let t_metadata1 = {
"schemaName" : dbconfig.user.toUpperCase(),
"tableName" : "nodb_tab_164_6",
"keyColumn" :
{
"name" : "ID",
"sqlType" : "VARCHAR2",
"maxLength" : 255,
"assignmentMethod" : "UUID"
},
"contentColumn" :
{
"name" : "JSON_DOCUMENTS",
"sqlType" : "BLOB",
"compress" : "NONE",
"cache" : true,
"encrypt" : "NONE",
"validation" : "STRICT"
},
"versionColumn" :
{
"name" : "VERSION",
"type":"String",
"method":"SHA256"
},
"lastModifiedColumn" :
{
"name":"LAST_MODIFIED"
},
"creationTimeColumn":
{
"name":"CREATED_ON"
},
"readOnly": false
};
let t_collname = "soda_test_165_5";
let options = { metaData: t_metadata1 };
collection1 = await sd.createCollection(t_collname, options);
let t_metadata2 = {
"schemaName" : "foo",
"tableName" : "bar",
"keyColumn" :
{
"name" : "ID",
"sqlType" : "VARCHAR2",
"maxLength" : 255,
"assignmentMethod" : "UUID"
},
"contentColumn" :
{
"name" : "JSON_DOCUMENTS",
"sqlType" : "BLOB",
"compress" : "NONE",
"cache" : true,
"encrypt" : "NONE",
"validation" : "STRICT"
},
"versionColumn" :
{
"name" : "VERSION",
"type":"String",
"method":"SHA256"
},
"lastModifiedColumn" :
{
"name":"LAST_MODIFIED"
},
"creationTimeColumn":
{
"name":"CREATED_ON"
},
"readOnly": true
};
let options2 = { metaData: t_metadata2 };
collection2 = await sd.createCollection(t_collname, options2); // should error out
} catch(err) {
should.exist(err);
(err.message).should.startWith('ORA-40669:');
// ORA-40669: Collection create failed: collection with same name but different metadata exists.
} finally {
should.not.exist(collection2);
if (collection1) {
try {
await collection1.drop();
} catch(err) {
should.not.exist(err);
}
}
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 165.6
it('165.7 Negative - createCollection() when collection name is empty string', async () => {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let collName = "";
let coll = await sd.createCollection(collName);
await coll.drop();
} catch(err) {
should.exist(err);
// ORA-40658: Collection name cannot be null for this operation.
(err.message).should.startWith("ORA-40658:");
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 165.7
});

252
test/soda3.js Normal file
View File

@ -0,0 +1,252 @@
/* Copyright (c) 2018, 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
* 167. soda3.js
*
* DESCRIPTION
* SODA tests that use many collections.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const should = require('should');
const dbconfig = require('./dbconfig.js');
const sodaUtil = require('./sodaUtil.js');
describe('167. soda3.js', () => {
let conn, sd, t_collections;
let t_collectionNames = [
"chris_1", "chris_2", "chris_3", "chris_4",
"changjie_1", "changjie_2", "Changjie_3", "Changjie_4",
"venkat_1", "venkat_2", "venkat_3", "venkat_4"
];
before('create collections', async function() {
const runnable = await sodaUtil.checkPrerequisites();
if (!runnable) this.skip();
await sodaUtil.cleanup();
try {
conn = await oracledb.getConnection(dbconfig);
sd = conn.getSodaDatabase();
t_collections = await Promise.all(
t_collectionNames.map(function(name) {
return sd.createCollection(name);
})
);
} catch(err) {
should.not.exist(err);
}
}); // before
after('drop collections, close connection', async () => {
try {
if (t_collections) {
await Promise.all(
t_collections.map(function(coll) {
return coll.drop();
})
);
}
await conn.close();
} catch(err) {
should.not.exist(err);
}
}); // after
it('167.1 get collection names', async () => {
try {
let cNames = await sd.getCollectionNames();
should.strictEqual(cNames.length, t_collectionNames.length);
should.deepEqual(cNames, t_collectionNames.sort());
} catch(err) {
should.not.exist(err);
}
});
it('167.2 getCollectionNames() - limit option', async () => {
try {
let options = { limit: 1 };
let cNames = await sd.getCollectionNames(options);
should.strictEqual(cNames.length, 1);
should.deepEqual(cNames, t_collectionNames.sort().slice(0, 1));
} catch(err) {
should.not.exist(err);
}
});
it('167.3 getCollectionNames() - limit is "undefined"', async () => {
try {
let options = { limit: undefined };
let cNames = await sd.getCollectionNames(options);
should.strictEqual(cNames.length, t_collectionNames.length);
should.deepEqual(cNames, t_collectionNames.sort());
} catch(err) {
should.not.exist(err);
}
});
it('167.4 getCollectionNames() - limit is 0', async () => {
try {
let options = { limit: 0 };
let cNames = await sd.getCollectionNames(options);
should.strictEqual(cNames.length, t_collectionNames.length);
should.deepEqual(cNames, t_collectionNames.sort());
} catch(err) {
should.not.exist(err);
}
});
it('167.5 getCollectionNames() - limit is null', async () => {
try {
let options = { limit: null };
let cNames = await sd.getCollectionNames(options);
should.strictEqual(cNames.length, t_collectionNames.length);
should.deepEqual(cNames, t_collectionNames.sort());
} catch(err) {
should.exist(err);
should.strictEqual(err.message, 'NJS-007: invalid value for "limit" in parameter 2');
}
});
it('167.6 getCollectionNames() - limit is an empty string', async () => {
try {
let options = { limit: '' };
let cNames = await sd.getCollectionNames(options);
should.strictEqual(cNames.length, t_collectionNames.length);
should.deepEqual(cNames, t_collectionNames.sort());
} catch(err) {
should.exist(err);
should.strictEqual(err.message, 'NJS-008: invalid type for "limit" in parameter 2');
}
});
it('167.7 getCollectionNames() - limit is a negative number', async () => {
try {
let options = { limit: -7 };
let cNames = await sd.getCollectionNames(options);
should.strictEqual(cNames.length, t_collectionNames.length);
should.deepEqual(cNames, t_collectionNames.sort());
} catch(err) {
should.not.exist(err);
}
});
it('167.8 starsWith option - basic test', async () => {
try {
let options = { startsWith: "changjie" };
let cNames = await sd.getCollectionNames(options);
should.deepEqual(cNames, t_collectionNames.sort().slice(2));
} catch(err) {
should.not.exist(err);
}
});
it('167.9 starsWith is case sensitive', async () => {
try {
let options = { startsWith: "Changjie" };
let cNames = await sd.getCollectionNames(options);
should.strictEqual(cNames.length, t_collectionNames.length);
should.deepEqual(cNames, t_collectionNames.sort());
} catch(err) {
should.not.exist(err);
}
});
it('167.10 starsWith is an empyt string', async () => {
try {
let options = { startsWith: "" };
let cNames = await sd.getCollectionNames(options);
should.strictEqual(cNames.length, t_collectionNames.length);
should.deepEqual(cNames, t_collectionNames.sort());
} catch(err) {
should.not.exist(err);
}
});
it('167.11 starsWith is null', async () => {
try {
let options = { startsWith: null };
let cNames = await sd.getCollectionNames(options);
should.strictEqual(cNames.length, t_collectionNames.length);
should.deepEqual(cNames, t_collectionNames.sort());
} catch(err) {
should.exist(err);
should.strictEqual(err.message, 'NJS-007: invalid value for "startsWith" in parameter 2');
}
});
it('167.12 Negative - starsWith is invalid type, a Number', async () => {
try {
let options = { startsWith: 7 };
let cNames = await sd.getCollectionNames(options);
should.strictEqual(cNames.length, t_collectionNames.length);
should.deepEqual(cNames, t_collectionNames.sort());
} catch(err) {
should.exist(err);
should.strictEqual(err.message, 'NJS-008: invalid type for "startsWith" in parameter 2');
}
});
it('167.13 openCollection() basic case 1', async () => {
try {
let candidate = "Changjie_3";
let coll = await sd.openCollection(candidate);
should.strictEqual(coll.name, candidate);
} catch(err) {
should.not.exist(err);
}
});
it('167.14 openCollection() basic case 2', async () => {
try {
let candidate = "chris_1";
let coll = await sd.openCollection(candidate);
should.strictEqual(coll.name, candidate);
} catch(err) {
should.not.exist(err);
}
});
it('167.15 the returned value is null if the requested collection does not exist', async () => {
try {
let candidate = "nonexistent_collection";
let coll = await sd.openCollection(candidate);
should.strictEqual(coll, undefined);
} catch(err) {
should.not.exist(err);
}
});
it('167.16 the requested collection name is case sensitive', async () => {
try {
let candidate = "changjie_3";
let coll = await sd.openCollection(candidate);
should.strictEqual(coll, undefined);
} catch(err) {
should.not.exist(err);
}
});
});

176
test/soda4.js Normal file
View File

@ -0,0 +1,176 @@
/* Copyright (c) 2018, 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
* 168. soda4.js
*
* DESCRIPTION
* sodaDocument class
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const should = require('should');
const dbconfig = require('./dbconfig.js');
const sodaUtil = require('./sodaUtil.js');
describe('168. soda4.js', () => {
before(async function() {
const runnable = await sodaUtil.checkPrerequisites();
if (!runnable) this.skip();
await sodaUtil.cleanup();
});
it.skip('168.1 insertOneAndGet() method', async () => {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let collectionName = 'soda_test_168_1';
let coll = await sd.createCollection(collectionName);
// Insert a new document
let testContent = {
name: "Changjie Lin",
address: {city: "Shenzhen", country: "China"},
company: "Oracle Corporation",
manager: null,
VP: "Bruce"
};
let myDoc = await coll.insertOneAndGet(testContent);
let myKey = myDoc.key;
should.exist(myKey);
(myKey).should.be.a.String();
(myDoc).should.be.an.Object();
let content1 = myDoc.getContent();
console.log("getContent()");
console.log(content1);
// Fetch it back
let doc2 = await coll.find().key(myKey).getOne();
let content2 = doc2.getContent();
should.strictEqual(content2.name, testContent.name);
should.strictEqual(content2.company, testContent.company);
should.strictEqual(content2.manager, null);
await conn.commit();
let res = await coll.drop();
should.strictEqual(res.dropped, true);
} catch(err) {
should.not.exist(err);
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 168.1
// ORA-40665: A client-assigned key cannot be used for this operation.
it.skip('168.2 customize the key value', async () => {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let collectionName = 'soda_test_168_2';
let coll = await sd.createCollection(collectionName);
// Insert a new document
let testContent = {
name: "Shelly",
address: {city: "Shenzhen", country: "China"}
};
let testKey = "86755";
let testDoc = await sd.createDocument(testContent, { key: testKey} );
should.exist(testDoc);
console.log(testDoc);
await coll.insertOne(testDoc);
// Fetch it back
let doc2 = await coll.find().key(testKey).getOne();
let content2 = doc2.getContent();
console.log(content2);
await conn.commit();
let res = await coll.drop();
should.strictEqual(res.dropped, true);
} catch(err) {
should.not.exist(err);
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 168.2
it('168.3 content is null', async () => {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let collectionName = 'soda_test_168_3';
let coll = await sd.createCollection(collectionName);
// Insert a new document
let testContent = {};
let myDoc = await coll.insertOneAndGet(testContent);
let myKey = myDoc.key;
should.exist(myKey);
(myKey).should.be.a.String();
(myDoc).should.be.an.Object();
// Fetch it back
let doc2 = await coll.find().key(myKey).getOne();
let content2 = doc2.getContent();
should.deepEqual(content2, testContent);
await conn.commit();
let res = await coll.drop();
should.strictEqual(res.dropped, true);
} catch(err) {
should.not.exist(err);
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
should.not.exist(err);
}
}
}
}); // 168.3
});

361
test/sodaCallback.js Normal file
View File

@ -0,0 +1,361 @@
/* Copyright (c) 2018, 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
* 166. sodaCallback.js
*
* DESCRIPTION
* SODA tests in calback format.
*
*****************************************************************************/
'use strict';
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbconfig = require('./dbconfig.js');
describe('166. sodaCallback.js', function() {
var isRunnable;
before(function(done) {
var conn, soda, collNames;
function checkRunnable(cb) {
var clientRunnable, serverRunnable;
if (oracledb.oracleClientVersion < 1803000000) {
clientRunnable = false;
} else {
clientRunnable = true;
}
oracledb.getConnection(dbconfig, function(err, connection) {
if (err) cb(err);
if (connection.oracleServerVersion < 1803000000) {
serverRunnable = false;
} else {
serverRunnable = true;
}
if (clientRunnable && serverRunnable) {
isRunnable = true;
} else {
isRunnable = false;
}
connection.close(function(err) {
if (err) cb(err);
cb(null);
});
});
} // checkRunnable()
checkRunnable(function(err) {
should.not.exist(err);
if (!isRunnable) {
done();
} else {
async.series([
function(cb) {
oracledb.getConnection(dbconfig, function(err, connection) {
should.not.exist(err);
conn = connection;
cb();
});
},
function(cb) {
soda = conn.getSodaDatabase();
should.exist(soda);
cb();
},
function(cb) {
soda.getCollectionNames(function(err, names) {
should.not.exist(err);
collNames = names;
cb();
});
},
function(cb) {
if (collNames.length == 0) {
cb();
} else {
console.log("existing collections: ");
console.log(collNames);
cleanupCollections(collNames, cb);
}
},
function(cb) {
conn.close(function(err) {
should.not.exist(err);
cb();
});
}
], done);
}
});
//if (!runnable) this.skip();
function cleanupCollections(names, callback) {
async.forEach(names, function(item, cb) {
should.exist(soda);
soda.openCollection(item, function(err, collection) {
should.not.exist(err);
collection.drop(function(err, res) {
should.not.exist(err);
if (res.dropped) {
console.log("Succeed to drop collection", item);
} else {
console.log("Fail to drop collection", item);
}
cb();
});
});
}, function(err) {
should.not.exist(err);
callback();
});
} // cleanupCollection()
}); // before();
it('166.1 create a collection, then drop it', function(done) {
if (!isRunnable) {
done();
} else {
var conn, soda, coll;
var t_collName = "soda_test_166_1";
async.series([
function(cb) {
oracledb.getConnection(
dbconfig,
function(err, connection) {
should.not.exist(err);
conn = connection;
cb();
}
);
},
function(cb) {
soda = conn.getSodaDatabase();
should.exist(soda);
cb();
},
function(cb) {
soda.createCollection(t_collName, function(err, collection) {
should.not.exist(err);
coll = collection;
cb();
});
},
function(cb) {
soda.getCollectionNames(function(err, collNames) {
should.not.exist(err);
should.strictEqual(collNames[0], t_collName);
cb();
});
},
function(cb) {
soda.openCollection(t_collName, function(err, collection) {
should.not.exist(err);
coll = collection;
cb();
});
},
function(cb) {
coll.drop(function(err) {
should.not.exist(err);
cb();
});
},
function(cb) {
conn.close(function(err) {
should.not.exist(err);
cb();
});
}
], done);
}
}); // 166.1
it('166.2 the callback version of "examples/soda1.js" case', function(done) {
if (!isRunnable) {
done();
} else {
var conn, soda, coll;
var myKey;
var t_content1 = { name: "Matilda", address: {city: "Melbourne"} };
async.series([
function(cb) {
oracledb.getConnection(
dbconfig,
function(err, connection) {
should.not.exist(err);
conn = connection;
cb();
}
);
},
function(cb) {
soda = conn.getSodaDatabase();
should.exist(soda);
cb();
},
function(cb) { // Create a new SODA collection
var t_collName = "soda_test_166_2";
soda.createCollection(t_collName, function(err, collection) {
should.not.exist(err);
coll = collection;
cb();
});
},
function(cb) { // Create a index
var indexSpec = {
"name": "CITY_IDX",
"fields": [
{
"path": "address.city",
"datatype": "string",
"order": "asc"
}
]
};
coll.createIndex(indexSpec, function(err) {
should.not.exist(err);
cb();
});
},
function(cb) { // Insert a document
coll.insertOneAndGet(t_content1, function(err, doc) {
should.not.exist(err);
myKey = doc.key;
should.exist(myKey);
(myKey).should.be.a.String();
cb();
});
},
function(cb) { // Fetch the document back
coll.find().key(myKey).getOne(function(err, document) {
should.not.exist(err);
var content = document.getContent();
should.deepEqual(content, t_content1);
var contentStr = document.getContentAsString();
(contentStr).should.be.a.String();
should.strictEqual( JSON.stringify(content), contentStr );
cb();
});
},
function(cb) { // Replace documet content
var content = { name: "Matilda", address: {city: "Sydney"} };
coll.find().key(myKey).replaceOne(content, function(err) {
should.not.exist(err);
cb();
});
},
// Insert some more documents without caring about their keys
function(cb) {
var content = { name: "Venkat", address: {city: "Bengaluru"} };
coll.insertOne(content, function(err) {
should.not.exist(err);
cb();
});
},
function(cb) {
var content = { name: "May", address: {city: "London"} };
coll.insertOne(content, function(err) {
should.not.exist(err);
cb();
});
},
function(cb) {
var content = { name: "Sally-Ann", address: {city: "San Francisco"} };
coll.insertOne(content, function(err) {
should.not.exist(err);
cb();
});
},
// Find all documents with city names starting with 'S'
function(cb) {
coll.find()
.filter({"address.city": {"$like": "S%"}})
.getDocuments(function(err, documents) {
should.not.exist(err);
for (let i = 0; i < documents.length; i++) {
let content = documents[i].getContent();
(['Sydney', 'San Francisco']).should.containEql(content.address.city);
}
cb();
});
},
function(cb) { // Count all documents
coll.find().count(function(err, result) {
should.not.exist(err);
should.strictEqual(result.count, 4);
cb();
});
},
function(cb) { // Remove documents with cities containing 'o'
coll.find().filter({"address.city": {"$regex": ".*o.*"}})
.remove(function(err, result) {
should.not.exist(err);
should.strictEqual(result.count, 2);
cb();
});
},
function(cb) { // Count all documents
coll.find().count(function(err, result) {
should.not.exist(err);
should.strictEqual(result.count, 2);
cb();
});
},
function(cb) { // Commit changes
conn.commit(function(err) {
should.not.exist(err);
cb();
});
},
function(cb) { // Drop the collection
coll.drop(function(err) {
should.not.exist(err);
cb();
});
},
function(cb) {
conn.close(function(err) {
should.not.exist(err);
cb();
});
}
], done);
}
}); // 166.2
});

86
test/sodaUtil.js Normal file
View File

@ -0,0 +1,86 @@
/* Copyright (c) 2018, 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
* sodaUtil.js
*
* DESCRIPTION
* The utility functions of SODA tests.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const dbconfig = require('./dbconfig.js');
let sodaUtil = exports;
module.exports = sodaUtil;
sodaUtil.cleanup = async function() {
let conn;
try {
conn = await oracledb.getConnection(dbconfig);
let sd = conn.getSodaDatabase();
let cNames = await sd.getCollectionNames();
if (cNames.length > 0) {
console.log("existing collections: ");
console.log(cNames);
for (let i = 0; i < cNames.length; i++) {
let coll = await sd.openCollection(cNames[i]);
let res = await coll.drop();
if (res.dropped) {
console.log("Succeed to drop collection", cNames[i]);
} else {
console.log("Fail to drop collection", cNames[i]);
}
}
}
} catch(err) {
console.log('Error in processing:\n', err);
} finally {
if (conn) {
try {
await conn.close();
} catch(err) {
console.log('Error in closing connection:\n', err);
}
}
}
}; // cleanup()
sodaUtil.checkPrerequisites = async function() {
if (oracledb.oracleClientVersion < 1803000000) return false;
try {
let connection = await oracledb.getConnection(dbconfig);
if (connection.oracleServerVersion < 1803000000) return false;
await connection.close();
return true;
} catch(err) {
console.log('Error in checking prerequistes:\n', err);
}
};