📄 teststockmanagementdata.java
字号:
package junittest;
import junit.framework.*;
import data.*;
import user.*;
public class TestStockManagementData extends TestCase {
private StockManagementData stockManagementData = null;
protected void setUp() throws Exception {
super.setUp();
stockManagementData = new StockManagementData();
}
protected void tearDown() throws Exception {
stockManagementData = null;
super.tearDown();
}
//测试检查用户的方法
public void testCheckUser() {
//测试正确的用户名
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]);
}
//测试创建用户的方法
public void testCreateUser() {
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() {
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() {
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);
}
//测试查询用户的方法
public void testGetUserByUserName() {
String userName = "jack";
String[][] result = stockManagementData.getUserByUserName(userName);
this.assertEquals("return value", "jack", result[0][1]);
}
//测试日志数据表记录的创建方法
public void testCreateUserLog() throws Exception{
String programName = "登陆窗口";
String operationContent = "登陆";
String userName = "jack";
//int result = stockManagementData.createUserLog(programName, operationContent, userName);
//this.assertEquals("return value", 1, result);
}
//测试日志数据表记录的删除方法
public void testDeleteUserLog() throws Exception{
Integer id = new Integer(1);
//int result = stockManagementData.deleteUserLog(id);
//this.assertEquals("return value", 1, result);
}
//测试返回数据库的所有数据表名字方法
public void testGetTableNames() throws Exception{
String[] tableNames = stockManagementData.getTableNames();
this.assertEquals("returnValue", "accountEntryLedger", tableNames[0]);
//this.assertEquals("returnValue", "accountName", tableNames[1]);
}
//测试取得数据表数据的方法
public void testGetDataByTableName() throws Exception{
String[][] data = stockManagementData.getDataByTableName("userTable");
this.assertEquals("returnValue", "ame", data[0][0]);
}
//测试写入数据表数据的方法
public void testSetDataByTableName() throws Exception{
String[][] data = new String[][] {
{"20040427", "0", "供应商", "请购员", "订购员", "验收员", "现金管理员", "收货地址",
"仓库", "2004-04-26", "2004-4-26 18:16:10", "1", "备注"},
{"20040426", "0", "aa1", "aa2", "aa3", "aa4", "aa5", "aa6", "aa7",
"2004-04-26", "2004-4-26 18:16:10", "0", "ss"}
};
//向数据表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", "20040426", "55566", "15.23", "58", "2004-04-26 13:45:12"}
};
//向数据表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);
}
//测试创建帐套的方法
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);
}
//测试商品类别的创建方法
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);*/
}
//测试商品创建方法
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 = "生产厂商1";
int upperLimit = 0;
int lowerLimit = 0;
double salePrice = 15;
double discount = 1;
//创建商品
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 = "生产厂商2";
upperLimit = 0;
lowerLimit = 0;
salePrice = 20.12;
discount = 0.56;
//创建商品
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 = "生产厂商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);
}
//测试根据类别取得商品的方法
public void testFindByGoodsCategory() throws Exception {
int goodsCategory = 1;
String[][] detail = stockManagementData.getGoodsByGoodsCategory(goodsCategory);
this.assertEquals("", 2, detail.length);
}
//测试根据条形码取得商品的方法
public void testFindByGoodsBarCode() throws Exception {
String goodsBarCode = "1";
String[][] detail = stockManagementData.getGoodsByGoodsBarCode(goodsBarCode);
this.assertEquals("", 3, detail.length);
}
//测试根据商品名字取得商品的方法
public void testFindByGoodsName() throws Exception {
String goodsName = "商品";
String[][] detail = stockManagementData.getGoodsByGoodsName(goodsName);
this.assertEquals("", 3, detail.length);
}
//测试根据生产厂商取得商品的方法
public void testFindByProducer() throws Exception {
String goodsName = "生产厂商";
String[][] detail = stockManagementData.getGoodsByProducer(goodsName);
this.assertEquals("", 3, detail.length);
}
//测试设置商品折扣的方法
public void testSetGoodsDiscount() throws Exception {
String goodsBarCode = "10000001";
double discount = 0.85;
int result = stockManagementData.setGoodsDiscount(goodsBarCode, discount);
this.assertEquals("return value", 1, result);
}
//测试取得折扣商品的方法
public void testFindDiscountGoods() throws Exception {
String[][] detail = stockManagementData.getDiscountGoods();
this.assertEquals("", 2, detail.length);
}
//测试商品删除方法
public void testGoodsDelete() throws Exception {
/*String goodsBarCode = "10000001";
int result = stockManagementData.deleteGoods(goodsBarCode);
this.assertEquals("return value", 1, result);
goodsBarCode = "10000002";
result = stockManagementData.deleteGoods(goodsBarCode);
this.assertEquals("return value", 1, result);*/
}
//测试供应商创建方法
public void testSupplierCreate() throws Exception{
//创建供应商数组
String[] supplier = new String[]{"测试供应商1", "南部", "拼音码1", "简称1", "021-556892",
"张凡", "1350058956", "021-896523", "021-963258", "地址1", "511896",
"中行", "银行帐号", "jack@hotmail.com", "www.jack.com", "备注1"};
//创建供应商
int result = stockManagementData.createSupplier(supplier);
this.assertEquals("", 1, result);
supplier = new String[]{"测试供应商2", "北部", "拼音码2", "简称2", "021-556892",
"张凡", "1350058956", "021-896523", "021-963258", "地址2", "511896",
"中行", "银行帐号", "jack@hotmail.com", "www.jack.com", "备注2"};
//创建供应商
result = stockManagementData.createSupplier(supplier);
this.assertEquals("", 1, result);
supplier = new String[]{"测试供应商3", "南部", "拼音码3", "简称3", "021-556892",
"张凡", "1350058956", "021-896523", "021-963258", "地址3", "511896",
"中行", "银行帐号", "jack@hotmail.com", "www.jack.com", "备注3"};
//创建供应商
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -