5 Star 10 Fork 4

00fly / javacode-frame

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
CustomerServiceTest.java 1.75 KB
一键复制 编辑 原始数据 按行查看 历史
00fly 提交于 2021-08-07 10:01 . update
package com.fly.test;
import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import com.fly.HbnApplication;
import com.fly.hbn.model.Customer;
import com.fly.hbn.service.CustomerService;
/**
* Junit 单元测试
*
* @author 00fly
* @version [版本号, 2018-09-11]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = HbnApplication.class)
public class CustomerServiceTest
{
@Autowired
CustomerService customerService;
@Autowired
private SessionFactory sessionFactory;
/**
* 事务测试(去掉@Transactional数据被插入或更新)
*
* @see [类、类#方法、类#成员]
*/
@Test
public void testTrans()
{
List<Customer> list = customerService.getAllCustomers();
System.out.println(list);
for (Customer customer : list)
{
customer.setCustomerName("custome_" + RandomStringUtils.randomNumeric(8));
customerService.updateCustomer(customer);
}
}
@Test
public void test()
{
Session session = sessionFactory.getCurrentSession();
List<?> data = session.createSQLQuery("select * from customer").addEntity(Customer.class).list();
System.out.println(data);
}
}
Java
1
https://gitee.com/00fly/java-code-frame.git
git@gitee.com:00fly/java-code-frame.git
00fly
java-code-frame
javacode-frame
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891