/**
 * ClientService测试类
 * ClientServiceTest.java
 * Copyright (C) 2010 SLMS
 * Simple Logistics Management System
 * 
 */
package com.zds.slms.test;

import java.util.List;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.zds.slms.domain.Client;
import com.zds.slms.service.IClientService;

/**
 * Copyright (C) 2010:SLMS<br/>
 * Project:SLMS<br/>
 * Module ID:<br/>
 * Comments:Simple Logistics Management System<br/>
 * JDK version used:JDK1.6<br/>
 * Package:com.zds.slms.test<br/>
 * Author:chenyongzheng<br/>
 * Create Date:2010-12-5<br/>
 * Modified By:<br/>
 * Modified Date:<br/>
 * Why & What is modified:<br/>
 * Version:0.1<br/>
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/applicationContext_common.xml",
		"/applicationContext_beans.xml" })
public class ClientServiceTest {
	// Bean自动注入
	@Autowired
	IClientService clientService;

	@Test
	public void testFindClient() {
		int recordCount = 10;
		// 测试插入10条客户信息
		for (int i = 0; i < recordCount; i++) {
			Client client = new Client();
			client.setName("name" + i);
			client.setCode("cd");
			client.setAddress("address" + i);
			client.setEmail("email" + i);
			client.setTelephone("13996551866");
			// 执行插入操作
			clientService.saveClient(client);

		}
		// 查询所有插入的数据
		List<Client> clients = clientService.findClient(null);
		// 用预想结果条件和实际结果条数相比较
		Assert.assertEquals("ClientService Test fail...", recordCount,
				clients.size());

	}

	/**
	 * 
	 * 
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		List<Client> clients = clientService.findClient(null);
		// 清空数据库所有记录以免干扰测试
		for (Client client : clients) {
			clientService.deleteClient(new String[] { String.valueOf(client
					.getId()) });
		}
	}

}
