⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testcartdatajunit1.java~26~

📁 购物车模块实例。购物车模块可以浏览商品类别;可以根据商品类别浏览商品信息;可以购买商品;可以查看购物车的商品;可以修改购买商品的数量和删除购买的商品。
💻 JAVA~26~
字号:
package junittest;import junit.framework.*;import cmscartpro.*;import javax.naming.*;import java.util.Properties;import javax.rmi.PortableRemoteObject;import java.rmi.RemoteException;public class TestCartDataJUnit1 extends TestCase {  private static final String ERROR_NULL_REMOTE = "Remote interface reference is null. "      + "It must be created by calling one of the Home interface methods first.  "      + "Make sure that the setUp() method calls one of the create() or finder Home "      + "interfacewrappers, or the userTableCPRemote remote reference is assigned there "      + "in some other way.";  private static final int MAX_OUTPUT_LINE_LENGTH = 100;  private boolean logging = false;  private CartDataHome cartDataHome = null;  private CartData cartData = null;  public TestCartDataJUnit1(String name) {    super(name);  }  public void initialize() throws Exception {    //创建服务器查找类    Context context = getInitialContext();    //取得服务器的EJB对象    Object ref = context.lookup("CartData");    //取得EJB的本地接口    cartDataHome = (CartDataHome) PortableRemoteObject.narrow(ref, CartDataHome.class);  }  //服务器查找类初始化方法  private Context getInitialContext() throws Exception {    String url = "t3://bemyfriend:7001";    String user = null;    String password = null;    Properties properties = null;    try {      properties = new Properties();      properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");      properties.put(Context.PROVIDER_URL, url);      if (user != null) {        properties.put(Context.SECURITY_PRINCIPAL, user);        properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);      }      return new InitialContext(properties);    }    catch(Exception e) {      System.out.println("Unable to connect to WebLogic server at " + url);      System.out.println("Please make sure that the server is running.");      throw e;    }  }  public void setUp() throws Exception {    super.setUp();    initialize();    //取得EJB的远程接口    create();  }  public void tearDown() throws Exception {    cartDataHome = null;    cartData = null;    super.tearDown();  }  public CartData create() throws Exception {    cartData = cartDataHome.create();    return cartData;  }  //测试取得产品类别的方法  public void testGetCategories() throws RemoteException {    assertNotNull(ERROR_NULL_REMOTE, cartData);    long startTime = 0;      log("运行getCategories方法");      startTime = System.currentTimeMillis();    }    int expectedReturnCount = 8;    String[][] actualReturn = inforData.getCategories();    assertEquals("返回的记录数", expectedReturnCount, actualReturn.length);    if (logging) {      long endTime = System.currentTimeMillis();      log("运行成功: getCategories()");      log("运行时间: " + (endTime - startTime) + " ms.");    }  }  //测试取得产品的方法  public void testGetProducts() throws RemoteException {    int categoryId = 0;    assertNotNull(ERROR_NULL_REMOTE, cartData);    cartData.getProducts(categoryId);  }  public CartDataHome getHome() {    return cartDataHome;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -