Skip to content

Commit

Permalink
deps up, and test work
Browse files Browse the repository at this point in the history
  • Loading branch information
CraZySacX committed Aug 19, 2015
1 parent 38753f1 commit 6cde671
Show file tree
Hide file tree
Showing 8 changed files with 320 additions and 116 deletions.
3 changes: 2 additions & 1 deletion bin/startdbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
java -cp drivers\/hsqldb.jar org.hsqldb.server.Server --database.0 file:test\/mydb --dbname.0 xdb >test\/hsqldb.log 2>&1 &
java -Dderby.system.home=test -classpath drivers\/derby.jar:drivers\/derbynet.jar:drivers\/derbytools.jar -jar drivers\/derbyrun.jar server start >test\/derby.log 2>&1 &
java -Dderby.system.home=./test -classpath drivers\/derby.jar:drivers\/derbynet.jar:drivers\/derbytools.jar -jar drivers\/derbyrun.jar server start >test\/derby.log 2>&1 &
sleep 10
1 change: 1 addition & 0 deletions bin/stopdbs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/bash
java -classpath drivers/derby.jar:drivers/derbytools.jar:drivers/derbynet.jar -jar drivers/derbyrun.jar server shutdown >test\/derby.log 2>&1 &
rm -rf test/testdb
11 changes: 7 additions & 4 deletions lib/jdbc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ JDBCConn.prototype.initialize = function(config, callback) {
var self = this;
self._config = config;

if (self._config.properties){
var Properties = java.import('java.util.Properties');
var properties = new Properties();

var Properties = java.import('java.util.Properties');
var properties = new Properties();

if (self._config.properties) {
self._config.properties.forEach(function(prop){
properties.putSync(prop[0], prop[1]);
});
this._props = properties;
}

this._props = properties;

if (self._config.user){
if(this._props.getPropertySync('user') === undefined){
this._props.putSync('user', self._config.user);
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"description": "Node Module JDBC wrapper",
"main": "index.js",
"dependencies": {
"java": "~0.4.4",
"underscore": "~1.7.0",
"promise": "~6.0.1"
"java": "~0.5",
"underscore": "~1.8",
"promise": "~7.0"
},
"devDependencies": {
"nodeunit": "~0.9.0"
"nodeunit": "~0.9"
},
"scripts": {
"pretest": "bin\/startdbs",
Expand Down
84 changes: 83 additions & 1 deletion test/test-derby.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jinst.setupClasspath(['./drivers/hsqldb.jar',

var config = {
drivername: 'org.apache.derby.jdbc.ClientDriver',
url: 'jdbc:derby://localhost:1527/testdb'
url: 'jdbc:derby://localhost:1527/testdb;create=true'
};

module.exports = {
Expand All @@ -20,5 +20,87 @@ module.exports = {
test.equal(drivername, 'org.apache.derby.jdbc.ClientDriver');
test.done();
});
},
testopen: function(test) {
derbyConn.open(function(err, conn) {
test.expect(2);
test.equal(null, err);
test.ok(conn);
test.done();
});
},
testcreatetable: function(test) {
derbyConn.executeUpdate("CREATE TABLE blah (id int, name varchar(10), date DATE, time TIME, timestamp TIMESTAMP)", function(err, result) {
test.expect(1);
test.equal(null, err);
test.done();
});
},
// testeqinsert: function(test) {
// derbyConn.executeQuery("INSERT INTO blah VALUES (1, 'Jason', CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP);", function(err, result) {
// test.expect(2);
// test.equal(null, err);
// test.ok(result);
// test.done();
// });
// },
// testeuinsert: function(test) {
// derbyConn.executeUpdate("INSERT INTO blah VALUES (3, 'Temp', CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP);", function(err, result) {
// test.expect(2);
// test.equal(null, err);
// test.ok(result && result == 1);
// test.done();
// });
// },
// testequpdate: function(test) {
// derbyConn.executeQuery("UPDATE blah SET id = 2 WHERE name = 'Jason';", function(err, result) {
// test.expect(2);
// test.equal(null, err);
// test.ok(result);
// test.done();
// });
// },
// testeuupdate: function(test) {
// derbyConn.executeUpdate("UPDATE blah SET id = 4 WHERE name = 'Temp';", function(err, result) {
// test.expect(2);
// test.equal(null, err);
// test.ok(result && result == 1);
// test.done();
// });
// },
// testselect: function(test) {
// derbyConn.executeQuery("SELECT * FROM blah;", function(err, result) {
// test.expect(6);
// test.equal(null, err);
// test.ok(result && result.length == 2);
// test.equal(result[0].NAME, 'Jason');
// test.ok(result[0].DATE);
// test.ok(result[0].TIME);
// test.ok(result[0].TIMESTAMP);
// test.done();
// });
// },
// testeqdelete: function(test) {
// derbyConn.executeQuery("DELETE FROM blah WHERE id = 2;", function(err, result) {
// test.expect(2);
// test.equal(null, err);
// test.ok(result);
// test.done();
// });
// },
// testeudelete: function(test) {
// derbyConn.executeUpdate("DELETE FROM blah WHERE id = 4;", function(err, result) {
// test.expect(2);
// test.equal(null, err);
// test.ok(result && result == 1);
// test.done();
// });
// },
testdroptable: function(test) {
derbyConn.executeUpdate("DROP TABLE blah", function(err, result) {
test.expect(1);
test.equal(null, err);
test.done();
});
}
};
109 changes: 3 additions & 106 deletions test/test-hsqldb.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,22 @@
var jinst = require('../lib/jinst.js');
var nodeunit = require('nodeunit');
var jdbcConn = new ( require('../lib/jdbc.js') ),
jdbcConnWithProps = new ( require('../lib/jdbc.js') );
var jdbcConn = new ( require('../lib/jdbc.js') );

jinst.setupClasspath(['./drivers/hsqldb.jar',
'./drivers/derby.jar',
'./drivers/derbyclient.jar',
'./drivers/derbytools.jar']);

var configWithUserInUrl = {
drivername: 'org.hsqldb.jdbc.JDBCDriver',
url: 'jdbc:hsqldb:hsql://localhost/xdb;user=SA;password='
};

var configWithUserInConfig = {
var config = {
drivername: 'org.hsqldb.jdbc.JDBCDriver',
url: 'jdbc:hsqldb:hsql://localhost/xdb',
user : 'SA',
password: ''
};

var configWithPropertiesInConfig = {
drivername: 'org.hsqldb.jdbc.JDBCDriver',
url: 'jdbc:hsqldb:hsql://localhost/xdb',
properties: [
['user', 'SA'],
['password','']
]
};

module.exports = {
testinit: function(test) {
jdbcConn.initialize(configWithUserInUrl, function(err, drivername) {
test.expect(2);
test.equal(null, err);
test.equal(drivername, 'org.hsqldb.jdbc.JDBCDriver');
test.done();
});
},
testinitwithproperties: function(test) {
jdbcConnWithProps.initialize(configWithPropertiesInConfig, function(err, drivername) {
jdbcConn.initialize(config, function(err, drivername) {
test.expect(2);
test.equal(null, err);
test.equal(drivername, 'org.hsqldb.jdbc.JDBCDriver');
Expand All @@ -54,14 +31,6 @@ module.exports = {
test.done();
});
},
testopenwithproperties: function(test) {
jdbcConnWithProps.open(function(err, conn) {
test.expect(2);
test.equal(null, err);
test.ok(conn);
test.done();
});
},
testcreatetable: function(test) {
jdbcConn.executeQuery("CREATE TABLE blah (id int, name varchar(10), date DATE, time TIME, timestamp TIMESTAMP);", function(err, result) {
test.expect(2);
Expand All @@ -70,14 +39,6 @@ module.exports = {
test.done();
});
},
testcreatetablewithproperties: function(test) {
jdbcConnWithProps.executeQuery("CREATE TABLE blahP (id int, name varchar(10), date DATE, time TIME, timestamp TIMESTAMP);", function(err, result) {
test.expect(2);
test.equal(null, err);
test.ok(result);
test.done();
});
},
testeqinsert: function(test) {
jdbcConn.executeQuery("INSERT INTO blah VALUES (1, 'Jason', CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP);", function(err, result) {
test.expect(2);
Expand All @@ -86,14 +47,6 @@ module.exports = {
test.done();
});
},
testeqinsertwithproperties: function(test) {
jdbcConnWithProps.executeQuery("INSERT INTO blahP VALUES (1, 'Jason', CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP);", function(err, result) {
test.expect(2);
test.equal(null, err);
test.ok(result);
test.done();
});
},
testeuinsert: function(test) {
jdbcConn.executeUpdate("INSERT INTO blah VALUES (3, 'Temp', CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP);", function(err, result) {
test.expect(2);
Expand All @@ -102,14 +55,6 @@ module.exports = {
test.done();
});
},
testeuinsertwithproperties: function(test) {
jdbcConnWithProps.executeUpdate("INSERT INTO blahP VALUES (3, 'Temp', CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP);", function(err, result) {
test.expect(2);
test.equal(null, err);
test.ok(result && result == 1);
test.done();
});
},
testequpdate: function(test) {
jdbcConn.executeQuery("UPDATE blah SET id = 2 WHERE name = 'Jason';", function(err, result) {
test.expect(2);
Expand All @@ -118,14 +63,6 @@ module.exports = {
test.done();
});
},
testequpdatewithproperties: function(test) {
jdbcConnWithProps.executeQuery("UPDATE blahP SET id = 2 WHERE name = 'Jason';", function(err, result) {
test.expect(2);
test.equal(null, err);
test.ok(result);
test.done();
});
},
testeuupdate: function(test) {
jdbcConn.executeUpdate("UPDATE blah SET id = 4 WHERE name = 'Temp';", function(err, result) {
test.expect(2);
Expand All @@ -134,14 +71,6 @@ module.exports = {
test.done();
});
},
testeuupdatewithproperties: function(test) {
jdbcConnWithProps.executeUpdate("UPDATE blahP SET id = 4 WHERE name = 'Temp';", function(err, result) {
test.expect(2);
test.equal(null, err);
test.ok(result && result == 1);
test.done();
});
},
testselect: function(test) {
jdbcConn.executeQuery("SELECT * FROM blah;", function(err, result) {
test.expect(6);
Expand All @@ -154,14 +83,6 @@ module.exports = {
test.done();
});
},
testselectwithproperties: function(test) {
jdbcConnWithProps.executeQuery("SELECT * FROM blahP;", function(err, result) {
test.expect(2);
test.equal(null, err);
test.ok(result && result.length == 2);
test.done();
});
},
testeqdelete: function(test) {
jdbcConn.executeQuery("DELETE FROM blah WHERE id = 2;", function(err, result) {
test.expect(2);
Expand All @@ -170,14 +91,6 @@ module.exports = {
test.done();
});
},
testeqdeletewithproperties: function(test) {
jdbcConnWithProps.executeQuery("DELETE FROM blahP WHERE id = 2;", function(err, result) {
test.expect(2);
test.equal(null, err);
test.ok(result);
test.done();
});
},
testeudelete: function(test) {
jdbcConn.executeUpdate("DELETE FROM blah WHERE id = 4;", function(err, result) {
test.expect(2);
Expand All @@ -186,28 +99,12 @@ module.exports = {
test.done();
});
},
testeudeletewithproperties: function(test) {
jdbcConnWithProps.executeUpdate("DELETE FROM blahP WHERE id = 4;", function(err, result) {
test.expect(2);
test.equal(null, err);
test.ok(result && result == 1);
test.done();
});
},
testdroptable: function(test) {
jdbcConn.executeQuery("DROP TABLE blah;", function(err, result) {
test.expect(2);
test.equal(null, err);
test.ok(result);
test.done();
});
},
testdroptablewithproperties: function(test) {
jdbcConnWithProps.executeQuery("DROP TABLE blahP;", function(err, result) {
test.expect(2);
test.equal(null, err);
test.ok(result);
test.done();
});
}
};
Loading

0 comments on commit 6cde671

Please sign in to comment.