惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
博客园 - 【当耐特】
月光博客
月光博客
Vercel News
Vercel News
D
Docker
I
InfoQ
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
GbyAI
GbyAI
有赞技术团队
有赞技术团队
雷峰网
雷峰网
博客园 - 聂微东
小众软件
小众软件
Y
Y Combinator Blog
腾讯CDC
L
LangChain Blog
The GitHub Blog
The GitHub Blog
宝玉的分享
宝玉的分享
Stack Overflow Blog
Stack Overflow Blog
大猫的无限游戏
大猫的无限游戏
T
The Blog of Author Tim Ferriss

博客园 - xhan

提交给mysql java驱动的优化下个版本要发布了^_^ java 可伸缩阻塞队列实现 java mysql大数据量批量插入与流式读取分析 innodb next-key lock引发的死锁 jremoting的功能扩展点 java开源项目jremoting largest remainder method java impl 元数据编程实战_使用Emit运行时生成Protobuf编码类 发布个c#版的HandlerSocket客户端类库 redis入门系列文章广告贴 九 redis学习笔记之虚拟内存 八 redis学习笔记之主从复制 七 redis学习笔记之持久化 六 redis学习笔记之发布订阅 五 redis学习笔记之pipeline 四 redis学习笔记之事务 三 redis学习笔记之排序 二 redis学习笔记之数据类型 - xhan - 博客园 一 redis学习笔记之环境搭建
数据库单元测试
xhan · 2011-09-22 · via 博客园 - xhan

package com.hichina.bc.repository.test;

import junit.framework.Assert;

import org.hibernate.SessionFactory;

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.hichina.bc.domain.Customer;

import com.hichina.bc.repository.CustomerRepository;

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(locations = {"classpath:dispatcher-servlet.xml"})

public class CustomerRepositoryTest   {

@Autowired

private SessionFactory sessionFactory;

@Autowired

private CustomerRepository customerRepository;

@Test 

public void testInsert() {

sessionFactory.openSession()

.createSQLQuery("truncate table CustomerTest").executeUpdate();

sessionFactory.openSession()

.createSQLQuery("insert into  CustomerTest (name,password) values ('aa','bb')")

.executeUpdate();

Customer customer = customerRepository.getById(1);

Assert.assertNotNull(customer);

}

@Test

public void testSave() {

Customer customer = new Customer();

customer.setName("xhan");

customer.setPassword("13");

customerRepository.save(customer);

System.out.println(customer.getUserId());

Assert.assertTrue(customer.getUserId() != 0);

}

@Test

public void testUpdate() {

Customer customer = new Customer();

customer.setName("xhan");

customer.setPassword("13");

customerRepository.save(customer);

Assert.assertTrue(customer.getUserId() != 0);

customer.setName("123");

customer.setPassword("xhan");

customerRepository.update(customer);

Customer customer2 = customerRepository.getById(customer.getUserId());

Assert.assertEquals("xhan", customer2.getPassword());

Assert.assertNotSame(customer, customer2);

}

}