mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-16 16:15:06 +00:00
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:
parent
80ef651e4a
commit
c981bef5c1
@ -3,7 +3,7 @@
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* @author Hern<EFBFBD>n Chanfreau
|
||||
* @author Hernán Chanfreau
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -11,22 +11,37 @@
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Hern<EFBFBD>n Chanfreau
|
||||
* @author Herná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() {
|
||||
@ -64,6 +79,10 @@ public void initData() {
|
||||
id_pers3 = pers3.getId();
|
||||
getSession().getTransaction().commit();
|
||||
|
||||
getSession().getTransaction().begin();
|
||||
currentPers1 = (Person)getSession().get("Personaje", id_pers1);
|
||||
getSession().getTransaction().commit();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -78,21 +97,52 @@ public void testRetrieveRevisionsWithEntityName() {
|
||||
assert(pers3Revs.size() == 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(dependsOnMethods="testRetrieveRevisionsWithEntityName")
|
||||
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);
|
||||
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);
|
||||
|
||||
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());
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* @author Hern<EFBFBD>n Chanfreau
|
||||
* @author Hernán Chanfreau
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* @author Hern<EFBFBD>n Chanfreau
|
||||
* @author Hernán Chanfreau
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -12,10 +12,11 @@
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Hern<EFBFBD>n Chanfreau
|
||||
* @author Hernán Chanfreau
|
||||
*
|
||||
*/
|
||||
|
||||
@Test(sequential=true)
|
||||
public class ReadEntityWithAuditedManyToManyTest extends AbstractSessionTest{
|
||||
|
||||
private long id_car1;
|
||||
@ -23,11 +24,26 @@ public class ReadEntityWithAuditedManyToManyTest extends AbstractSessionTest{
|
||||
|
||||
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() {
|
||||
@ -66,34 +82,65 @@ public void initData() {
|
||||
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);
|
||||
car1_2 = getAuditReader().find(Car.class, id_car1, 2);
|
||||
Car car2_2 = 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 (Person owner : car1_2.getOwners()) {
|
||||
for (Car ownedCar : owner.getCars()) {
|
||||
System.out.println(" o Car: " + ownedCar.getNumber());
|
||||
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 (Person owner : car2_2.getOwners()) {
|
||||
for (Car ownedCar : owner.getCars()) {
|
||||
System.out.println(" o Car: " + ownedCar.getNumber());
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* @author Hern<EFBFBD>n Chanfreau
|
||||
* @author Hernán Chanfreau
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* @author Hern<EFBFBD>n Chanfreau
|
||||
* @author Hernán Chanfreau
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -12,22 +12,38 @@
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Hern<EFBFBD>n Chanfreau
|
||||
* @author Herná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() {
|
||||
@ -36,7 +52,6 @@ public void initData() {
|
||||
|
||||
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>();
|
||||
@ -68,22 +83,60 @@ public void initData() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObtainCollectionWithEntityName() {
|
||||
public void testObtainAuditedCollectionWithEntityName() {
|
||||
|
||||
Car car1 = getAuditReader().find(Car.class, id_car1, 2);
|
||||
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);
|
||||
|
||||
System.out.println(" > Car: " + car1.getNumber());
|
||||
System.out.println(" > Owners:");
|
||||
for (Person owner : car1.getOwners()) {
|
||||
System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
|
||||
for (Person owner : car1_1.getOwners()) {
|
||||
owner.getName();
|
||||
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());
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
import org.hibernate.envers.RelationTargetAuditMode;
|
||||
|
||||
/**
|
||||
* @author Hern<EFBFBD>n Chanfreau
|
||||
* @author Hernán Chanfreau
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.hibernate.envers.test.integration.entityNames.oneToManyNotAudited;
|
||||
|
||||
/**
|
||||
* @author Hern<EFBFBD>n Chanfreau
|
||||
* @author Hernán Chanfreau
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -11,18 +11,39 @@
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Herná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() {
|
||||
@ -31,7 +52,6 @@ public void initData() {
|
||||
|
||||
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>();
|
||||
@ -65,20 +85,71 @@ public void initData() {
|
||||
@Test
|
||||
public void testObtainCollectionWithEntityNameAndNotAuditedMode() {
|
||||
|
||||
Car car1 = getAuditReader().find(Car.class, id_car1, 2);
|
||||
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);
|
||||
|
||||
System.out.println(" > Car: " + car1.getNumber());
|
||||
System.out.println(" > Owners:");
|
||||
for (Person owner : car1.getOwners()) {
|
||||
System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
|
||||
for (Person owner : car1_1.getOwners()) {
|
||||
owner.getName();
|
||||
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());
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* @author Hern<EFBFBD>n Chanfreau
|
||||
* @author Hernán Chanfreau
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* @author Hern<EFBFBD>n Chanfreau
|
||||
* @author Hernán Chanfreau
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -10,24 +10,43 @@
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Hern<EFBFBD>n Chanfreau
|
||||
* @author Herná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() {
|
||||
@ -58,15 +77,18 @@ public void initData() {
|
||||
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() {
|
||||
|
||||
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());
|
||||
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);
|
||||
@ -74,4 +96,35 @@ public void testGetAssociationWithEntityName() {
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
import org.hibernate.envers.RelationTargetAuditMode;
|
||||
|
||||
/**
|
||||
* @author Hern<EFBFBD>n Chanfreau
|
||||
* @author Hernán Chanfreau
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.hibernate.envers.test.integration.entityNames.singleAssociatedNotAudited;
|
||||
|
||||
/**
|
||||
* @author Hern<EFBFBD>n Chanfreau
|
||||
* @author Hernán Chanfreau
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -10,10 +10,11 @@
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Hern<EFBFBD>n Chanfreau
|
||||
* @author Hernán Chanfreau
|
||||
*
|
||||
*/
|
||||
|
||||
@Test(sequential=true)
|
||||
public class ReadEntityAssociatedNotAuditedTest extends AbstractSessionTest{
|
||||
|
||||
private long id_car1;
|
||||
@ -22,12 +23,26 @@ public class ReadEntityAssociatedNotAuditedTest extends AbstractSessionTest{
|
||||
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() {
|
||||
@ -63,18 +78,49 @@ public void initData() {
|
||||
@Test
|
||||
public void testGetAssociationWithEntityNameAndNotAuditedMode() {
|
||||
// persons from "actual" model
|
||||
Person person1 = (Person)getSession().get("Personaje", id_pers1);
|
||||
currentPerson1 = (Person)getSession().get("Personaje", id_pers1);
|
||||
Person person2 = (Person)getSession().get("Personaje", id_pers2);
|
||||
|
||||
Car car1 = getAuditReader().find(Car.class, id_car1, 1);
|
||||
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
|
||||
Person person1_1 = car1.getOwner();
|
||||
person1_1 = car1.getOwner();
|
||||
Person person2_1 = car2.getOwner();
|
||||
|
||||
assert(person1.getAge() == person1_1.getAge());
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user