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

推荐订阅源

T
The Exploit Database - CXSecurity.com
J
Java Code Geeks
H
Help Net Security
B
Blog RSS Feed
G
Google Developers Blog
博客园 - 司徒正美
MongoDB | Blog
MongoDB | Blog
量子位
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
P
Proofpoint News Feed
小众软件
小众软件
人人都是产品经理
人人都是产品经理
云风的 BLOG
云风的 BLOG
V
V2EX
月光博客
月光博客
C
Check Point Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
A
Arctic Wolf
Help Net Security
Help Net Security
Schneier on Security
Schneier on Security
D
DataBreaches.Net
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Palo Alto Networks Blog
T
Tenable Blog
L
LangChain Blog
Attack and Defense Labs
Attack and Defense Labs
Google DeepMind News
Google DeepMind News
N
News and Events Feed by Topic
Forbes - Security
Forbes - Security
F
Fortinet All Blogs
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
大猫的无限游戏
大猫的无限游戏
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Y
Y Combinator Blog
WordPress大学
WordPress大学
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
NISL@THU
NISL@THU
GbyAI
GbyAI
博客园 - Franky
S
Secure Thoughts
有赞技术团队
有赞技术团队
PCI Perspectives
PCI Perspectives
U
Unit 42

博客园 - 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);

}

}