HHH-5588: Improve support for entityNames in envers

Extending test cases for testing resolution for entityNames for entities retrieved previously by envers
This commit is contained in:
Hernan 2010-11-15 00:20:01 -02:00 committed by adamw
parent 80ef651e4a
commit c981bef5c1
17 changed files with 1323 additions and 1003 deletions

View File

@ -1,51 +1,51 @@
package org.hibernate.envers.test.integration.entityNames.auditedEntity;
import org.hibernate.envers.Audited;
/**
* @author Hern<EFBFBD>n Chanfreau
*
*/
@Audited
public class Person {
private long id;
private String name;
private int age;
public Person(){ }
public Person(String name, int age){
this.name = name;
this.age = age;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
package org.hibernate.envers.test.integration.entityNames.auditedEntity;
import org.hibernate.envers.Audited;
/**
* @author Hern&aacute;n Chanfreau
*
*/
@Audited
public class Person {
private long id;
private String name;
private int age;
public Person(){ }
public Person(String name, int age){
this.name = name;
this.age = age;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}

View File

@ -1,99 +1,149 @@
package org.hibernate.envers.test.integration.entityNames.auditedEntity;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import org.hibernate.MappingException;
import org.hibernate.envers.test.AbstractSessionTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author Hern<EFBFBD>n Chanfreau
*
*/
public class ReadEntityWhtiEntityNameTest extends AbstractSessionTest{
private long id_pers1;
private long id_pers2;
private long id_pers3;
protected void initMappings() throws MappingException, URISyntaxException {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/auditedEntity/mappings.hbm.xml");
config.addFile(new File(url.toURI()));
}
@BeforeClass(dependsOnMethods = "init")
public void initData() {
newSessionFactory();
Person pers1 = new Person("Hernan", 28);
Person pers2 = new Person("Leandro", 29);
Person pers3 = new Person("Barba", 30);
//REV 1
getSession().getTransaction().begin();
getSession().persist("Personaje",pers1);
id_pers1 = pers1.getId();
getSession().getTransaction().commit();
//REV 2
getSession().getTransaction().begin();
pers1 = (Person)getSession().get("Personaje", id_pers1);
pers1.setAge(29);
getSession().persist("Personaje",pers1);
getSession().persist("Personaje",pers2);
id_pers2 = pers2.getId();
getSession().getTransaction().commit();
//REV
getSession().getTransaction().begin();
pers1 = (Person)getSession().get("Personaje", id_pers1);
pers1.setName("Hernan David");
pers2 = (Person)getSession().get("Personaje", id_pers2);
pers2.setAge(30);
getSession().persist("Personaje",pers1);
getSession().persist("Personaje",pers2);
getSession().persist("Personaje",pers3);
id_pers3 = pers3.getId();
getSession().getTransaction().commit();
}
@Test
public void testRetrieveRevisionsWithEntityName() {
List<Number> pers1Revs = getAuditReader().getRevisions(Person.class,"Personaje", id_pers1);
List<Number> pers2Revs = getAuditReader().getRevisions(Person.class,"Personaje", id_pers2);
List<Number> pers3Revs = getAuditReader().getRevisions(Person.class,"Personaje", id_pers3);
assert(pers1Revs.size() == 3);
assert(pers2Revs.size() == 2);
assert(pers3Revs.size() == 1);
}
@Test
public void testRetrieveAuditedEntityWithEntityName() {
Person Person1 = getAuditReader().find(Person.class, "Personaje", id_pers1, 1);
Person Person2 = getAuditReader().find(Person.class, "Personaje", id_pers1, 2);
Person Person3 = getAuditReader().find(Person.class, "Personaje", id_pers1, 3);
System.out.println("Revision 1:");
System.out.println(" > Name: " + Person1.getName());
System.out.println(" > Age: " + Person1.getAge());
System.out.println("Revision 2:");
System.out.println(" > Name: " + Person2.getName());
System.out.println(" > Age: " + Person2.getAge());
System.out.println("Revision 3:");
System.out.println(" > Name: " + Person3.getName());
System.out.println(" > Age: " + Person3.getAge());
}
}
package org.hibernate.envers.test.integration.entityNames.auditedEntity;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import org.hibernate.MappingException;
import org.hibernate.envers.test.AbstractSessionTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author Hern&aacute;n Chanfreau
*
*/
@Test(sequential=true)
public class ReadEntityWhtiEntityNameTest extends AbstractSessionTest{
private long id_pers1;
private long id_pers2;
private long id_pers3;
private Person person1_1;
private Person person1_2;
private Person person1_3;
private Person currentPers1;
protected void initMappings() throws MappingException, URISyntaxException {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/auditedEntity/mappings.hbm.xml");
config.addFile(new File(url.toURI()));
}
/**
* The test needs to run with the same session and auditReader.
*/
@Override
public void newSessionFactory() {
if (getSession() == null) {
super.newSessionFactory();
}
}
@BeforeClass(dependsOnMethods = "init")
public void initData() {
newSessionFactory();
Person pers1 = new Person("Hernan", 28);
Person pers2 = new Person("Leandro", 29);
Person pers3 = new Person("Barba", 30);
//REV 1
getSession().getTransaction().begin();
getSession().persist("Personaje",pers1);
id_pers1 = pers1.getId();
getSession().getTransaction().commit();
//REV 2
getSession().getTransaction().begin();
pers1 = (Person)getSession().get("Personaje", id_pers1);
pers1.setAge(29);
getSession().persist("Personaje",pers1);
getSession().persist("Personaje",pers2);
id_pers2 = pers2.getId();
getSession().getTransaction().commit();
//REV
getSession().getTransaction().begin();
pers1 = (Person)getSession().get("Personaje", id_pers1);
pers1.setName("Hernan David");
pers2 = (Person)getSession().get("Personaje", id_pers2);
pers2.setAge(30);
getSession().persist("Personaje",pers1);
getSession().persist("Personaje",pers2);
getSession().persist("Personaje",pers3);
id_pers3 = pers3.getId();
getSession().getTransaction().commit();
getSession().getTransaction().begin();
currentPers1 = (Person)getSession().get("Personaje", id_pers1);
getSession().getTransaction().commit();
}
@Test
public void testRetrieveRevisionsWithEntityName() {
List<Number> pers1Revs = getAuditReader().getRevisions(Person.class,"Personaje", id_pers1);
List<Number> pers2Revs = getAuditReader().getRevisions(Person.class,"Personaje", id_pers2);
List<Number> pers3Revs = getAuditReader().getRevisions(Person.class,"Personaje", id_pers3);
assert(pers1Revs.size() == 3);
assert(pers2Revs.size() == 2);
assert(pers3Revs.size() == 1);
}
@Test(dependsOnMethods="testRetrieveRevisionsWithEntityName")
public void testRetrieveAuditedEntityWithEntityName() {
person1_1 = getAuditReader().find(Person.class, "Personaje", id_pers1, 1);
person1_2 = getAuditReader().find(Person.class, "Personaje", id_pers1, 2);
person1_3 = getAuditReader().find(Person.class, "Personaje", id_pers1, 3);
person1_1.getName();
person1_1.getAge();
person1_2.getName();
person1_2.getAge();
person1_3.getName();
person1_3.getAge();
}
@Test(dependsOnMethods="testRetrieveAuditedEntityWithEntityName")
public void testObtainEntityNameAuditedEntityWithEntityName() {
String currentPers1EN = getSession().getEntityName(currentPers1);
String person1EN = getAuditReader().getEntityName(person1_1.getId(), 1, person1_1);
assert (currentPers1EN.equals(person1EN));
String person2EN = getAuditReader().getEntityName(person1_2.getId(), 2, person1_2);
assert (currentPers1EN.equals(person2EN));
String person3EN = getAuditReader().getEntityName(person1_3.getId(), 3, person1_3);
assert (currentPers1EN.equals(person3EN));
}
@Test(dependsOnMethods="testObtainEntityNameAuditedEntityWithEntityName")
public void testFindHistoricAndCurrentForAuditedEntityWithEntityName() {
// force a new session and AR
super.newSessionFactory();
person1_1 = getAuditReader().find(Person.class, "Personaje", id_pers1, 1);
person1_2 = getAuditReader().find(Person.class, "Personaje", id_pers1, 2);
person1_3 = getAuditReader().find(Person.class, "Personaje", id_pers1, 3);
person1_1.getName();
person1_1.getAge();
person1_2.getName();
person1_2.getAge();
person1_3.getName();
person1_3.getAge();
}
}

View File

@ -5,7 +5,7 @@ import java.util.List;
import org.hibernate.envers.Audited;
/**
* @author Hern<EFBFBD>n Chanfreau
* @author Hern&aacute;n Chanfreau
*
*/

View File

@ -5,7 +5,7 @@ import java.util.List;
import org.hibernate.envers.Audited;
/**
* @author Hern<EFBFBD>n Chanfreau
* @author Hern&aacute;n Chanfreau
*
*/

View File

@ -1,99 +1,146 @@
package org.hibernate.envers.test.integration.entityNames.manyToManyAudited;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.MappingException;
import org.hibernate.envers.test.AbstractSessionTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author Hern<EFBFBD>n Chanfreau
*
*/
public class ReadEntityWithAuditedManyToManyTest extends AbstractSessionTest{
private long id_car1;
private long id_car2;
private long id_pers1;
protected void initMappings() throws MappingException, URISyntaxException {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/manyToManyAudited/mappings.hbm.xml");
config.addFile(new File(url.toURI()));
}
@BeforeClass(dependsOnMethods = "init")
public void initData() {
newSessionFactory();
Person pers1 = new Person("Hernan", 28);
Person pers2 = new Person("Leandro", 29);
Person pers3 = new Person("Barba", 32);
Person pers4 = new Person("Camomo", 15);
//REV 1
getSession().getTransaction().begin();
List<Person > owners = new ArrayList<Person>();
owners.add(pers1);
owners.add(pers2);
owners.add(pers3);
Car car1 = new Car(5, owners);
getSession().persist(car1);
getSession().getTransaction().commit();
id_pers1 = pers1.getId();
id_car1 = car1.getId();
owners = new ArrayList<Person>();
owners.add(pers2);
owners.add(pers3);
owners.add(pers4);
Car car2 = new Car(27, owners);
//REV 2
getSession().getTransaction().begin();
Person person1 = (Person)getSession().get("Personaje", id_pers1);
person1.setName("Hernan David");
person1.setAge(40);
getSession().persist(car1);
getSession().persist(car2);
getSession().getTransaction().commit();
id_car2 = car2.getId();
}
@Test
public void testObtainManyYoManyWithEntityName() {
Car car1 = getAuditReader().find(Car.class, id_car1, 2);
Car car2 = getAuditReader().find(Car.class, id_car2, 2);
System.out.println(" > Car: " + car1.getNumber());
System.out.println(" > Owners:");
for (Person owner : car1.getOwners()) {
System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
System.out.println(" > Cars owned:");
for (Car ownedCar : owner.getCars()) {
System.out.println(" o Car: " + ownedCar.getNumber());
}
}
System.out.println(" > Car: " + car2.getNumber());
System.out.println(" > Owners:");
for (Person owner : car2.getOwners()) {
System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
System.out.println(" > Cars owned:");
for (Car ownedCar : owner.getCars()) {
System.out.println(" o Car: " + ownedCar.getNumber());
}
}
}
}
package org.hibernate.envers.test.integration.entityNames.manyToManyAudited;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.MappingException;
import org.hibernate.envers.test.AbstractSessionTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author Hern&aacute;n Chanfreau
*
*/
@Test(sequential=true)
public class ReadEntityWithAuditedManyToManyTest extends AbstractSessionTest{
private long id_car1;
private long id_car2;
private long id_pers1;
private Person person1;
private Car car1;
private Person person1_1;
private Car car1_2;
protected void initMappings() throws MappingException, URISyntaxException {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/manyToManyAudited/mappings.hbm.xml");
config.addFile(new File(url.toURI()));
}
/**
* The test needs to run with the same session and auditReader.
*/
@Override
public void newSessionFactory() {
if (getSession() == null) {
super.newSessionFactory();
}
}
@BeforeClass(dependsOnMethods = "init")
public void initData() {
newSessionFactory();
Person pers1 = new Person("Hernan", 28);
Person pers2 = new Person("Leandro", 29);
Person pers3 = new Person("Barba", 32);
Person pers4 = new Person("Camomo", 15);
//REV 1
getSession().getTransaction().begin();
List<Person > owners = new ArrayList<Person>();
owners.add(pers1);
owners.add(pers2);
owners.add(pers3);
Car car1 = new Car(5, owners);
getSession().persist(car1);
getSession().getTransaction().commit();
id_pers1 = pers1.getId();
id_car1 = car1.getId();
owners = new ArrayList<Person>();
owners.add(pers2);
owners.add(pers3);
owners.add(pers4);
Car car2 = new Car(27, owners);
//REV 2
getSession().getTransaction().begin();
Person person1 = (Person)getSession().get("Personaje", id_pers1);
person1.setName("Hernan David");
person1.setAge(40);
getSession().persist(car1);
getSession().persist(car2);
getSession().getTransaction().commit();
id_car2 = car2.getId();
}
@Test
public void testObtainManyYoManyWithEntityName() {
car1_2 = getAuditReader().find(Car.class, id_car1, 2);
Car car2_2 = getAuditReader().find(Car.class, id_car2, 2);
for (Person owner : car1_2.getOwners()) {
for (Car ownedCar : owner.getCars()) {
ownedCar.getNumber();
}
}
for (Person owner : car2_2.getOwners()) {
for (Car ownedCar : owner.getCars()) {
ownedCar.getNumber();
}
}
car1 = (Car)getSession().get(Car.class, id_car1);
person1 = (Person)getSession().get("Personaje", id_pers1);
person1_1 = getAuditReader().find(Person.class, "Personaje", id_pers1, 1);
}
@Test(dependsOnMethods="testObtainManyYoManyWithEntityName")
public void testGetEntityNameManyYoManyWithEntityName() {
String currPerson1EN = getSession().getEntityName(person1);
String currCar1EN = getSession().getEntityName(car1);
String person1_1EN = getAuditReader().getEntityName(id_pers1, 1, person1_1);
assert(currPerson1EN.equals(person1_1EN));
String car1_2EN = getAuditReader().getEntityName(id_car1, 2, car1_2);
assert(currCar1EN.equals(car1_2EN));
}
@Test(dependsOnMethods="testGetEntityNameManyYoManyWithEntityName")
public void testFindHistoricAndCurrentForManyYoManyWithEntityName() {
//force new session and AR
super.newSessionFactory();
car1_2 = getAuditReader().find(Car.class, id_car1, 2);
Car car2_2 = getAuditReader().find(Car.class, id_car2, 2);
for (Person owner : car1_2.getOwners()) {
for (Car ownedCar : owner.getCars()) {
ownedCar.getNumber();
}
}
for (Person owner : car2_2.getOwners()) {
for (Car ownedCar : owner.getCars()) {
ownedCar.getNumber();
}
}
person1_1 = getAuditReader().find(Person.class, "Personaje", id_pers1, 1);
for (Car ownedCar : person1_1.getCars()) {
ownedCar.getNumber();
}
}
}

View File

@ -1,56 +1,56 @@
package org.hibernate.envers.test.integration.entityNames.oneToManyAudited;
import java.util.List;
import org.hibernate.envers.Audited;
/**
* @author Hern<EFBFBD>n Chanfreau
*
*/
@Audited
public class Car {
private long id;
private int number;
private List<Person> owners;
public Car() { }
public Car(int number, List<Person> owners) {
this.number = number;
this.owners = owners;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public List<Person> getOwners() {
return owners;
}
public void setOwners(List<Person> owners) {
this.owners = owners;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
}
package org.hibernate.envers.test.integration.entityNames.oneToManyAudited;
import java.util.List;
import org.hibernate.envers.Audited;
/**
* @author Hern&aacute;n Chanfreau
*
*/
@Audited
public class Car {
private long id;
private int number;
private List<Person> owners;
public Car() { }
public Car(int number, List<Person> owners) {
this.number = number;
this.owners = owners;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public List<Person> getOwners() {
return owners;
}
public void setOwners(List<Person> owners) {
this.owners = owners;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
}

View File

@ -1,51 +1,51 @@
package org.hibernate.envers.test.integration.entityNames.oneToManyAudited;
import org.hibernate.envers.Audited;
/**
* @author Hern<EFBFBD>n Chanfreau
*
*/
@Audited
public class Person {
private long id;
private String name;
private int age;
public Person(){ }
public Person(String name, int age){
this.name = name;
this.age = age;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
package org.hibernate.envers.test.integration.entityNames.oneToManyAudited;
import org.hibernate.envers.Audited;
/**
* @author Hern&aacute;n Chanfreau
*
*/
@Audited
public class Person {
private long id;
private String name;
private int age;
public Person(){ }
public Person(String name, int age){
this.name = name;
this.age = age;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}

View File

@ -1,89 +1,142 @@
package org.hibernate.envers.test.integration.entityNames.oneToManyAudited;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.MappingException;
import org.hibernate.envers.test.AbstractSessionTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author Hern<EFBFBD>n Chanfreau
*
*/
public class ReadEntityWithAuditedCollectionTest extends AbstractSessionTest{
private long id_car1;
private long id_car2;
private long id_pers1;
protected void initMappings() throws MappingException, URISyntaxException {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/oneToManyAudited/mappings.hbm.xml");
config.addFile(new File(url.toURI()));
}
@BeforeClass(dependsOnMethods = "init")
public void initData() {
newSessionFactory();
Person pers1 = new Person("Hernan", 28);
Person pers2 = new Person("Leandro", 29);
Person pers3 = new Person("Barba", 32);
Person pers4 = new Person("Camomo", 15);
List<Person > owners = new ArrayList<Person>();
owners.add(pers1);
owners.add(pers2);
Car car1 = new Car(5, owners);
//REV 1
getSession().getTransaction().begin();
getSession().persist(car1);
getSession().getTransaction().commit();
id_pers1 = pers1.getId();
id_car1 = car1.getId();
owners = new ArrayList<Person>();
owners.add(pers2);
owners.add(pers4);
Car car2 = new Car(27, owners);
//REV 2
getSession().getTransaction().begin();
Person person1 = (Person)getSession().get("Personaje", id_pers1);
person1.setName("Hernan David");
person1.setAge(40);
getSession().persist(car1);
getSession().persist(car2);
getSession().getTransaction().commit();
id_car2 = car2.getId();
}
@Test
public void testObtainCollectionWithEntityName() {
Car car1 = getAuditReader().find(Car.class, id_car1, 2);
Car car2 = getAuditReader().find(Car.class, id_car2, 2);
System.out.println(" > Car: " + car1.getNumber());
System.out.println(" > Owners:");
for (Person owner : car1.getOwners()) {
System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
}
System.out.println(" > Car: " + car2.getNumber());
System.out.println(" > Owners:");
for (Person owner : car2.getOwners()) {
System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
}
}
}
package org.hibernate.envers.test.integration.entityNames.oneToManyAudited;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.MappingException;
import org.hibernate.envers.test.AbstractSessionTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author Hern&aacute;n Chanfreau
*
*/
@Test(sequential=true)
public class ReadEntityWithAuditedCollectionTest extends AbstractSessionTest{
private long id_car1;
private long id_car2;
private Car currentCar1;
private Person currentPerson1;
private long id_pers1;
private Car car1_1;
private Person person1_1;
protected void initMappings() throws MappingException, URISyntaxException {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/oneToManyAudited/mappings.hbm.xml");
config.addFile(new File(url.toURI()));
}
/**
* The test needs to run with the same session and auditReader.
*/
@Override
public void newSessionFactory() {
if (getSession() == null) {
super.newSessionFactory();
}
}
@BeforeClass(dependsOnMethods = "init")
public void initData() {
newSessionFactory();
Person pers1 = new Person("Hernan", 28);
Person pers2 = new Person("Leandro", 29);
Person pers4 = new Person("Camomo", 15);
List<Person > owners = new ArrayList<Person>();
owners.add(pers1);
owners.add(pers2);
Car car1 = new Car(5, owners);
//REV 1
getSession().getTransaction().begin();
getSession().persist(car1);
getSession().getTransaction().commit();
id_pers1 = pers1.getId();
id_car1 = car1.getId();
owners = new ArrayList<Person>();
owners.add(pers2);
owners.add(pers4);
Car car2 = new Car(27, owners);
//REV 2
getSession().getTransaction().begin();
Person person1 = (Person)getSession().get("Personaje", id_pers1);
person1.setName("Hernan David");
person1.setAge(40);
getSession().persist(car1);
getSession().persist(car2);
getSession().getTransaction().commit();
id_car2 = car2.getId();
}
@Test
public void testObtainAuditedCollectionWithEntityName() {
currentCar1 = (Car)getSession().get(Car.class, id_car1);
currentPerson1 = (Person)getSession().get("Personaje", id_pers1);
car1_1 = getAuditReader().find(Car.class, id_car1, 2);
Car car2 = getAuditReader().find(Car.class, id_car2, 2);
for (Person owner : car1_1.getOwners()) {
owner.getName();
owner.getAge();
}
for (Person owner : car2.getOwners()) {
owner.getName();
owner.getAge();
}
}
@Test(dependsOnMethods="testObtainAuditedCollectionWithEntityName")
public void testObtainEntityNameAuditedCollectionWithEntityName() {
person1_1 = getAuditReader().find(Person.class,"Personaje", id_pers1, 1);
String currCar1EN = getSession().getEntityName(currentCar1);
String currPerson1EN = getSession().getEntityName(currentPerson1);
String car1_1EN = getAuditReader().getEntityName(id_car1, 2, car1_1);
assert(currCar1EN.equals(car1_1EN));
String person1_1EN = getAuditReader().getEntityName(id_pers1, 1, person1_1);
assert(currPerson1EN.equals(person1_1EN));
}
@Test(dependsOnMethods="testObtainEntityNameAuditedCollectionWithEntityName")
public void testObtainAuditedCollectionWithEntityNameWithNewSession() {
// force a new session and AR
super.newSessionFactory();
Car car1_1 = getAuditReader().find(Car.class, id_car1, 2);
Car car2 = getAuditReader().find(Car.class, id_car2, 2);
Person person1_1 = getAuditReader().find(Person.class,"Personaje", id_pers1, 1);
for (Person owner : car1_1.getOwners()) {
owner.getName();
owner.getAge();
}
for (Person owner : car2.getOwners()) {
owner.getName();
owner.getAge();
}
person1_1.getName();
person1_1.getAge();
}
}

View File

@ -1,58 +1,58 @@
package org.hibernate.envers.test.integration.entityNames.oneToManyNotAudited;
import java.util.List;
import org.hibernate.envers.Audited;
import org.hibernate.envers.RelationTargetAuditMode;
/**
* @author Hern<EFBFBD>n Chanfreau
*
*/
public class Car {
private long id;
private int number;
private List<Person> owners;
public Car() { }
public Car(int number, List<Person> owners) {
this.number = number;
this.owners = owners;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED)
public List<Person> getOwners() {
return owners;
}
public void setOwners(List<Person> owners) {
this.owners = owners;
}
@Audited
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
}
package org.hibernate.envers.test.integration.entityNames.oneToManyNotAudited;
import java.util.List;
import org.hibernate.envers.Audited;
import org.hibernate.envers.RelationTargetAuditMode;
/**
* @author Hern&aacute;n Chanfreau
*
*/
public class Car {
private long id;
private int number;
private List<Person> owners;
public Car() { }
public Car(int number, List<Person> owners) {
this.number = number;
this.owners = owners;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED)
public List<Person> getOwners() {
return owners;
}
public void setOwners(List<Person> owners) {
this.owners = owners;
}
@Audited
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
}

View File

@ -1,48 +1,48 @@
package org.hibernate.envers.test.integration.entityNames.oneToManyNotAudited;
/**
* @author Hern<EFBFBD>n Chanfreau
*
*/
public class Person {
private long id;
private String name;
private int age;
public Person(){ }
public Person(String name, int age){
this.name = name;
this.age = age;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
package org.hibernate.envers.test.integration.entityNames.oneToManyNotAudited;
/**
* @author Hern&aacute;n Chanfreau
*
*/
public class Person {
private long id;
private String name;
private int age;
public Person(){ }
public Person(String name, int age){
this.name = name;
this.age = age;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}

View File

@ -1,84 +1,155 @@
package org.hibernate.envers.test.integration.entityNames.oneToManyNotAudited;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.MappingException;
import org.hibernate.envers.test.AbstractSessionTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class ReadEntityWithAuditedCollectionTest extends AbstractSessionTest{
private long id_car1;
private long id_car2;
private long id_pers1;
protected void initMappings() throws MappingException, URISyntaxException {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/oneToManyNotAudited/mappings.hbm.xml");
config.addFile(new File(url.toURI()));
}
@BeforeClass(dependsOnMethods = "init")
public void initData() {
newSessionFactory();
Person pers1 = new Person("Hernan", 28);
Person pers2 = new Person("Leandro", 29);
Person pers3 = new Person("Barba", 32);
Person pers4 = new Person("Camomo", 15);
List<Person > owners = new ArrayList<Person>();
owners.add(pers1);
owners.add(pers2);
Car car1 = new Car(5, owners);
//REV 1
getSession().getTransaction().begin();
getSession().persist(car1);
getSession().getTransaction().commit();
id_pers1 = pers1.getId();
id_car1 = car1.getId();
owners = new ArrayList<Person>();
owners.add(pers2);
owners.add(pers4);
Car car2 = new Car(27, owners);
//REV 2
getSession().getTransaction().begin();
Person person1 = (Person)getSession().get("Personaje", id_pers1);
person1.setName("Hernan David");
person1.setAge(40);
getSession().persist(car1);
getSession().persist(car2);
getSession().getTransaction().commit();
id_car2 = car2.getId();
}
@Test
public void testObtainCollectionWithEntityNameAndNotAuditedMode() {
Car car1 = getAuditReader().find(Car.class, id_car1, 2);
Car car2 = getAuditReader().find(Car.class, id_car2, 2);
System.out.println(" > Car: " + car1.getNumber());
System.out.println(" > Owners:");
for (Person owner : car1.getOwners()) {
System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
}
System.out.println(" > Car: " + car2.getNumber());
System.out.println(" > Owners:");
for (Person owner : car2.getOwners()) {
System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
}
}
}
package org.hibernate.envers.test.integration.entityNames.oneToManyNotAudited;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.MappingException;
import org.hibernate.envers.test.AbstractSessionTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author Hern&aacute;n Chanfreau
*
*/
@Test(sequential=true)
public class ReadEntityWithAuditedCollectionTest extends AbstractSessionTest{
private long id_car1;
private long id_car2;
private Car currentCar1;
private Person currentPerson1;
private long id_pers1;
private Car car1_1;
private Person person1_1;
protected void initMappings() throws MappingException, URISyntaxException {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/oneToManyNotAudited/mappings.hbm.xml");
config.addFile(new File(url.toURI()));
}
/**
* The test needs to run with the same session and auditReader.
*/
@Override
public void newSessionFactory() {
if (getSession() == null) {
super.newSessionFactory();
}
}
@BeforeClass(dependsOnMethods = "init")
public void initData() {
newSessionFactory();
Person pers1 = new Person("Hernan", 28);
Person pers2 = new Person("Leandro", 29);
Person pers4 = new Person("Camomo", 15);
List<Person > owners = new ArrayList<Person>();
owners.add(pers1);
owners.add(pers2);
Car car1 = new Car(5, owners);
//REV 1
getSession().getTransaction().begin();
getSession().persist(car1);
getSession().getTransaction().commit();
id_pers1 = pers1.getId();
id_car1 = car1.getId();
owners = new ArrayList<Person>();
owners.add(pers2);
owners.add(pers4);
Car car2 = new Car(27, owners);
//REV 2
getSession().getTransaction().begin();
Person person1 = (Person)getSession().get("Personaje", id_pers1);
person1.setName("Hernan David");
person1.setAge(40);
getSession().persist(car1);
getSession().persist(car2);
getSession().getTransaction().commit();
id_car2 = car2.getId();
}
@Test
public void testObtainCollectionWithEntityNameAndNotAuditedMode() {
currentCar1 = (Car)getSession().get(Car.class, id_car1);
currentPerson1 = (Person)getSession().get("Personaje", id_pers1);
car1_1 = getAuditReader().find(Car.class, id_car1, 2);
Car car2 = getAuditReader().find(Car.class, id_car2, 2);
for (Person owner : car1_1.getOwners()) {
owner.getName();
owner.getAge();
}
for (Person owner : car2.getOwners()) {
owner.getName();
owner.getAge();
}
}
@Test(dependsOnMethods="testObtainCollectionWithEntityNameAndNotAuditedMode")
public void testObtainEntityNameCollectionWithEntityNameAndNotAuditedMode() {
if(getAuditReader().isEntityNameNotAudited("Personaje")) {
person1_1 = (Person)getSession().get("Personaje", id_pers1);
} else {
assert(false);
}
String currCar1EN = getSession().getEntityName(currentCar1);
String currPerson1EN = getSession().getEntityName(currentPerson1);
String car1_1EN = getAuditReader().getEntityName(id_car1, 2, car1_1);
assert(currCar1EN.equals(car1_1EN));
String person1_1EN = getSession().getEntityName(person1_1);
assert(currPerson1EN.equals(person1_1EN));
}
@Test(dependsOnMethods="testObtainEntityNameCollectionWithEntityNameAndNotAuditedMode")
public void testObtainCollectionWithEntityNameAndNotAuditedModeWithNewSession() {
// force new session and AR
super.newSessionFactory();
Car car1_1 = getAuditReader().find(Car.class, id_car1, 2);
Car car2 = getAuditReader().find(Car.class, id_car2, 2);
for (Person owner : car1_1.getOwners()) {
owner.getName();
owner.getAge();
}
for (Person owner : car2.getOwners()) {
owner.getName();
owner.getAge();
}
if(getAuditReader().isEntityNameNotAudited("Personaje")) {
person1_1 = (Person)getSession().get("Personaje", id_pers1);
} else {
assert(false);
}
person1_1.getName();
person1_1.getAge();
}
}

View File

@ -1,54 +1,54 @@
package org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited;
import org.hibernate.envers.Audited;
/**
* @author Hern<EFBFBD>n Chanfreau
*
*/
@Audited
public class Car {
private long id;
private int number;
private Person owner;
public Car() { }
public Car(int number, Person owner) {
this.number = number;
this.owner = owner;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Person getOwner() {
return owner;
}
public void setOwner(Person owner) {
this.owner = owner;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
}
package org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited;
import org.hibernate.envers.Audited;
/**
* @author Hern&aacute;n Chanfreau
*
*/
@Audited
public class Car {
private long id;
private int number;
private Person owner;
public Car() { }
public Car(int number, Person owner) {
this.number = number;
this.owner = owner;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Person getOwner() {
return owner;
}
public void setOwner(Person owner) {
this.owner = owner;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
}

View File

@ -1,51 +1,51 @@
package org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited;
import org.hibernate.envers.Audited;
/**
* @author Hern<EFBFBD>n Chanfreau
*
*/
@Audited
public class Person {
private long id;
private String name;
private int age;
public Person(){ }
public Person(String name, int age){
this.name = name;
this.age = age;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
package org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited;
import org.hibernate.envers.Audited;
/**
* @author Hern&aacute;n Chanfreau
*
*/
@Audited
public class Person {
private long id;
private String name;
private int age;
public Person(){ }
public Person(String name, int age){
this.name = name;
this.age = age;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}

View File

@ -1,77 +1,130 @@
package org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import org.hibernate.MappingException;
import org.hibernate.envers.test.AbstractSessionTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author Hern<EFBFBD>n Chanfreau
*
*/
public class ReadEntityAssociatedAuditedTest extends AbstractSessionTest{
private long id_car1;
private long id_car2;
private long id_pers1;
private long id_pers2;
protected void initMappings() throws MappingException, URISyntaxException {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml");
config.addFile(new File(url.toURI()));
}
@BeforeClass(dependsOnMethods = "init")
public void initData() {
newSessionFactory();
Person pers1 = new Person("Hernan", 15);
Person pers2 = new Person("Leandro", 19);
Car car1 = new Car(1, pers1);
Car car2 = new Car(2, pers2);
//REV 1
getSession().getTransaction().begin();
getSession().persist("Personaje",pers1);
getSession().persist(car1);
getSession().getTransaction().commit();
id_car1 = car1.getId();
id_pers1 = pers1.getId();
//REV 2
getSession().getTransaction().begin();
pers1.setAge(50);
getSession().persist("Personaje", pers1);
getSession().persist("Personaje", pers2);
getSession().persist(car2);
getSession().getTransaction().commit();
id_car2 = car2.getId();
id_pers2 = pers2.getId();
}
@Test
public void testGetAssociationWithEntityName() {
Person person1 = (Person)getSession().get("Personaje", id_pers1);
Car car1 = getAuditReader().find(Car.class, id_car1, 1);
Person person1_1 = car1.getOwner();
assert(person1.getAge() != person1_1.getAge());
Person person2 = (Person)getSession().get("Personaje", id_pers2);
Car car2 = getAuditReader().find(Car.class, id_car2, 2);
Person person2_1 = car2.getOwner();
assert(person2.getAge() == person2_1.getAge());
}
}
package org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import org.hibernate.MappingException;
import org.hibernate.envers.test.AbstractSessionTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author Hern&aacute;n Chanfreau
*
*/
@Test(sequential=true)
public class ReadEntityAssociatedAuditedTest extends AbstractSessionTest{
private long id_car1;
private long id_car2;
private Car currentCar1;
private Car car1;
private long id_pers1;
private long id_pers2;
private Person currentPerson1;
private Person person1;
protected void initMappings() throws MappingException, URISyntaxException {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml");
config.addFile(new File(url.toURI()));
}
/**
* The test needs to run with the same session and auditReader.
*/
@Override
public void newSessionFactory() {
if (getSession() == null) {
super.newSessionFactory();
}
}
@BeforeClass(dependsOnMethods = "init")
public void initData() {
newSessionFactory();
Person pers1 = new Person("Hernan", 15);
Person pers2 = new Person("Leandro", 19);
Car car1 = new Car(1, pers1);
Car car2 = new Car(2, pers2);
//REV 1
getSession().getTransaction().begin();
getSession().persist("Personaje",pers1);
getSession().persist(car1);
getSession().getTransaction().commit();
id_car1 = car1.getId();
id_pers1 = pers1.getId();
//REV 2
getSession().getTransaction().begin();
pers1.setAge(50);
getSession().persist("Personaje", pers1);
getSession().persist("Personaje", pers2);
getSession().persist(car2);
getSession().getTransaction().commit();
id_car2 = car2.getId();
id_pers2 = pers2.getId();
getSession().getTransaction().begin();
currentCar1 = (Car)getSession().get(Car.class, id_car1);
currentPerson1 = (Person)getSession().get("Personaje", id_pers1);
getSession().getTransaction().commit();
}
@Test
public void testGetAssociationWithEntityName() {
car1 = getAuditReader().find(Car.class, id_car1, 1);
person1 = car1.getOwner();
assert(currentPerson1.getAge() != person1.getAge());
Person person2 = (Person)getSession().get("Personaje", id_pers2);
Car car2 = getAuditReader().find(Car.class, id_car2, 2);
Person person2_1 = car2.getOwner();
assert(person2.getAge() == person2_1.getAge());
}
@Test(dependsOnMethods="testGetAssociationWithEntityName")
public void testObtainEntityNameAssociationWithEntityName() {
String currentCar1EN = getSession().getEntityName(currentCar1);
String currentPerson1EN = getSession().getEntityName(currentPerson1);
String car1EN = getAuditReader().getEntityName(id_car1, 1, car1);
assert (currentCar1EN.equals(car1EN));
String person1EN = getAuditReader().getEntityName(id_pers1, 1, person1);
assert (currentPerson1EN.equals(person1EN));
}
@Test(dependsOnMethods="testObtainEntityNameAssociationWithEntityName")
public void testFindHistoricAndCurrentGetAssociationWithEntityName() {
//force a new session and AR
super.newSessionFactory();
Car car1 = getAuditReader().find(Car.class, id_car1, 1);
car1.getOwner().getName();
Car car2 = getAuditReader().find(Car.class, id_car2, 2);
car2.getOwner().getName();
Person person = getAuditReader().find(Person.class, "Personaje", id_car2, 2);
person.getName();
}
}

View File

@ -1,56 +1,56 @@
package org.hibernate.envers.test.integration.entityNames.singleAssociatedNotAudited;
import org.hibernate.envers.Audited;
import org.hibernate.envers.RelationTargetAuditMode;
/**
* @author Hern<EFBFBD>n Chanfreau
*
*/
public class Car {
private long id;
private int number;
private Person owner;
public Car() { }
public Car(int number, Person owner) {
this.number = number;
this.owner = owner;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED)
public Person getOwner() {
return owner;
}
public void setOwner(Person owner) {
this.owner = owner;
}
@Audited
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
}
package org.hibernate.envers.test.integration.entityNames.singleAssociatedNotAudited;
import org.hibernate.envers.Audited;
import org.hibernate.envers.RelationTargetAuditMode;
/**
* @author Hern&aacute;n Chanfreau
*
*/
public class Car {
private long id;
private int number;
private Person owner;
public Car() { }
public Car(int number, Person owner) {
this.number = number;
this.owner = owner;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED)
public Person getOwner() {
return owner;
}
public void setOwner(Person owner) {
this.owner = owner;
}
@Audited
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
}

View File

@ -1,48 +1,48 @@
package org.hibernate.envers.test.integration.entityNames.singleAssociatedNotAudited;
/**
* @author Hern<EFBFBD>n Chanfreau
*
*/
public class Person {
private long id;
private String name;
private int age;
public Person(){ }
public Person(String name, int age){
this.name = name;
this.age = age;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
package org.hibernate.envers.test.integration.entityNames.singleAssociatedNotAudited;
/**
* @author Hern&aacute;n Chanfreau
*
*/
public class Person {
private long id;
private String name;
private int age;
public Person(){ }
public Person(String name, int age){
this.name = name;
this.age = age;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}

View File

@ -1,80 +1,126 @@
package org.hibernate.envers.test.integration.entityNames.singleAssociatedNotAudited;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import org.hibernate.MappingException;
import org.hibernate.envers.test.AbstractSessionTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author Hern<EFBFBD>n Chanfreau
*
*/
public class ReadEntityAssociatedNotAuditedTest extends AbstractSessionTest{
private long id_car1;
private long id_car2;
private long id_pers1;
private long id_pers2;
protected void initMappings() throws MappingException, URISyntaxException {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/singleAssociatedNotAudited/mappings.hbm.xml");
config.addFile(new File(url.toURI()));
}
@BeforeClass(dependsOnMethods = "init")
public void initData() {
newSessionFactory();
Person pers1 = new Person("Hernan", 15);
Person pers2 = new Person("Leandro", 19);
Car car1 = new Car(1, pers1);
Car car2 = new Car(2, pers2);
//REV 1
getSession().getTransaction().begin();
getSession().persist("Personaje",pers1);
getSession().persist(car1);
getSession().getTransaction().commit();
id_car1 = car1.getId();
id_pers1 = pers1.getId();
//REV 2
getSession().getTransaction().begin();
pers1.setAge(50);
getSession().persist("Personaje", pers1);
getSession().persist("Personaje", pers2);
getSession().persist(car2);
getSession().getTransaction().commit();
id_car2 = car2.getId();
id_pers2 = pers2.getId();
}
@Test
public void testGetAssociationWithEntityNameAndNotAuditedMode() {
// persons from "actual" model
Person person1 = (Person)getSession().get("Personaje", id_pers1);
Person person2 = (Person)getSession().get("Personaje", id_pers2);
Car car1 = getAuditReader().find(Car.class, id_car1, 1);
Car car2 = getAuditReader().find(Car.class, id_car2, 2);
// persons from "historic" model
Person person1_1 = car1.getOwner();
Person person2_1 = car2.getOwner();
assert(person1.getAge() == person1_1.getAge());
assert(person2.getAge() == person2_1.getAge());
}
}
package org.hibernate.envers.test.integration.entityNames.singleAssociatedNotAudited;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import org.hibernate.MappingException;
import org.hibernate.envers.test.AbstractSessionTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author Hern&aacute;n Chanfreau
*
*/
@Test(sequential=true)
public class ReadEntityAssociatedNotAuditedTest extends AbstractSessionTest{
private long id_car1;
private long id_car2;
private long id_pers1;
private long id_pers2;
private Car car1;
private Person person1_1;
private Person currentPerson1;
private Car currentCar1;
protected void initMappings() throws MappingException, URISyntaxException {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/singleAssociatedNotAudited/mappings.hbm.xml");
config.addFile(new File(url.toURI()));
}
/**
* The test needs to run with the same session and auditReader.
*/
@Override
public void newSessionFactory() {
if (getSession() == null) {
super.newSessionFactory();
}
}
@BeforeClass(dependsOnMethods = "init")
public void initData() {
newSessionFactory();
Person pers1 = new Person("Hernan", 15);
Person pers2 = new Person("Leandro", 19);
Car car1 = new Car(1, pers1);
Car car2 = new Car(2, pers2);
//REV 1
getSession().getTransaction().begin();
getSession().persist("Personaje",pers1);
getSession().persist(car1);
getSession().getTransaction().commit();
id_car1 = car1.getId();
id_pers1 = pers1.getId();
//REV 2
getSession().getTransaction().begin();
pers1.setAge(50);
getSession().persist("Personaje", pers1);
getSession().persist("Personaje", pers2);
getSession().persist(car2);
getSession().getTransaction().commit();
id_car2 = car2.getId();
id_pers2 = pers2.getId();
}
@Test
public void testGetAssociationWithEntityNameAndNotAuditedMode() {
// persons from "actual" model
currentPerson1 = (Person)getSession().get("Personaje", id_pers1);
Person person2 = (Person)getSession().get("Personaje", id_pers2);
currentCar1 = (Car)getSession().get(Car.class, id_car1);
car1 = getAuditReader().find(Car.class, id_car1, 1);
Car car2 = getAuditReader().find(Car.class, id_car2, 2);
// persons from "historic" model
person1_1 = car1.getOwner();
Person person2_1 = car2.getOwner();
assert(currentPerson1.getAge() == person1_1.getAge());
assert(person2.getAge() == person2_1.getAge());
}
@Test(dependsOnMethods="testGetAssociationWithEntityNameAndNotAuditedMode")
public void testObtainEntityNameAssociationWithEntityNameAndNotAuditedMode() {
String currentCar1EN = getSession().getEntityName(currentCar1);
String car1EN = getAuditReader().getEntityName(id_car1, 1, car1);
assert (currentCar1EN.equals(car1EN));
}
@Test(dependsOnMethods="testObtainEntityNameAssociationWithEntityNameAndNotAuditedMode")
public void testFindHistoricAndCurrentGetAssociationWithEntityNameAndNotAuditedMode() {
//force a new session and AR
super.newSessionFactory();
Car car1 = getAuditReader().find(Car.class, id_car1, 1);
car1.getOwner().getName();
Car car2 = getAuditReader().find(Car.class, id_car2, 2);
car2.getOwner().getName();
if(getAuditReader().isEntityNameNotAudited("Personaje")) {
Person person = (Person)getSession().get("Personaje", id_pers1);
person.getName();
} else {
// it is not_audited
assert(false);
}
}
}