参考:http://lijingshou.iteye.com/blog/2269593
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.bluedon.useradmin.datainteraction.commontype.OperationStatus;
import com.bluedon.useradmin.datainteraction.commontype.TableType;
import com.bluedon.useradmin.datainteraction.core.VolunteerDataInteractionServiceImpl;
import com.bluedon.useradmin.datainteraction.model.UploadDataRecord;
import com.bluedon.useradmin.datainteraction.model.bd.metadata.BDVolunteer;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:/application-context-test.xml"})
public class BDVolunteerTest {
@Resource
private VolunteerDataInteractionServiceImpl volunteerDataInteractionService;
@Test
public void testAdd(){
BDVolunteer volunteer = new BDVolunteer();
volunteer.setZyzbh("88888");
volunteer.setZjlx("440784");
volunteer.setZjhm("4407845");
volunteer.setXm("李四");
volunteer.setCsrq(new Date());
volunteer.setXingbie("1");
volunteer.setGuoji("中国");
volunteer.setMingzu("汉族");
volunteer.setZzmm("群众");
volunteer.setXueli("本科");
volunteer.setJgsf("110000");
volunteer.setJgs("110000");
volunteer.setJzsf("110000");
volunteer.setJzs("110000");
volunteer.setJzxq("110000");
volunteer.setYddh("138244");
volunteer.setCyzt("失业");
volunteer.setLjfwsj(100L);
volunteer.setLjpxsj(50L);
volunteer.setZcsj(new Date());
UploadDataRecord obj = new UploadDataRecord();
obj.setSystemCode("izy");
obj.setBatch("123");
obj.setCreateTime(new Date());
obj.setFlag("aaa");
obj.setOperation(OperationStatus.ADD.getValue());
obj.setTable(TableType.BDVolunteer.getName());
obj.setData(volunteer);
List<UploadDataRecord> list = new ArrayList<UploadDataRecord>();
list.add(obj);
volunteerDataInteractionService.addUploadData("izy", "123", list);
}
}
1、maven依赖
<!-- junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.9.RELEASE</version>
<scope>test</scope>
</dependency>
2、类名添加注解
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:/application-context-test.xml"})
然后即可用@Resource进行注入