Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/hibernate/test/sqlinterceptor/SQLInterceptorTest.java


1   // $Id$
2   package org.hibernate.test.sqlinterceptor;
3   
4   import java.util.ArrayList;
5   import java.util.List;
6   
7   import junit.framework.Test;
8   import junit.framework.TestSuite;
9   
10  import org.hibernate.EmptyInterceptor;
11  import org.hibernate.Session;
12  import org.hibernate.test.TestCase;
13  
14  /**
15   * Implementation of SQLExceptionConversionTest.
16   *
17   * @author Steve Ebersole
18   */
19  public class SQLInterceptorTest extends TestCase {
20  
21    public SQLInterceptorTest(String name) {
22      super(name);
23    }
24  
25    protected String[] getMappings() {
26      return new String[] {"sqlinterceptor/User.hbm.xml"};
27    }
28  
29    static class SQLInterceptor extends EmptyInterceptor {
30      
31      List preparedSQL = new ArrayList();
32      
33      public String onPrepareStatement(String sql) {
34        preparedSQL.add(sql);
35        return "/* sqlinterceptor */ " + sql;
36      }
37    }
38    
39    public void testSqlMutation() throws Exception {
40      
41      SQLInterceptor interceptor = new SQLInterceptor();
42      Session session = openSession(interceptor);
43      
44      User user = new User();
45      user.setUsername("Max");
46      
47      session.save(user);
48  
49      session.close();
50      
51      assertEquals(interceptor.preparedSQL.size(),2); // insert and identity.
52    }
53  
54    public static Test suite() {
55      return new TestSuite(SQLInterceptorTest.class);
56    }
57  }