Update of /cvsroot/appsunit/project/src/net/sourceforge/appsunit/environment
In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv32319/src/net/sourceforge/appsunit/environment
Added Files:
DbSession.java AppsSession.java
Log Message:
Initial helper classes will provide the environment that allows to execute tests.
--- NEW FILE: AppsSession.java ---
/*
* AppsSession.java
*
* $Id: AppsSession.java,v 1.1 2006/09/11 20:32:52 jancumps Exp $
* $Revision: 1.1 $
* $Date: 2006/09/11 20:32:52 $
*
* Created on 11 september 2006, 22:00
*
*/
package net.sourceforge.appsunit.environment;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
/**
* Utility class creates an Apps session environment.
*/
public class AppsSession {
/** Creates a new instance of AppsSession */
public AppsSession() {
}
/**
* Log on to the erp system with a given user and responsibility.
* @param application The short name of the module we're logging on to.
* @param connection Database connection.
* @param user Apps user name to log on.
* @param responsibility Apps responsibility to log on.
* @throws java.lang.Exception Exceptions are not caught. They will be passed to the caller.
* @TODO replace literal value insertion by parameter binding.
*/
public static void logon(Connection connection, String user, String responsibility, String application) throws Exception {
ResultSet rs = null;
PreparedStatement stmt = null;
String usr = null;
stmt = connection.prepareStatement(
"select user_id " +
"from fnd_user " +
"where user_name = '" +
user + "'");
rs = stmt.executeQuery(); // execute
if (rs.next()) {
usr = rs.getString(1); // retrieve map_id
}
rs.close();
TestCase.assertNotNull("user " + user + " not found", usr);
// TODO: lookup responsibility
String rsp = null;
stmt = connection.prepareStatement(
"select responsibility_id " +
"from fnd_responsibility " +
"where responsibility_key = '" +
responsibility + "'");
rs = stmt.executeQuery(); // execute
if (rs.next()) {
rsp = rs.getString(1); // retrieve responsibility_id
}
rs.close();
if (rsp == null ) {
throw new Exception("Responsibility " + responsibility + " not found.");
}
String appl = null;
stmt = parent.getConn().prepareStatement(
"select application_id from fnd_application where application_short_name = '" +
application + "'");
rs = stmt.executeQuery(); // execute
if (rs.next()) {
appl = rs.getString(1); // retrieve application_id
}
rs.close();
if (appl == null) {
throw new Exception("Application " + application + " not found.");
}
// call the fnd_global api to log on to the apps
CallableStatement cstmt = null;
cstmt = connection.prepareCall(
"{ call apps.fnd_global.apps_initialize(" +
"user_id => " + usr +
", resp_id => " + rsp +
", resp_appl_id => " + appl +
", security_group_id => null)}");
try {
// the first call somethimes fails. That's why it's retried in the catch block;
rs = cstmt.executeQuery(); // execute
rs.close();
} catch (Exception e) {
rs = cstmt.executeQuery(); // execute
rs.close();
}
}
--- NEW FILE: DbSession.java ---
/*
* DbSession.java
*
* $Id: DbSession.java,v 1.1 2006/09/11 20:32:52 jancumps Exp $
* $Revision: 1.1 $
* $Date: 2006/09/11 20:32:52 $
*
* Created on 11 september 2006, 21:59
*/
package net.sourceforge.appsunit.environment;
/**
*
* @author JCUMPS
*/
public class DbSession {
/**
* Creates a new instance of DbSession
*/
public DbSession() {
}
}
|