I am working on a project that is using an Oracle database with stored procedures. I am unit testing with junit.
What I’d like to do is use an embedded database to emulate the Oracle database. However the application is using calls to stored procedures. The stored procedure takes in two variables and outs 15.
It would be simple to emulate a this stored procedure with a simple query to a table full of test data.
What embedded databases are available that can be used to emulate this functionality?
web_services.search_registrants(
cert_nbr_in => :cert_nbr_in,
last_4_ssn_in => :last_4_ssn_in,
status_out => :status_out,
cert_nbr_out => :cert_nbr_out,
last_4_ssn_out => :last_4_ssn_out,
last_name_out => :last_name_out,
first_name_out => :first_name_out,
mid_name_out => :mid_name_out,
email_addr_out => :email_addr_out,
st_address1_out => :st_address1_out,
st_address2_out => :st_address2_out,
city_out => :city_out,
state_out => :state_out,
zip_code_out => :zip_code_out,
home_phone_out => :home_phone_out,
work_phone_out => :work_phone_out,
cell_phone_out => :cell_phone_out);
This is the java code, which works fine against Oracle.
public Applicant find(String certNumber, String last4Ssn) {
Connection conn = null;
CallableStatement cs = null;
Applicant applicant = null;
try {
try {
conn = this.getConnection();
cs = conn.prepareCall(
"{call NARS.web_services.search_registrants(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}") ;
cs.setString("CERT_NBR_IN", certNumber);
cs.setString("LAST_4_SSN_IN", last4Ssn);
cs.registerOutParameter("STATUS_OUT", Types.VARCHAR);
cs.registerOutParameter("CERT_NBR_OUT", Types.VARCHAR);
cs.registerOutParameter("LAST_4_SSN_OUT", Types.VARCHAR);
cs.registerOutParameter("LAST_NAME_OUT", Types.VARCHAR);
cs.registerOutParameter("FIRST_NAME_OUT", Types.VARCHAR);
cs.registerOutParameter("MID_NAME_OUT", Types.VARCHAR);
cs.registerOutParameter("EMAIL_ADDR_OUT", Types.VARCHAR);
cs.registerOutParameter("ST_ADDRESS1_OUT", Types.VARCHAR);
cs.registerOutParameter("ST_ADDRESS2_OUT", Types.VARCHAR);
cs.registerOutParameter("CITY_OUT", Types.VARCHAR);
cs.registerOutParameter("STATE_OUT", Types.VARCHAR);
cs.registerOutParameter("ZIP_CODE_OUT", Types.VARCHAR);
cs.registerOutParameter("HOME_PHONE_OUT", Types.VARCHAR);
cs.registerOutParameter("WORK_PHONE_OUT", Types.VARCHAR);
cs.registerOutParameter("CELL_PHONE_OUT", Types.VARCHAR);
cs.execute();
// 3 STATUS_OUT OUT VARCHAR2 -- 0 = found,
// 1 = not found, 2 = expired certification, 3 = abuse
String status = cs.getString("STATUS_OUT");
System.out.println("status is: " + status);
if(!status.equals("1")){
System.out.println("certNumber " + cs.getString("CERT_NBR_OUT"));
// Create new Applicant
applicant = new Applicant(certNumber, last4Ssn);
// 4 CERT_NBR_OUT OUT VARCHAR2 -- 2 expired certification
if(status.equals("2")){
applicant.setExpired(true);
}
if(status.equals("3")){
applicant.setAbuse(true);
}
applicant.setLastName(cs.getString("LAST_NAME_OUT"));
applicant.setFirstName(cs.getString("FIRST_NAME_OUT"));
applicant.setMidInit(cs.getString("MID_NAME_OUT"));
applicant.setEmailAddress(cs.getString("EMAIL_ADDR_OUT"));
applicant.setAddressLine1(cs.getString("ST_ADDRESS1_OUT"));
applicant.setAddressLine2(cs.getString("ST_ADDRESS2_OUT"));
applicant.setCity(cs.getString("CITY_OUT"));
applicant.setState(cs.getString("STATE_OUT"));
applicant.setZipCode(cs.getString("ZIP_CODE_OUT"));
applicant.setHomePhone(cs.getString("HOME_PHONE_OUT"));
applicant.setWorkPhone(cs.getString("WORK_PHONE_OUT"));
applicant.setCellPhone(cs.getString("CELL_PHONE_OUT"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if(cs != null) cs.close();
if(conn != null) conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
return applicant;
}
I solved this problem by using HSQLDB. I was able to write a stored procedures that return out variables. It’s really cool. Here is an example of my HSQLDB setup script.
And that’s it! So of course I set the database to my HSQLDB and tested against that.