📄 businessservicetest.java
字号:
package com.longtime.wap.module.business.service;
import java.util.Date;
import java.util.List;
import com.longtime.wap.common.util.BaseTestCase;
import com.longtime.wap.model.Business;
import com.longtime.wap.model.Cp;
public class BusinessServiceTest extends BaseTestCase {
private BusinessService service;
public BusinessServiceTest() {
super();
service = (BusinessService) context.getBean("businessBusinessService");
}
/**
* 根据id获取
*
*/
public void testGetBusinessByid() {
Business business = (Business) service.getBusinessById(Long.valueOf(4));
assertEquals("丛艳吉-川甘西行", business.getBusinessName());
assertEquals(2, business.getCategory());
assertEquals(365, business.getDuration());
assertEquals("2007-11-21", business.getPubDate().toString());
}
/**
* 根据名字获取业务对象
*
*/
public void testGetBusinessByName() {
Business business = (Business) service.getBusinessByName("绿色和平");
assertEquals(364, business.getBusinessId());
assertEquals(0, business.getCategory());
assertEquals(123, business.getCp().getCpId());
assertEquals(999, business.getDuration());
assertEquals("2007-11-29", business.getPubDate().toString());
}
/**
* 获取cp
*
*/
public void testGetCpByCpId() {
Cp cp = (Cp) service.getCpByCpId(43);
assertEquals(43, cp.getCpId());
assertEquals(11, cp.getCompanyCode());
assertEquals("龙通联讯", cp.getCompanyName());
assertEquals("电信业务", cp.getServiceDesc());
assertEquals("2007-11-28", cp.getRegDate().toString());
}
/**
* 更新,保存
*
*/
public void testSaveBusiness() {
//新增
Business business = new Business();
business.setBusinessName("嘿嘿");
business.setCategory(0);
business.setCp(service.getCpByCpId(43));
business.setDuration(50);
business.setPubDate(new Date());
service.saveBusiness(business);
assertEquals("嘿嘿", service.getBusinessByName("嘿嘿").getBusinessName());
assertEquals(0, service.getBusinessByName("嘿嘿").getCategory());
assertEquals(43, service.getBusinessByName("嘿嘿").getCp().getCpId());
assertEquals(50, service.getBusinessByName("嘿嘿").getDuration());
//更新
Business b = service.getBusinessById(Long.valueOf(3));
b.setCategory(0);
b.setBusinessName("《周杰伦-我不忙~》");
b.setDuration(50);
service.saveBusiness(b);
Business businessAfterSave = service.getBusinessById(Long.valueOf(3));
assertEquals(0, businessAfterSave.getCategory());
assertEquals("《周杰伦-我不忙~》", businessAfterSave.getBusinessName());
assertEquals(50, businessAfterSave.getDuration());
}
/**
* 批量删除业务对象
*
*/
public void testDeleteBusinesses() {
assertNotNull(service.getBusinessById(Long.valueOf(3)));
assertNotNull(service.getBusinessById(Long.valueOf(3)));
String[] ids = new String[] { "3", "364" };
service.deleteBusinesses(ids);
assertNull(service.getBusinessById(Long.valueOf(3)));
assertNull(service.getBusinessById(Long.valueOf(364)));
}
/**
* 批量更新业务时效
*
*/
public void testSaveBusinessesDuration() {
service.saveBusinessesDuration(new String[] { "3", "364" },
new String[] { "2", "998" });
assertEquals(2, service.getBusinessById(Long.valueOf(3))
.getDuration());
assertEquals(998, service.getBusinessById(Long.valueOf(364))
.getDuration());
}
/**
* 获取某类的业务集合
*
*/
@SuppressWarnings("unchecked")
public void testGetBusinessesByCategory() {
List<Business> bl = service.getBusinessesByCategory(2);
assertEquals(5, bl.size());
Business b = (Business) bl.get(4);
assertEquals(331, b.getBusinessId());
assertEquals(2, b.getCategory());
assertEquals(123, b.getCp().getCpId());
assertEquals("彩信", b.getBusinessName());
assertEquals(10, b.getDuration());
assertEquals("2007-11-29", b.getPubDate().toString());
}
/**
* 根据单位id获取属于某单位的业务对象集合
*
*/
@SuppressWarnings("unchecked")
public void testGetBusinessesByCpId() {
List<Business> bl = service.getBusinessesByCpId(Long.valueOf(1));
assertEquals(4, bl.size());
Business b = (Business) bl.get(3);
assertEquals(126, b.getBusinessId());
assertEquals(0, b.getCategory());
assertEquals(1, b.getCp().getCpId());
assertEquals("小笨蛋", b.getBusinessName());
assertEquals(0, b.getDuration());
assertEquals("2007-11-28", b.getPubDate().toString());
}
/**
* 获取所有单位列表
*
*/
@SuppressWarnings("unchecked")
public void testGetCps() {
List<Cp> cl = service.getCps();
assertEquals(10, cl.size());
Cp cp = (Cp) cl.get(9);
assertEquals(181, cp.getCpId());
assertEquals(12121121, cp.getCompanyCode());
assertEquals("都市主妇", cp.getCompanyName());
assertEquals("2007-11-29", cp.getRegDate().toString());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -