~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to test/org/hibernate/test/ops/DeleteTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hibernate.test.ops;
 
2
 
 
3
import junit.framework.Test;
 
4
 
 
5
import org.hibernate.Session;
 
6
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
 
7
 
 
8
/**
 
9
 * {@inheritDoc}
 
10
 *
 
11
 * @author Steve Ebersole
 
12
 */
 
13
public class DeleteTest extends AbstractOperationTestCase {
 
14
        public DeleteTest(String name) {
 
15
                super( name );
 
16
        }
 
17
 
 
18
        public static Test suite() {
 
19
                return new FunctionalTestClassTestSuite( DeleteTest.class );
 
20
        }
 
21
 
 
22
        public void testDeleteVersionedWithCollectionNoUpdate() {
 
23
                // test adapted from HHH-1564...
 
24
                Session s = openSession();
 
25
                s.beginTransaction();
 
26
                VersionedEntity c = new VersionedEntity( "c1", "child-1" );
 
27
                VersionedEntity p = new VersionedEntity( "root", "root");
 
28
                p.getChildren().add( c );
 
29
                c.setParent( p );
 
30
                s.save( p );
 
31
                s.getTransaction().commit();
 
32
                s.close();
 
33
 
 
34
                clearCounts();
 
35
 
 
36
                s = openSession();
 
37
                s.beginTransaction();
 
38
        VersionedEntity loadedParent = ( VersionedEntity ) s.get( VersionedEntity.class, "root" );
 
39
        s.delete( loadedParent );
 
40
                s.getTransaction().commit();
 
41
        s.close();
 
42
 
 
43
                assertInsertCount( 0 );
 
44
                assertUpdateCount( 0 );
 
45
                assertDeleteCount( 2 );
 
46
        }
 
47
 
 
48
        public void testNoUpdateOnDelete() {
 
49
                Session s = openSession();
 
50
        s.beginTransaction();
 
51
                Node node = new Node( "test" );
 
52
                s.persist( node );
 
53
                s.getTransaction().commit();
 
54
                s.close();
 
55
 
 
56
                clearCounts();
 
57
 
 
58
                s = openSession();
 
59
                s.beginTransaction();
 
60
                s.delete( node );
 
61
                s.getTransaction().commit();
 
62
                s.close();
 
63
 
 
64
                assertUpdateCount( 0 );
 
65
                assertInsertCount( 0 );
 
66
        }
 
67
 
 
68
        public void testNoUpdateOnDeleteWithCollection() {
 
69
                Session s = openSession();
 
70
        s.beginTransaction();
 
71
                Node parent = new Node( "parent" );
 
72
                Node child = new Node( "child" );
 
73
                parent.getCascadingChildren().add( child );
 
74
                s.persist( parent );
 
75
                s.getTransaction().commit();
 
76
                s.close();
 
77
 
 
78
                clearCounts();
 
79
 
 
80
                s = openSession();
 
81
                s.beginTransaction();
 
82
                parent = ( Node ) s.get( Node.class, "parent" );
 
83
                s.delete( parent );
 
84
                s.getTransaction().commit();
 
85
                s.close();
 
86
 
 
87
                assertUpdateCount( 0 );
 
88
                assertInsertCount( 0 );
 
89
                assertDeleteCount( 2 );
 
90
        }
 
91
}