HHH-10201 - Added test cases.
This commit is contained in:
parent
0d8db10fcb
commit
42fe168056
|
@ -16,8 +16,12 @@ import org.hibernate.envers.test.Priority;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
||||
public abstract class AbstractCollectionChangeTest extends BaseEnversFunctionalTestCase {
|
||||
protected Integer personId;
|
||||
protected Integer parentId;
|
||||
protected Integer houseId;
|
||||
|
||||
@Override
|
||||
protected void addSettings(Map settings) {
|
||||
|
@ -28,13 +32,17 @@ public abstract class AbstractCollectionChangeTest extends BaseEnversFunctionalT
|
|||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {Person.class, Name.class};
|
||||
return new Class[] {Person.class, Name.class, Parent.class, Child.class, House.class};
|
||||
}
|
||||
|
||||
protected abstract String getCollectionChangeValue();
|
||||
|
||||
protected abstract List<Integer> getExpectedPersonRevisions();
|
||||
|
||||
protected abstract List<Integer> getExpectedParentRevisions();
|
||||
|
||||
protected abstract List<Integer> getExpectedHouseRevisions();
|
||||
|
||||
@Test
|
||||
@Priority(10)
|
||||
public void initData() {
|
||||
|
@ -64,6 +72,43 @@ public abstract class AbstractCollectionChangeTest extends BaseEnversFunctionalT
|
|||
|
||||
personId = p.getId();
|
||||
|
||||
// Rev 4
|
||||
session.getTransaction().begin();
|
||||
Child child1 = new Child();
|
||||
Parent parent = new Parent();
|
||||
parent.setName( "P1" );
|
||||
child1.setParent( parent );
|
||||
parent.getChildren().add( child1 );
|
||||
session.saveOrUpdate( child1 );
|
||||
session.saveOrUpdate( parent );
|
||||
session.getTransaction().commit();
|
||||
|
||||
// Rev 5
|
||||
session.getTransaction().begin();
|
||||
Child child2 = new Child();
|
||||
parent.getChildren().add( child2 );
|
||||
child2.setParent( parent );
|
||||
session.saveOrUpdate( child2 );
|
||||
session.saveOrUpdate( parent );
|
||||
session.getTransaction().commit();
|
||||
|
||||
parentId = parent.getId();
|
||||
|
||||
// Rev 6
|
||||
session.getTransaction().begin();
|
||||
House house = new House();
|
||||
house.getColors().add( "Red" );
|
||||
session.saveOrUpdate( house );
|
||||
session.getTransaction().commit();
|
||||
|
||||
// Rev 7
|
||||
session.getTransaction().begin();
|
||||
house.getColors().add( "Blue" );
|
||||
session.saveOrUpdate( house );
|
||||
session.getTransaction().commit();
|
||||
|
||||
houseId = house.getId();
|
||||
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
@ -71,4 +116,16 @@ public abstract class AbstractCollectionChangeTest extends BaseEnversFunctionalT
|
|||
public void testPersonRevisionCount() {
|
||||
assert getAuditReader().getRevisions( Person.class, personId ).equals( getExpectedPersonRevisions() );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10201")
|
||||
public void testParentRevisionCount() {
|
||||
assert getAuditReader().getRevisions( Parent.class, parentId ).equals( getExpectedParentRevisions() );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10201")
|
||||
public void testHouseRevisionCount() {
|
||||
assert getAuditReader().getRevisions( House.class, houseId ).equals( getExpectedHouseRevisions() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.envers.test.integration.collection.norevision;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* @author Chris Cranford
|
||||
*/
|
||||
@Entity
|
||||
@Audited
|
||||
public class Child {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
private String name;
|
||||
@ManyToOne
|
||||
private Parent parent;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Parent getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(Parent parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
}
|
|
@ -18,4 +18,14 @@ public class CollectionChangeNoRevisionTest extends AbstractCollectionChangeTest
|
|||
protected List<Integer> getExpectedPersonRevisions() {
|
||||
return Arrays.asList( 1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Integer> getExpectedParentRevisions() {
|
||||
return Arrays.asList( 4 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Integer> getExpectedHouseRevisions() {
|
||||
return Arrays.asList( 6, 7 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,4 +19,14 @@ public class CollectionChangeRevisionTest extends AbstractCollectionChangeTest {
|
|||
protected List<Integer> getExpectedPersonRevisions() {
|
||||
return Arrays.asList( 1, 3 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Integer> getExpectedParentRevisions() {
|
||||
return Arrays.asList( 4, 5 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Integer> getExpectedHouseRevisions() {
|
||||
return Arrays.asList( 6, 7 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.envers.test.integration.collection.norevision;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* @author Chris Cranford
|
||||
*/
|
||||
@Entity
|
||||
@Audited
|
||||
public class House {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
@ElementCollection
|
||||
private List<String> colors = new ArrayList<>();
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<String> getColors() {
|
||||
return colors;
|
||||
}
|
||||
|
||||
public void setColors(List<String> colors) {
|
||||
this.colors = colors;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.envers.test.integration.collection.norevision;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* @author Chris Cranford
|
||||
*/
|
||||
@Entity
|
||||
@Audited
|
||||
public class Parent {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
private String name;
|
||||
@OneToMany(mappedBy = "parent")
|
||||
private List<Child> children = new ArrayList<>();
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Child> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<Child> children) {
|
||||
this.children = children;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue