?? testcustomercactus1.java
字號:
package cactustest;import org.apache.cactus.*;import stockmanagementpro.*;import javax.naming.*;import java.util.Collection;import java.rmi.RemoteException;public class TestCustomerCactus1 extends ServletTestCase { private static final String ERROR_NULL_REMOTE = "接口未定義."; private static final int MAX_OUTPUT_LINE_LENGTH = 100; private boolean logging = false; private CustomerHome customerHome = null; private Customer customer = null; public TestCustomerCactus1(String name) { super(name); } public void initializeLocalHome() throws Exception { Context context = new InitialContext(); customerHome = (CustomerHome) context.lookup("Customer"); } public void setUp() throws Exception { super.setUp(); initializeLocalHome(); } public void tearDown() throws Exception { customerHome = null; customer = null; super.tearDown(); } //測試客戶創建方法 public void testCustomerCreate() throws Exception{ //創建客戶數組 String[] customer = new String[]{"測試客戶1", "南部", "拼音碼1", "簡稱1", "021-556892", "張凡", "1350058956", "021-896523", "021-963258", "地址1", "511896", "中行", "銀行帳號", "jack@hotmail.com", "www.jack.com", "10000","備注1"}; //創建客戶 customerHome.create(customer[0], customer[1], customer[2], customer[3], customer[4], customer[5], customer[6], customer[7], customer[8], customer[9], customer[10], customer[11], customer[12], customer[13], customer[14], Double.parseDouble(customer[15]), customer[16]); customer = new String[]{"測試客戶2", "北部", "拼音碼2", "簡稱2", "021-556892", "張凡", "1350058956", "021-896523", "021-963258", "地址2", "511896", "中行", "銀行帳號", "jack@hotmail.com", "www.jack.com", "10000", "備注2"}; //創建客戶 customerHome.create(customer[0], customer[1], customer[2], customer[3], customer[4], customer[5], customer[6], customer[7], customer[8], customer[9], customer[10], customer[11], customer[12], customer[13], customer[14], Double.parseDouble(customer[15]), customer[16]); customer = new String[]{"測試客戶3", "南部", "拼音碼3", "簡稱3", "021-556892", "張凡", "1350058956", "021-896523", "021-963258", "地址3", "511896", "中行", "銀行帳號", "jack@hotmail.com", "www.jack.com", "10000", "備注3"}; //創建客戶 customerHome.create(customer[0], customer[1], customer[2], customer[3], customer[4], customer[5], customer[6], customer[7], customer[8], customer[9], customer[10], customer[11], customer[12], customer[13], customer[14], Double.parseDouble(customer[15]), customer[16]); } //測試客戶更新方法 public void testCustomerUpdate() throws Exception{ String[] customer = new String[]{"測試客戶1", "北部"}; this.customer = customerHome.findByPrimaryKey(customer[0]); //更新客戶的值 this.customer.setCustomerZone(customer[1]); } //測試根據客戶名字取得記錄的方法 public void testFindByCustomerName() throws Exception { Collection col = customerHome.findByCustomerName("%客戶%"); this.assertEquals("", 6, col.size()); } //測試根據地區取得記錄的方法 public void testFindByCustomerZone() throws Exception { Collection col = customerHome.findByCustomerZone("%北部%"); this.assertEquals("", 4, col.size()); } //測試取得信用客戶記錄的方法 public void testFindCreditCustomer() throws Exception { Collection col = customerHome.findCreditCustomer(); this.assertEquals("", 6, col.size()); } //測試客戶刪除方法 public void testCustomerDelete() throws Exception{ String[] customers = new String[]{"測試客戶1", "測試客戶2", "測試客戶3"}; customer = customerHome.findByPrimaryKey(customers[0]); //刪除客戶 customer.remove(); customer = customerHome.findByPrimaryKey(customers[1]); //刪除客戶 customer.remove(); customer = customerHome.findByPrimaryKey(customers[2]); //刪除客戶 customer.remove(); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -