?? teststockmanagementdatacactus1.java
字號:
package cactustest;
import org.apache.cactus.*;
import stockmanagementpro.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.rmi.RemoteException;
import user.User;
public class TestStockManagementDataCactus1 extends ServletTestCase {
private static final String ERROR_NULL_REMOTE = "對象未定義.";
private static final int MAX_OUTPUT_LINE_LENGTH = 100;
private boolean logging = false;
private StockManagementDataHome stockManagementDataHome = null;
private StockManagementData stockManagementData = null;
public TestStockManagementDataCactus1(String name) {
super(name);
}
//初始化EJB的方法
public void initialize() throws Exception {
Context context = new InitialContext();
Object ref = context.lookup("StockManagementData");
stockManagementDataHome = (StockManagementDataHome) PortableRemoteObject.
narrow(ref, StockManagementDataHome.class);
create();
}
public void setUp() throws Exception {
super.setUp();
initialize();
}
public void tearDown() throws Exception {
stockManagementDataHome = null;
stockManagementData = null;
super.tearDown();
}
//創(chuàng)建EJB的遠(yuǎn)程接口
public StockManagementData create() throws Exception {
stockManagementData = stockManagementDataHome.create();
return stockManagementData;
}
//測試檢查用戶的方法
public void testCheckUser() throws RemoteException {
//測試正確的用戶名
String userName = "jack";
String userPassword = "jack";
//檢查用戶的方法
int[] functions = stockManagementData.checkUser(userName, userPassword);
this.assertEquals("return value", 0, functions[0]);
//測試錯誤的用戶名
userName = "jack1";
userPassword = "jack";
//檢查用戶的方法
functions = stockManagementData.checkUser(userName, userPassword);
this.assertEquals("return value", -1, functions[0]);
}
//測試創(chuàng)建用戶的方法
public void testCreateUser() throws RemoteException {
String userName = "test";
String userPassword = "test";
int baseInforFunction = 0;
int stockFunction = 0;
int stockManageFunction = 0;
int saleFunction = 0;
User user = new User(userName, userPassword, baseInforFunction,
stockFunction, stockManageFunction, saleFunction);
int result = stockManagementData.createUser(user);
this.assertEquals("return value", 1, result);
}
//測試更新用戶的方法
public void testUpdateUser() throws RemoteException {
String userName = "test";
String userPassword = "test1";
int baseInforFunction = 1;
int stockFunction = 1;
int stockManageFunction = 1;
int saleFunction = 1;
User user = new User(userName, userPassword, baseInforFunction,
stockFunction, stockManageFunction, saleFunction);
int result = stockManagementData.updateUser(user);
this.assertEquals("return value", 1, result);
}
//測試刪除用戶的方法
public void testDeleteUser() throws RemoteException {
String userName = "test";
String userPassword = "test";
int baseInforFunction = 0;
int stockFunction = 0;
int stockManageFunction = 0;
int saleFunction = 0;
User user = new User(userName, userPassword, baseInforFunction,
stockFunction, stockManageFunction, saleFunction);
int result = stockManagementData.deleteUser(user);
this.assertEquals("return value", 1, result);
}
//測試根據(jù)用戶名字取得用戶記錄的方法
public void testGetUserByUserName() throws RemoteException {
String userName = "jack";
String[][] result = stockManagementData.getUserByUserName(userName);
this.assertEquals("return value", "jack", result[0][1]);
}
//測試日志數(shù)據(jù)表記錄的創(chuàng)建方法
public void testCreateUserLog() throws Exception{
String programName = "登陸窗口";
String operationContent = "登陸";
String userName = "jack";
//stockManagementData.createUserLog(programName, operationContent, userName);
}
//測試日志數(shù)據(jù)表記錄的刪除方法
public void testDeleteUserLog() throws Exception{
Integer id = new Integer(1);
//stockManagementData.deleteUserLog(id);
}
//測試返回數(shù)據(jù)庫的所有數(shù)據(jù)表名字方法
public void testGetTableNames() throws Exception{
String[] tableNames = stockManagementData.getTableNames();
this.assertEquals("returnValue", "accountEntryLedger", tableNames[0]);
//this.assertEquals("returnValue", "accountName", tableNames[1]);
}
//測試取得數(shù)據(jù)表數(shù)據(jù)的方法
public void testGetDataByTableName() throws Exception{
String[][] data = stockManagementData.getDataByTableName("userTable");
this.assertEquals("returnValue", "ame", data[0][0]);
}
//測試寫入數(shù)據(jù)表數(shù)據(jù)的方法
public void testSetDataByTableName() throws Exception{
String[][] data = new String[][] {
{"20040428", "0", "供應(yīng)商", "請購員", "訂購員", "驗(yàn)收員", "現(xiàn)金管理員", "收貨地址",
"倉庫", "2004-04-26", "2004-4-26 18:16:10", "1", "備注"},
{"20040427", "0", "aa1", "aa2", "aa3", "aa4", "aa5", "aa6", "aa7",
"2004-04-26", "2004-4-26 18:16:10", "0", "ss"}
};
//向數(shù)據(jù)表stockLedger寫入記錄
int result = stockManagementData.setDataByTableName("stockLedger", data);
this.assertEquals("returnValue", 1, result);
data = new String[][] {
{"1", "20040427", "55566", "15.23", "58", "2004-04-26"},
{"2", "20040428", "55566", "15.23", "58", "2004-04-26 13:45:12"}
};
//向數(shù)據(jù)表stockSubLedger寫入記錄
result = stockManagementData.setDataByTableName("stockSubLedger", data);
this.assertEquals("returnValue", 1, result);
}
//測試取得帳套名字的方法
public void testGetLedgerNames() throws Exception{
String[] ledgerNames = stockManagementData.getLedgerNames();
this.assertEquals("return value", 1, ledgerNames.length);
}
//測試創(chuàng)建帳套的方法
public void testCreateLedger() throws Exception{
String ledgerDate = "200405";
int result = stockManagementData.createLedger(ledgerDate);
this.assertEquals("return value", 1, result);
result = stockManagementData.createLedger(ledgerDate);
this.assertEquals("return value", 0, result);
}
//測試刪除帳套的方法
public void testDeleteLedger() throws Exception{
String ledgerDate = "200403";
int result = stockManagementData.deleteLedger(ledgerDate);
this.assertEquals("return value", 0, result);
}
//測試商品類別的創(chuàng)建方法
public void testCreateGoodsCategory() throws Exception{
/*int parentId = 0;
String categoryName = "商品類別1";
String categoryDescription = "商品類別1的描述";
int result = stockManagementData.createGoodsCategory(parentId,
categoryName, categoryDescription);
this.assertEquals("return value", 1, result);
parentId = 0;
categoryName = "商品類別2";
categoryDescription = "商品類別2的描述";
result = stockManagementData.createGoodsCategory(parentId,
categoryName, categoryDescription);
this.assertEquals("return value", 1, result);*/
}
//測試商品類別的更新方法
public void testUpdateGoodsCategory() throws Exception{
int categoryId = 1;
int parentId = 0;
String categoryName = "商品類別1(更新)";
String categoryDescription = "商品類別1的描述";
int result = stockManagementData.updateGoodsCategory(categoryId, parentId,
categoryName, categoryDescription);
this.assertEquals("return value", 1, result);
}
//測試商品類別的findAll方法
public void testFindAll() throws Exception{
String[][] detail = stockManagementData.getAllGoodsCategory();
this.assertEquals("", 2, detail.length);
}
//測試商品類別的刪除方法
public void testDeleteGoodsCategory() throws Exception{
/*int categoryId = 1;
int result = stockManagementData.deleteGoodsCategory(categoryId);
this.assertEquals("return value", 1, result);
categoryId = 2;
result = stockManagementData.deleteGoodsCategory(categoryId);
this.assertEquals("return value", 1, result);*/
}
//測試商品創(chuàng)建方法
public void testGoodsCreate() throws Exception {
/*String goodsBarCode = "10000001";
int categoryId = 1;
String goodsName = "類別1的商品1";
String goodsNickName = "別名1";
String goodsAssistantName = "助記碼1";
String goodsPYName = "LBDSP1";
String unit = "件";
String specification = "每箱10件";
String producer = "生產(chǎn)廠商1";
int upperLimit = 0;
int lowerLimit = 0;
double salePrice = 15;
double discount = 1;
//創(chuàng)建商品
int result = stockManagementData.createGoods(goodsBarCode, categoryId,
goodsName, goodsNickName, goodsAssistantName, goodsPYName, unit,
specification, producer, upperLimit, lowerLimit, salePrice, discount);
this.assertEquals("return value", 1, result);
goodsBarCode = "10000002";
categoryId = 1;
goodsName = "類別1的商品2";
goodsNickName = "別名2";
goodsAssistantName = "助記碼2";
goodsPYName = "LBDSP2";
unit = "件";
specification = "每箱10件";
producer = "生產(chǎn)廠商2";
upperLimit = 0;
lowerLimit = 0;
salePrice = 20.12;
discount = 0.56;
//創(chuàng)建商品
result = stockManagementData.createGoods(goodsBarCode, categoryId, goodsName,
goodsNickName, goodsAssistantName, goodsPYName, unit,
specification, producer, upperLimit, lowerLimit, salePrice, discount);
this.assertEquals("return value", 1, result);*/
}
//測試商品更新方法
public void testGoodsUpdate() throws Exception {
String goodsBarCode = "10000001";
int categoryId = 1;
String goodsName = "類別1的商品1(更新)";
String goodsNickName = "別名1";
String goodsAssistantName = "助記碼1";
String goodsPYName = "LBDSP1";
String unit = "件";
String specification = "每箱10件";
String producer = "生產(chǎn)廠商1";
int upperLimit = 0;
int lowerLimit = 0;
double salePrice = 15;
double discount = 1;
int result = stockManagementData.updateGoods(goodsBarCode, categoryId, goodsName,
goodsNickName, goodsAssistantName, goodsPYName, unit,
specification, producer, upperLimit, lowerLimit, salePrice, discount);
this.assertEquals("return value", 1, result);
}
//測試根據(jù)類別取得商品的方法
public void testFindByGoodsCategory() throws Exception {
int goodsCategory = 1;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -