Fix for HHH-4646 and HHH-5177
Adding tests cases: - MappedSuperclass audited at class level with a NotAuditedSubclass and: - Audited subclass at class level - Audited subclass at method/field level - MappedSuperclass audited at method/field level with a NotAuditedSubclass and: - Audited subclass at class level - Audited subclass at method/field level
This commit is contained in:
parent
b919969497
commit
65e14bb39b
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel;
|
||||||
|
|
||||||
|
import javax.persistence.MappedSuperclass;
|
||||||
|
|
||||||
|
import org.hibernate.envers.Audited;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
*
|
||||||
|
* @author Hern&aacut;n Chanfreau
|
||||||
|
*/
|
||||||
|
@MappedSuperclass
|
||||||
|
public class AuditedMethodMappedSuperclass {
|
||||||
|
|
||||||
|
@Audited
|
||||||
|
private String str;
|
||||||
|
|
||||||
|
private String otherStr;
|
||||||
|
|
||||||
|
public AuditedMethodMappedSuperclass() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuditedMethodMappedSuperclass(String str, String otherStr) {
|
||||||
|
this.str = str;
|
||||||
|
this.otherStr = otherStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStr() {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStr(String str) {
|
||||||
|
this.str = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOtherStr() {
|
||||||
|
return otherStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOtherStr(String otherStr) {
|
||||||
|
this.otherStr = otherStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o)
|
||||||
|
return true;
|
||||||
|
if (!(o instanceof AuditedMethodMappedSuperclass))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
AuditedMethodMappedSuperclass that = (AuditedMethodMappedSuperclass) o;
|
||||||
|
|
||||||
|
if (str != null ? !str.equals(that.str) : that.str != null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
return (str != null ? str.hashCode() : 0);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
*
|
||||||
|
* @author Hernán Chanfreau
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class NotAuditedSubclassEntity extends AuditedMethodMappedSuperclass {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String notAuditedStr;
|
||||||
|
|
||||||
|
public NotAuditedSubclassEntity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotAuditedSubclassEntity(Integer id, String str, String otherStr, String notAuditedStr) {
|
||||||
|
super(str, otherStr);
|
||||||
|
this.notAuditedStr = notAuditedStr;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotAuditedSubclassEntity(String str, String otherStr, String notAuditedStr) {
|
||||||
|
super(str, otherStr);
|
||||||
|
this.notAuditedStr = notAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNotAuditedStr() {
|
||||||
|
return notAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNotAuditedStr(String notAuditedStr) {
|
||||||
|
this.notAuditedStr = notAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o)
|
||||||
|
return true;
|
||||||
|
if (!(o instanceof NotAuditedSubclassEntity))
|
||||||
|
return false;
|
||||||
|
if (!super.equals(o))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
NotAuditedSubclassEntity that = (NotAuditedSubclassEntity) o;
|
||||||
|
|
||||||
|
if (id != null ? !id.equals(that.id) : that.id != null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = 31 * result + (id != null ? id.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.auditAllSubclass;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
import org.hibernate.envers.Audited;
|
||||||
|
import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.AuditedMethodMappedSuperclass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Hern&aacut;n Chanfreau
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Audited
|
||||||
|
public class AuditedAllSubclassEntity extends AuditedMethodMappedSuperclass {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String subAuditedStr;
|
||||||
|
|
||||||
|
|
||||||
|
public AuditedAllSubclassEntity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuditedAllSubclassEntity(Integer id, String str, String otherString, String subAuditedStr) {
|
||||||
|
super(str, otherString);
|
||||||
|
this.subAuditedStr = subAuditedStr;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuditedAllSubclassEntity(String str, String otherString, String subAuditedStr ) {
|
||||||
|
super(str, otherString);
|
||||||
|
this.subAuditedStr = subAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubAuditedStr() {
|
||||||
|
return subAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubAuditedStr(String subAuditedStr) {
|
||||||
|
this.subAuditedStr = subAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof AuditedAllSubclassEntity)) return false;
|
||||||
|
if (!super.equals(o)) return false;
|
||||||
|
|
||||||
|
AuditedAllSubclassEntity that = (AuditedAllSubclassEntity) o;
|
||||||
|
|
||||||
|
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = 31 * result + (id != null ? id.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,121 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.auditAllSubclass;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.exception.NotAuditedException;
|
||||||
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
|
import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.AuditedMethodMappedSuperclass;
|
||||||
|
import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.NotAuditedSubclassEntity;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
*
|
||||||
|
* @author Hern&aacut;n Chanfreau
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MappedSubclassingAllAuditedTest extends AbstractEntityTest {
|
||||||
|
private Integer id2_1;
|
||||||
|
private Integer id1_1;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(AuditedMethodMappedSuperclass.class);
|
||||||
|
cfg.addAnnotatedClass(AuditedAllSubclassEntity.class);
|
||||||
|
cfg.addAnnotatedClass(NotAuditedSubclassEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass(dependsOnMethods = "init")
|
||||||
|
public void initData() {
|
||||||
|
// Revision 1
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
NotAuditedSubclassEntity nas = new NotAuditedSubclassEntity("nae","super str","not audited str");
|
||||||
|
em.persist(nas);
|
||||||
|
AuditedAllSubclassEntity ae = new AuditedAllSubclassEntity("ae", "super str", "audited str");
|
||||||
|
em.persist(ae);
|
||||||
|
id1_1 = ae.getId();
|
||||||
|
id2_1 = nas.getId();
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2
|
||||||
|
em.getTransaction().begin();
|
||||||
|
ae = em.find(AuditedAllSubclassEntity.class, id1_1);
|
||||||
|
ae.setStr("ae new");
|
||||||
|
ae.setSubAuditedStr("audited str new");
|
||||||
|
nas = em.find(NotAuditedSubclassEntity.class, id2_1);
|
||||||
|
nas.setStr("nae new");
|
||||||
|
nas.setNotAuditedStr("not aud str new");
|
||||||
|
em.getTransaction().commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRevisionsCountsForAudited() {
|
||||||
|
assert Arrays.asList(1, 2).equals(
|
||||||
|
getAuditReader().getRevisions(AuditedAllSubclassEntity.class, id1_1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions={ NotAuditedException.class })
|
||||||
|
public void testRevisionsCountsForNotAudited() {
|
||||||
|
try {
|
||||||
|
getAuditReader().getRevisions(NotAuditedSubclassEntity.class, id2_1);
|
||||||
|
assert(false);
|
||||||
|
} catch (NotAuditedException nae) {
|
||||||
|
throw nae;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHistoryOfAudited() {
|
||||||
|
AuditedAllSubclassEntity ver1 = new AuditedAllSubclassEntity(id1_1, "ae", "super str", "audited str");
|
||||||
|
AuditedAllSubclassEntity ver2 = new AuditedAllSubclassEntity(id1_1, "ae new", "super str", "audited str new");
|
||||||
|
|
||||||
|
AuditedAllSubclassEntity rev1 = getAuditReader().find(AuditedAllSubclassEntity.class, id1_1, 1);
|
||||||
|
AuditedAllSubclassEntity rev2 = getAuditReader().find(AuditedAllSubclassEntity.class, id1_1, 2);
|
||||||
|
|
||||||
|
//this property is not audited on superclass
|
||||||
|
assert(rev1.getOtherStr() == null);
|
||||||
|
assert(rev2.getOtherStr() == null);
|
||||||
|
|
||||||
|
assert rev1.equals(ver1);
|
||||||
|
assert rev2.equals(ver2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions={ NotAuditedException.class })
|
||||||
|
public void testHistoryOfNotAudited() {
|
||||||
|
try {
|
||||||
|
getAuditReader().find(NotAuditedSubclassEntity.class, id2_1, 1);
|
||||||
|
assert(false);
|
||||||
|
} catch (NotAuditedException nae) {
|
||||||
|
throw nae;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.auditMethodSubclass;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
import org.hibernate.envers.Audited;
|
||||||
|
import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.AuditedMethodMappedSuperclass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Hern&aacut;n Chanfreau
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class AuditedMethodSubclassEntity extends AuditedMethodMappedSuperclass {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Audited
|
||||||
|
private String subAuditedStr;
|
||||||
|
|
||||||
|
|
||||||
|
public AuditedMethodSubclassEntity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuditedMethodSubclassEntity(Integer id, String str, String otherString, String subAuditedStr) {
|
||||||
|
super(str, otherString);
|
||||||
|
this.subAuditedStr = subAuditedStr;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuditedMethodSubclassEntity(String str, String otherString, String subAuditedStr ) {
|
||||||
|
super(str, otherString);
|
||||||
|
this.subAuditedStr = subAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubAuditedStr() {
|
||||||
|
return subAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubAuditedStr(String subAuditedStr) {
|
||||||
|
this.subAuditedStr = subAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof AuditedMethodSubclassEntity)) return false;
|
||||||
|
if (!super.equals(o)) return false;
|
||||||
|
|
||||||
|
AuditedMethodSubclassEntity that = (AuditedMethodSubclassEntity) o;
|
||||||
|
|
||||||
|
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = 31 * result + (id != null ? id.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,121 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.auditMethodSubclass;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.exception.NotAuditedException;
|
||||||
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
|
import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.AuditedMethodMappedSuperclass;
|
||||||
|
import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.NotAuditedSubclassEntity;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
*
|
||||||
|
* @author Hern&aacut;n Chanfreau
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MappedSubclassingMethodAuditedTest extends AbstractEntityTest {
|
||||||
|
private Integer id2_1;
|
||||||
|
private Integer id1_1;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(AuditedMethodMappedSuperclass.class);
|
||||||
|
cfg.addAnnotatedClass(AuditedMethodSubclassEntity.class);
|
||||||
|
cfg.addAnnotatedClass(NotAuditedSubclassEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass(dependsOnMethods = "init")
|
||||||
|
public void initData() {
|
||||||
|
// Revision 1
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
NotAuditedSubclassEntity nas = new NotAuditedSubclassEntity("nae","super str","not audited str");
|
||||||
|
em.persist(nas);
|
||||||
|
AuditedMethodSubclassEntity ae = new AuditedMethodSubclassEntity("ae", "super str", "audited str");
|
||||||
|
em.persist(ae);
|
||||||
|
id1_1 = ae.getId();
|
||||||
|
id2_1 = nas.getId();
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2
|
||||||
|
em.getTransaction().begin();
|
||||||
|
ae = em.find(AuditedMethodSubclassEntity.class, id1_1);
|
||||||
|
ae.setStr("ae new");
|
||||||
|
ae.setSubAuditedStr("audited str new");
|
||||||
|
nas = em.find(NotAuditedSubclassEntity.class, id2_1);
|
||||||
|
nas.setStr("nae new");
|
||||||
|
nas.setNotAuditedStr("not aud str new");
|
||||||
|
em.getTransaction().commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRevisionsCountsForAudited() {
|
||||||
|
assert Arrays.asList(1, 2).equals(
|
||||||
|
getAuditReader().getRevisions(AuditedMethodSubclassEntity.class, id1_1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions={ NotAuditedException.class })
|
||||||
|
public void testRevisionsCountsForNotAudited() {
|
||||||
|
try {
|
||||||
|
getAuditReader().getRevisions(NotAuditedSubclassEntity.class, id2_1);
|
||||||
|
assert(false);
|
||||||
|
} catch (NotAuditedException nae) {
|
||||||
|
throw nae;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHistoryOfAudited() {
|
||||||
|
AuditedMethodSubclassEntity ver1 = new AuditedMethodSubclassEntity(id1_1, "ae", "super str", "audited str");
|
||||||
|
AuditedMethodSubclassEntity ver2 = new AuditedMethodSubclassEntity(id1_1, "ae new", "super str", "audited str new");
|
||||||
|
|
||||||
|
AuditedMethodSubclassEntity rev1 = getAuditReader().find(AuditedMethodSubclassEntity.class, id1_1, 1);
|
||||||
|
AuditedMethodSubclassEntity rev2 = getAuditReader().find(AuditedMethodSubclassEntity.class, id1_1, 2);
|
||||||
|
|
||||||
|
//this property is not audited on superclass
|
||||||
|
assert(rev1.getOtherStr() == null);
|
||||||
|
assert(rev2.getOtherStr() == null);
|
||||||
|
|
||||||
|
assert rev1.equals(ver1);
|
||||||
|
assert rev2.equals(ver2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions={ NotAuditedException.class })
|
||||||
|
public void testHistoryOfNotAudited() {
|
||||||
|
try {
|
||||||
|
getAuditReader().find(NotAuditedSubclassEntity.class, id2_1, 1);
|
||||||
|
assert(false);
|
||||||
|
} catch (NotAuditedException nae) {
|
||||||
|
throw nae;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel;
|
||||||
|
|
||||||
|
import javax.persistence.MappedSuperclass;
|
||||||
|
|
||||||
|
import org.hibernate.envers.Audited;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
*
|
||||||
|
* @author Hern&aacut;n Chanfreau
|
||||||
|
*/
|
||||||
|
@MappedSuperclass
|
||||||
|
@Audited
|
||||||
|
public class AuditedAllMappedSuperclass {
|
||||||
|
|
||||||
|
private String str;
|
||||||
|
|
||||||
|
private String otherStr;
|
||||||
|
|
||||||
|
public AuditedAllMappedSuperclass() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuditedAllMappedSuperclass(String str, String otherStr) {
|
||||||
|
this.str = str;
|
||||||
|
this.otherStr = otherStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStr() {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStr(String str) {
|
||||||
|
this.str = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOtherStr() {
|
||||||
|
return otherStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOtherStr(String otherStr) {
|
||||||
|
this.otherStr = otherStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o)
|
||||||
|
return true;
|
||||||
|
if (!(o instanceof AuditedAllMappedSuperclass))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
AuditedAllMappedSuperclass that = (AuditedAllMappedSuperclass) o;
|
||||||
|
|
||||||
|
if (str != null ? !str.equals(that.str) : that.str != null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
return (str != null ? str.hashCode() : 0);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
*
|
||||||
|
* @author Hernán Chanfreau
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class NotAuditedSubclassEntity extends AuditedAllMappedSuperclass {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String notAuditedStr;
|
||||||
|
|
||||||
|
public NotAuditedSubclassEntity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotAuditedSubclassEntity(Integer id, String str, String otherStr, String notAuditedStr) {
|
||||||
|
super(str, otherStr);
|
||||||
|
this.notAuditedStr = notAuditedStr;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotAuditedSubclassEntity(String str, String otherStr, String notAuditedStr) {
|
||||||
|
super(str, otherStr);
|
||||||
|
this.notAuditedStr = notAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNotAuditedStr() {
|
||||||
|
return notAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNotAuditedStr(String notAuditedStr) {
|
||||||
|
this.notAuditedStr = notAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o)
|
||||||
|
return true;
|
||||||
|
if (!(o instanceof NotAuditedSubclassEntity))
|
||||||
|
return false;
|
||||||
|
if (!super.equals(o))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
NotAuditedSubclassEntity that = (NotAuditedSubclassEntity) o;
|
||||||
|
|
||||||
|
if (id != null ? !id.equals(that.id) : that.id != null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = 31 * result + (id != null ? id.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.auditAllSubclass;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
import org.hibernate.envers.Audited;
|
||||||
|
import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.AuditedAllMappedSuperclass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Hern&aacut;n Chanfreau
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Audited
|
||||||
|
public class AuditedAllSubclassEntity extends AuditedAllMappedSuperclass {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String subAuditedStr;
|
||||||
|
|
||||||
|
|
||||||
|
public AuditedAllSubclassEntity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuditedAllSubclassEntity(Integer id, String str, String otherString, String subAuditedStr) {
|
||||||
|
super(str, otherString);
|
||||||
|
this.subAuditedStr = subAuditedStr;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuditedAllSubclassEntity(String str, String otherString, String subAuditedStr ) {
|
||||||
|
super(str, otherString);
|
||||||
|
this.subAuditedStr = subAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubAuditedStr() {
|
||||||
|
return subAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubAuditedStr(String subAuditedStr) {
|
||||||
|
this.subAuditedStr = subAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof AuditedAllSubclassEntity)) return false;
|
||||||
|
if (!super.equals(o)) return false;
|
||||||
|
|
||||||
|
AuditedAllSubclassEntity that = (AuditedAllSubclassEntity) o;
|
||||||
|
|
||||||
|
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = 31 * result + (id != null ? id.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.auditAllSubclass;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.exception.NotAuditedException;
|
||||||
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
|
import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.AuditedAllMappedSuperclass;
|
||||||
|
import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.NotAuditedSubclassEntity;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
*
|
||||||
|
* @author Hern&aacut;n Chanfreau
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MappedSubclassingAllAuditedTest extends AbstractEntityTest {
|
||||||
|
private Integer id2_1;
|
||||||
|
private Integer id1_1;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(AuditedAllMappedSuperclass.class);
|
||||||
|
cfg.addAnnotatedClass(AuditedAllSubclassEntity.class);
|
||||||
|
cfg.addAnnotatedClass(NotAuditedSubclassEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass(dependsOnMethods = "init")
|
||||||
|
public void initData() {
|
||||||
|
// Revision 1
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
NotAuditedSubclassEntity nas = new NotAuditedSubclassEntity("nae","super str","not audited str");
|
||||||
|
em.persist(nas);
|
||||||
|
AuditedAllSubclassEntity ae = new AuditedAllSubclassEntity("ae", "super str", "audited str");
|
||||||
|
em.persist(ae);
|
||||||
|
id1_1 = ae.getId();
|
||||||
|
id2_1 = nas.getId();
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2
|
||||||
|
em.getTransaction().begin();
|
||||||
|
ae = em.find(AuditedAllSubclassEntity.class, id1_1);
|
||||||
|
ae.setStr("ae new");
|
||||||
|
ae.setSubAuditedStr("audited str new");
|
||||||
|
nas = em.find(NotAuditedSubclassEntity.class, id2_1);
|
||||||
|
nas.setStr("nae new");
|
||||||
|
nas.setNotAuditedStr("not aud str new");
|
||||||
|
em.getTransaction().commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRevisionsCountsForAudited() {
|
||||||
|
assert Arrays.asList(1, 2).equals(
|
||||||
|
getAuditReader().getRevisions(AuditedAllSubclassEntity.class, id1_1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions={ NotAuditedException.class })
|
||||||
|
public void testRevisionsCountsForNotAudited() {
|
||||||
|
try {
|
||||||
|
getAuditReader().getRevisions(NotAuditedSubclassEntity.class, id2_1);
|
||||||
|
assert(false);
|
||||||
|
} catch (NotAuditedException nae) {
|
||||||
|
throw nae;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHistoryOfAudited() {
|
||||||
|
AuditedAllSubclassEntity ver1 = new AuditedAllSubclassEntity(id1_1, "ae", "super str", "audited str");
|
||||||
|
AuditedAllSubclassEntity ver2 = new AuditedAllSubclassEntity(id1_1, "ae new", "super str", "audited str new");
|
||||||
|
|
||||||
|
AuditedAllSubclassEntity rev1 = getAuditReader().find(AuditedAllSubclassEntity.class, id1_1, 1);
|
||||||
|
AuditedAllSubclassEntity rev2 = getAuditReader().find(AuditedAllSubclassEntity.class, id1_1, 2);
|
||||||
|
|
||||||
|
assert(rev1.getOtherStr() != null);
|
||||||
|
assert(rev2.getOtherStr() != null);
|
||||||
|
|
||||||
|
assert rev1.equals(ver1);
|
||||||
|
assert rev2.equals(ver2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions={ NotAuditedException.class })
|
||||||
|
public void testHistoryOfNotAudited() {
|
||||||
|
try {
|
||||||
|
getAuditReader().find(NotAuditedSubclassEntity.class, id2_1, 1);
|
||||||
|
assert(false);
|
||||||
|
} catch (NotAuditedException nae) {
|
||||||
|
throw nae;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.auditMethodSubclass;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
import org.hibernate.envers.Audited;
|
||||||
|
import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.AuditedAllMappedSuperclass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Hern&aacut;n Chanfreau
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class AuditedMethodSubclassEntity extends AuditedAllMappedSuperclass {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Audited
|
||||||
|
private String subAuditedStr;
|
||||||
|
|
||||||
|
|
||||||
|
public AuditedMethodSubclassEntity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuditedMethodSubclassEntity(Integer id, String str, String otherString, String subAuditedStr) {
|
||||||
|
super(str, otherString);
|
||||||
|
this.subAuditedStr = subAuditedStr;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuditedMethodSubclassEntity(String str, String otherString, String subAuditedStr ) {
|
||||||
|
super(str, otherString);
|
||||||
|
this.subAuditedStr = subAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubAuditedStr() {
|
||||||
|
return subAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubAuditedStr(String subAuditedStr) {
|
||||||
|
this.subAuditedStr = subAuditedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof AuditedMethodSubclassEntity)) return false;
|
||||||
|
if (!super.equals(o)) return false;
|
||||||
|
|
||||||
|
AuditedMethodSubclassEntity that = (AuditedMethodSubclassEntity) o;
|
||||||
|
|
||||||
|
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = 31 * result + (id != null ? id.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.auditMethodSubclass;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.exception.NotAuditedException;
|
||||||
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
|
import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.AuditedAllMappedSuperclass;
|
||||||
|
import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.NotAuditedSubclassEntity;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
*
|
||||||
|
* @author Hern&aacut;n Chanfreau
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MappedSubclassingMethodAuditedTest extends AbstractEntityTest {
|
||||||
|
private Integer id2_1;
|
||||||
|
private Integer id1_1;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(AuditedAllMappedSuperclass.class);
|
||||||
|
cfg.addAnnotatedClass(AuditedMethodSubclassEntity.class);
|
||||||
|
cfg.addAnnotatedClass(NotAuditedSubclassEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass(dependsOnMethods = "init")
|
||||||
|
public void initData() {
|
||||||
|
// Revision 1
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
NotAuditedSubclassEntity nas = new NotAuditedSubclassEntity("nae","super str","not audited str");
|
||||||
|
em.persist(nas);
|
||||||
|
AuditedMethodSubclassEntity ae = new AuditedMethodSubclassEntity("ae", "super str", "audited str");
|
||||||
|
em.persist(ae);
|
||||||
|
id1_1 = ae.getId();
|
||||||
|
id2_1 = nas.getId();
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2
|
||||||
|
em.getTransaction().begin();
|
||||||
|
ae = em.find(AuditedMethodSubclassEntity.class, id1_1);
|
||||||
|
ae.setStr("ae new");
|
||||||
|
ae.setSubAuditedStr("audited str new");
|
||||||
|
nas = em.find(NotAuditedSubclassEntity.class, id2_1);
|
||||||
|
nas.setStr("nae new");
|
||||||
|
nas.setNotAuditedStr("not aud str new");
|
||||||
|
em.getTransaction().commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRevisionsCountsForAudited() {
|
||||||
|
assert Arrays.asList(1, 2).equals(
|
||||||
|
getAuditReader().getRevisions(AuditedMethodSubclassEntity.class, id1_1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions={ NotAuditedException.class })
|
||||||
|
public void testRevisionsCountsForNotAudited() {
|
||||||
|
try {
|
||||||
|
getAuditReader().getRevisions(NotAuditedSubclassEntity.class, id2_1);
|
||||||
|
assert(false);
|
||||||
|
} catch (NotAuditedException nae) {
|
||||||
|
throw nae;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHistoryOfAudited() {
|
||||||
|
AuditedMethodSubclassEntity ver1 = new AuditedMethodSubclassEntity(id1_1, "ae", "super str", "audited str");
|
||||||
|
AuditedMethodSubclassEntity ver2 = new AuditedMethodSubclassEntity(id1_1, "ae new", "super str", "audited str new");
|
||||||
|
|
||||||
|
AuditedMethodSubclassEntity rev1 = getAuditReader().find(AuditedMethodSubclassEntity.class, id1_1, 1);
|
||||||
|
AuditedMethodSubclassEntity rev2 = getAuditReader().find(AuditedMethodSubclassEntity.class, id1_1, 2);
|
||||||
|
|
||||||
|
assert(rev1.getOtherStr() != null);
|
||||||
|
assert(rev2.getOtherStr() != null);
|
||||||
|
|
||||||
|
assert rev1.equals(ver1);
|
||||||
|
assert rev2.equals(ver2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions={ NotAuditedException.class })
|
||||||
|
public void testHistoryOfNotAudited() {
|
||||||
|
try {
|
||||||
|
getAuditReader().find(NotAuditedSubclassEntity.class, id2_1, 1);
|
||||||
|
assert(false);
|
||||||
|
} catch (NotAuditedException nae) {
|
||||||
|
throw nae;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -69,7 +69,12 @@
|
||||||
<package name="org.hibernate.envers.test.integration.secondary.ids" />
|
<package name="org.hibernate.envers.test.integration.secondary.ids" />
|
||||||
<package name="org.hibernate.envers.test.integration.serialization" />
|
<package name="org.hibernate.envers.test.integration.serialization" />
|
||||||
<package name="org.hibernate.envers.test.integration.strategy" />
|
<package name="org.hibernate.envers.test.integration.strategy" />
|
||||||
<package name="org.hibernate.envers.test.integration.superclass" />
|
|
||||||
|
<package name="org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel" />
|
||||||
|
<package name="org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.auditAllSubclass" />
|
||||||
|
<package name="org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.auditAllSubclass" />
|
||||||
|
<package name="org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.auditMethodSubclass" />
|
||||||
|
|
||||||
<package name="org.hibernate.envers.test.integration.entityNames.auditedEntity" />
|
<package name="org.hibernate.envers.test.integration.entityNames.auditedEntity" />
|
||||||
<package name="org.hibernate.envers.test.integration.entityNames.manyToManyAudited" />
|
<package name="org.hibernate.envers.test.integration.entityNames.manyToManyAudited" />
|
||||||
<package name="org.hibernate.envers.test.integration.entityNames.oneToManyAudited" />
|
<package name="org.hibernate.envers.test.integration.entityNames.oneToManyAudited" />
|
||||||
|
|
Loading…
Reference in New Issue