I have a function called userLogin()
that takes the input (username and password) of a login page as parameters and returns the string representation of a Json object that contains the details of the user who is trying to login.
My Function:
public String userLogin(String strUser, String strPswrd) throws Exception
{
String strResult = null;
String strUserlevel = null;
String strDate = null;
String strId = null;
int nUserID = 0;
int nParam = 0;
StringBuilder sbSql = null;
JSONObject oJson = null;
ResultSet oRs = null;
Root oRoot = null;
PreparedStatement oPrStmt = null;
try{
oRoot = Root.createDbConnection(null);
oJson = new JSONObject();
sbSql = new StringBuilder("SELECT * FROM members WHERE username =? AND Password = ? AND deleteflag =0 ");
oPrStmt = oRoot.con.prepareStatement(sbSql.toString());
nParam =0;
oPrStmt.setString(++nParam, strUser);
oPrStmt.setString(++nParam, strPswrd);
oRs =oPrStmt.executeQuery();
if(oRs.next()){
nUserID = oRs.getInt("userlevel");
strUserlevel = oRs.getString("users");
strDate = oRs.getString("lastlogin");
strId = oRs.getString("id");
strUser = strUser.substring(0, 1).toUpperCase() + strUser.substring(1);
oJson.put("status", "success");
oJson.put("ID", strId);
oJson.put("userID", nUserID);
oJson.put("userlevel", strUserlevel);
oJson.put("lastlogin", strDate);
oJson.put("username", strUser);
}
strResult = oJson.toString();
}
catch(Exception ex){
ex.printStackTrace();
}
return strResult;
}
Currently, I have installed the groovy-eclipse plugin from the Groovy/Grails Tool suite.I have watched some Youtube video's and read some tutorials on how to write groovy test cases but don't know how to implement it for my function.Can someone help me as I am new to using this tool .