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

📄 cellphoneservicetest.java

📁 这个是完整的wap项目的源码 开发语言 Java 系统架构 Struts + hibernate + spring 数据库 Mysql5.0 应用服务器Tomcat5.0 开发工具 MyEc
💻 JAVA
字号:
package com.longtime.wap.module.cellphone.service;

import java.util.List;

import com.longtime.wap.common.util.BaseTestCase;
import com.longtime.wap.common.web.Page;
import com.longtime.wap.model.Cellphone;

public class CellphoneServiceTest extends BaseTestCase {

	private CellphoneService service;

	public CellphoneServiceTest() {
		super();
		service = (CellphoneService) context
				.getBean("cellphoneCellphoneService");
	}

	/**
	 * 根据id获取手机对象
	 * 
	 */
public void testGetCellphoneById() {
		Cellphone cellphone = (Cellphone)service.getCellphoneById(Long.valueOf(2));
		assertEquals("55853-2", cellphone.getUa());
		assertEquals("T320", cellphone.getModel());
		assertEquals("Moto", cellphone.getBrand());
		assertEquals(0, cellphone.getSupportImageSize());
		assertEquals(0, cellphone.getSupportImageType());
	}
	/**
	 * 根据手机UA获取手机对象
	 * 
	 */
	public void testGetCellphoneByUA() {
		Cellphone cellphone = (Cellphone)service.getCellphoneByUA("55853-2");
		assertEquals(2, cellphone.getCellphoneId());
		assertEquals("T320", cellphone.getModel());
		assertEquals("Moto", cellphone.getBrand());
		assertEquals(0, cellphone.getSupportImageSize());
		assertEquals(0, cellphone.getSupportImageType());
	}

	/**
	 * 根据手机型号获取手机对象
	 * 
	 */
	public void testGetCellphoneByModel() {
		Cellphone cellphone = (Cellphone)service.getCellphoneByModel("T320");
		assertEquals(2, cellphone.getCellphoneId());
		assertEquals("55853-2", cellphone.getUa());
		assertEquals("Moto", cellphone.getBrand());
		assertEquals(0, cellphone.getSupportImageSize());
		assertEquals(0, cellphone.getSupportImageType());
	}

	/**
	 * 新增,更新手机对象
	 * 
	 */
	public void testSaveCellphone() {
		//新增
		Cellphone cellphone = new Cellphone();
		cellphone.setBrand("Moto");
		cellphone.setModel("T60");
		cellphone.setSupportImageSize(0);
		cellphone.setSupportImageType(0);
		cellphone.setUa("2312-4");
		service.saveCellphone(cellphone);
		Cellphone cellphoneAfterSave = service.getCellphoneByModel("T60");
		assertEquals("Moto", cellphoneAfterSave.getBrand());
		assertEquals(0, cellphoneAfterSave.getSupportImageSize());
		assertEquals(0, cellphoneAfterSave.getSupportImageType());
		assertEquals("2312-4", cellphoneAfterSave.getUa());
		//更新
		Cellphone c = (Cellphone)service.getCellphoneById(Long.valueOf(2));
		c.setBrand("Nokia");
		c.setSupportImageType(2);
		c.setModel("T321");
		c.setUa("55853-3");
		service.saveCellphone(c);
		Cellphone cAfterSave = (Cellphone)service.getCellphoneById(Long.valueOf(2));
		assertEquals("Nokia", cAfterSave.getBrand());
		assertEquals(2, cAfterSave.getSupportImageType());
		assertEquals("T321", cAfterSave.getModel());
		assertEquals("55853-3", cAfterSave.getUa());
	}
	

	/**
	 * 删除手机对象
	 * 
	 */
	public void testDeleteCellphones() {
		String[] ids = new String[]{"2", "31", "32"};
		service.deleteCellphones(ids);
		assertNull(service.getCellphoneById(Long.valueOf(2)));
		assertNull(service.getCellphoneById(Long.valueOf(31)));
		assertNull(service.getCellphoneById(Long.valueOf(32)));
	}

	/**
	 * 根据条件获取手机对象
	 * 
	 */
	@SuppressWarnings("unchecked")
	public void testGetCellByCondition() {
		List<Cellphone> cl = service.getCellByCondition("10", "Sony", new Page(1));
		assertEquals(2, cl.size());
		assertEquals(31, cl.get(0).getCellphoneId());
		assertEquals(32, cl.get(1).getCellphoneId());
	}
}

⌨️ 快捷键说明

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