01: package org.osbl.issue.model;
02:
03: import junit.framework.TestCase;
04: import org.hibernate.*;
05: import org.hibernate.cfg.Configuration;
06: import org.osbl.identity.model.*;
07: import org.apache.commons.lang.builder.EqualsBuilder;
08:
09: import java.util.*;
10: import java.sql.Timestamp;
11: import java.sql.Date;
12:
13: public class IssueMappingTest extends TestCase {
14:
15: private Session session;
16: private Transaction transaction;
17:
18: protected void setUp() throws Exception {
19: Configuration configuration = new Configuration();
20: configuration.configure("test-hibernate.cfg.xml");
21: configuration.addResource("Issue.hbm.xml");
22:
23: SessionFactory sessionFactory = configuration
24: .buildSessionFactory();
25: session = sessionFactory.openSession();
26: transaction = session.beginTransaction();
27: }
28:
29: public void testCRUD() {
30: Issue issue = new Issue();
31: HashSet<String> assignees = new HashSet<String>();
32: assignees.add("he");
33: issue.setAssignees(assignees);
34: issue.setDescription("description");
35: issue.setDone(new Timestamp(System.currentTimeMillis()));
36: issue.setDue(new Date(System.currentTimeMillis()));
37: issue.setInCharge("he");
38: List<Link> links = new ArrayList<Link>();
39: links.add(new Link("name", "a=1&b=2"));
40: issue.setLinks(links);
41: issue.setName("name");
42:
43: session.save(issue);
44:
45: session.flush();
46: session.clear();
47:
48: Issue loadedIssue = (Issue) session.createQuery("from Issue")
49: .uniqueResult();
50: assertEquals(issue.getAssignees().iterator().next(),
51: loadedIssue.getAssignees().iterator().next());
52: assertEquals(issue.getDescription(), loadedIssue
53: .getDescription());
54: assertEquals(issue.getDone(), loadedIssue.getDone());
55: //assertEquals(issue.getDue(), loadedIssue.getDue());
56: assertEquals(issue.getLinks().get(0).getName(), loadedIssue
57: .getLinks().get(0).getName());
58: assertEquals(issue.getLinks().get(0).getLink(), loadedIssue
59: .getLinks().get(0).getLink());
60: assertEquals(issue.getName(), loadedIssue.getName());
61: //assertTrue(EqualsBuilder.reflectionEquals(issue, loadedIssue));
62:
63: session.clear();
64: }
65:
66: protected void tearDown() throws Exception {
67: transaction.rollback();
68: session.close();
69: }
70: }
|