dcsimg
how to write test case for following code
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   deepika_bagadiya
Posted On:   Saturday, August 3, 2002 05:31 AM

Please tell me what test case I must write for this code using junit package Gic; import java.sql.*; import java.awt.*; public class AddState extends javax.swing.JDialog { /*This constructor is called when parent is JFrame */ public AddState(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); addComponents(); addListeners(); setSize(200,120); b = true; } /*This constructor is called when parent is Dialog */ public AddState(java.awt.Dialog parent, boolean modal, init id_State) super(parent, modal); m_objEditState = (EditState) parent; initComponents();    More>>

Please tell me what test case I must write for this code using junit


package Gic;

import java.sql.*;
import java.awt.*;


public class AddState extends javax.swing.JDialog {
/*This constructor is called when parent is JFrame */
public AddState(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
addComponents();
addListeners();
setSize(200,120);
b = true;
}

/*This constructor is called when parent is Dialog */
public AddState(java.awt.Dialog parent, boolean modal,
init id_State)
super(parent, modal);
m_objEditState = (EditState) parent;
initComponents();
addComponents();
addListeners();
setSize(200,120);
b = false;

id = id_State;
/*This block of code get the value of selected state
in parent form from database and set the StateText
field by that value*/
try{
Statement stment = conn.createStatement();
ResultSet rst;
/* this function is called from database class to
perform Select query on database*/
rst = stment.executeQuery("Select State from
State Where State_Id = '"+ id +"' ");
while(rst.next()){
m_txtStateName.setText(
(String)rst.getString("State"));
}
rst.close();
conn.close();
}
catch(SQLException e) {
System.out.println("An error 11 occured
" +
"The SQLException message is: " + e.toString());
}
};
/*This function initialize all components*/
private void initComponents() {
m_lblStateName = new javax.swing.JLabel();
m_lblStateName.setFont(new java.awt.Font("Dialog",
0, 12));
m_lblStateName.setText("State Name");

m_txtStateName = new javax.swing.JTextField();

m_btnOk = new javax.swing.JButton();
m_btnOk.setFont(new java.awt.Font("Dialog", 0, 12));
m_btnOk.setText("Ok");

m_btnCancel = new javax.swing.JButton();
m_btnCancel.setFont(new java.awt.Font("Dialog", 0,
12));
m_btnCancel.setText("Cancel");

setTitle("Add State");
setResizable(false);
pack();
}

/*This function add various component to content pane
and Sets null layout*/
private void addComponents() {
Container content = getContentPane();
content.setLayout( null );

content.add(m_btnCancel);
m_btnCancel.setBounds(100, 60, 75, 25);

content.add( m_btnOk);
m_btnOk.setBounds(20, 60, 75, 25);

content.add(m_lblStateName);
m_lblStateName.setBounds(10, 20, 100, 20);

content.add(m_txtStateName);
m_txtStateName.setBounds(90, 20, 100, 20);
}

/*This function add window listener and Action
listener*/
private void addListeners() {

addWindowListener(new
java.awt.event.WindowAdapter() {
public void windowClosing
(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});

m_btnOk.addActionListener(new
java.awt.event.ActionListener() {
public void
actionPerformed(java.awt.event.ActionEvent evt) {
m_btnOkActionPerformed(evt);
}
});

m_btnCancel.addActionListener(new
java.awt.event.ActionListener() {
public void
actionPerformed(java.awt.event.ActionEvent evt) {
m_btnCancelActionPerformed(evt);
}
});

}

/*On Clicking ok button this form accepts state name
from user and checks the value of b.
If b is true then it inserts the value of state
in database and if b is false then it udate the state
value in database*/
private void m_btnOkActionPerformed
(java.awt.event.ActionEvent evt) {
String state = m_txtStateName.getText();
if(b == true){
try{
m_objdbConn = new DatabaseConnection();
String s = "Select StateId from Config";
ResultSet rst = m_objdbConn.GetResultSet(s);
if(rst.isBeforeFirst()) {
rst.next();
}
int id = rst.getInt("StateId");
rst.close();
s = "Update Config Set StateId = StateId + 1";
/* this function is called from database class to
perform update query on database*/
m_objdbConn.ExecuteQuery(s);
s = "Insert Into State (State_Id,State) values ('"+
id +"','" + state + "')";
/* this function is called from database class to
perform insert query on database*/
m_objdbConn.ExecuteQuery(s);
}

catch (SQLException e) {
System.out.println("An error 11 occurbed
" +
"The SQLException message is: " + e.toString());
}
}

if(b == false){
m_objdbConn = new DatabaseConnection();
String s = " Update State Set State = '" + state +
"' Where State_Id = '" + id + "' " ;
/* this function is called from database class to
perform update query on database*/
m_objdbConn.ExecuteQuery(s);
/* this function is called from EditState class to
update table display in that class*/
m_objEditState.editTable(state);
}
/* then the form unloads*/
try{
this.dispose();
this.finalize();
}

catch(Throwable t)
{
String Str = "Error during form unload";
}

}

/*On clicking cancel button the form gets unloaded*/
private void m_btnCancelActionPerformed
(java.awt.event.ActionEvent evt) {

try{
this.dispose();
this.finalize();
}
catch(Throwable t) {
String str = "Error during form load";
}

}

/*This function unloads the add state form*/
private void closeDialog(java.awt.event.WindowEvent evt)
{
setVisible(false);
dispose();
}


private javax.swing.JButton m_btnCancel;
//variable for cancel button
private javax.swing.JTextField m_txtStateName;
//variable for State name text field
private javax.swing.JLabel m_lblStateName;
//variable for State lablel
private javax.swing.JButton m_btnOk;
//variable for ok button
boolean b; //global variable of boolean
int id ; //global variable of integer
private EditState m_objEditState;
//object of state class
private DatabaseConnection m_objdbConn;
/*object of database connection class
(I have created my own databse connection class
which opens connection to database and execute query)*/



}

   <<Less

Re: how to write test case for following code

Posted By:   Anonymous  
Posted On:   Sunday, August 4, 2002 01:12 AM

From what is identifiable from your post, you might want to take a look at XPloration: Testing the GUI

Re: how to write test case for following code

Posted By:   Lasse_Koskela  
Posted On:   Saturday, August 3, 2002 08:51 AM

How about re-posting using the
 tags?
About | Sitemap | Contact