📄 testchapter09.java
字号:
package com.manning.hq.ch09;
import junit.framework.TestCase;
import org.hibernate.HibernateException;
import org.hibernate.Session;
/**
* A smoke test for chapter 09.
*/
public class TestChapter09 extends TestCase {
private Session session;
private Session session2;
protected void setUp() throws Exception {
HibernateFactory.buildSessionFactory();
session = HibernateFactory.openSession();
session2 = HibernateFactory.openSession();
}
protected void tearDown() throws Exception {
super.tearDown();
session.createQuery("delete Event").executeUpdate();
session.createQuery("delete Location").executeUpdate();
session.close();
session2.close();
}
public void testChapter09() throws HibernateException {
Event event = new Event();
event.setName("Good Morning Chapter 9");
session.save(event);
session.flush();
Event event2 = (Event) session2.load(Event.class, event.getId());
assertEquals("Check names", event.getName(), event2.getName());
}
public void testLocationsWithMultipleAddresses() throws HibernateException {
LocationWithMultipleAddresses loc = new LocationWithMultipleAddresses();
loc.setName("A Name");
session.save(loc);
session.flush();
LocationWithMultipleAddresses loc2 = (LocationWithMultipleAddresses) session2.load(LocationWithMultipleAddresses.class, loc.getId());
assertEquals("Check names", loc.getName(), loc2.getName());
}
/**
*
*/
public void testAddress(){
Location location = new Location();
Address address = new Address();
location.setAddress(address);
address.setCity("Arlington");
session.save(location);
session.flush();
Location actual = (Location) session2.load(Location.class, location.getId());
assertEquals("", actual.getAddress().getCity(), location.getAddress().getCity());
}
/**
*
*/
public void testLocations(){
Event event = new Event();
Location location = new Location();
location.setName("Homeland");
event.setLocation(location);
session.save(event);
session.flush();
Event actual = (Event) session2.load(Event.class, event.getId());
assertEquals("", actual.getLocation().getName(), actual.getLocation().getName());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -