KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > legacy > StatisticsTest


1 //$Id: StatisticsTest.java,v 1.1 2004/09/26 05:18:25 oneovthafew Exp $
2
package org.hibernate.test.legacy;
3
4
5 import junit.framework.Test;
6 import junit.framework.TestSuite;
7 import junit.textui.TestRunner;
8
9 import org.hibernate.Query;
10 import org.hibernate.Session;
11 import org.hibernate.SessionFactory;
12 import org.hibernate.Transaction;
13 import org.hibernate.stat.Statistics;
14 import org.hibernate.test.TestCase;
15
16 /**
17  * @author Emmanuel Bernard
18  */

19 public class StatisticsTest extends TestCase {
20
21     public StatisticsTest(String JavaDoc x) {
22         super(x);
23     }
24     
25     public void testSessionStats() throws Exception JavaDoc {
26         
27         SessionFactory sf = getSessions();
28         Statistics stats = sf.getStatistics();
29         boolean isStats = stats.isStatisticsEnabled();
30         stats.clear();
31         stats.setStatisticsEnabled(true);
32         Session s = sf.openSession();
33         assertEquals( 1, stats.getSessionOpenCount() );
34         s.close();
35         assertEquals( 1, stats.getSessionCloseCount() );
36         s = sf.openSession();
37         Transaction tx = s.beginTransaction();
38         A a = new A();
39         a.setName("mya");
40         s.save(a);
41         a.setName("b");
42         tx.commit();
43         s.close();
44         assertEquals( 1, stats.getFlushCount() );
45         s = sf.openSession();
46         tx = s.beginTransaction();
47         String JavaDoc hql = "from " + A.class.getName();
48         Query q = s.createQuery(hql);
49         q.list();
50         tx.commit();
51         s.close();
52         assertEquals(1, stats.getQueryExecutionCount() );
53         assertEquals(1, stats.getQueryStatistics(hql).getExecutionCount() );
54         
55         stats.setStatisticsEnabled(isStats);
56     }
57     
58     public String JavaDoc[] getMappings() {
59         return new String JavaDoc[] { "legacy/ABC.hbm.xml", "legacy/ABCExtends.hbm.xml" };
60     }
61
62     public static Test suite() {
63         return new TestSuite(StatisticsTest.class);
64     }
65     
66     /**
67      * @see org.hibernate.test.TestCase#getMappings()
68      */

69     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
70         TestRunner.run( suite() );
71     }
72
73 }
74
Popular Tags