HHH-4439 - Test and Javadoc change

This commit is contained in:
Lukasz Antoniak 2012-01-06 15:20:27 +01:00
parent 1293253412
commit 05df3d8638
4 changed files with 127 additions and 5 deletions

View File

@ -10,8 +10,8 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* The {@code AuditingOverride} annotation is used to override the auditing
* behavior of a field (or property) inherited from {@link MappedSuperclass}
* type or inside an embedded component.
* behavior of a superclass or single property inherited from {@link MappedSuperclass}
* type, or inside an embedded component.
*
* @author Erik-Berndt Scheper
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)

View File

@ -102,7 +102,7 @@ public class AuditedPropertiesReader {
/**
* Recursively constructs sets of audited and not audited properties and classes which behavior has been overridden
* using @AuditOverride annotation.
* using {@link AuditOverride} annotation.
* @param clazz Class that is being processed. Currently mapped entity shall be passed during first invocation.
*/
private void doReadOverrideAudited(XClass clazz) {
@ -425,8 +425,8 @@ public class AuditedPropertiesReader {
return true;
} else {
return false;
}
}
}
}
private void setPropertyAuditMappedBy(XProperty property, PropertyAuditingData propertyData) {
AuditMappedBy auditMappedBy = property.getAnnotation(AuditMappedBy.class);

View File

@ -0,0 +1,64 @@
package org.hibernate.envers.test.integration.superclass.auditoverride;
import org.hibernate.envers.AuditOverride;
import org.hibernate.envers.AuditOverrides;
import org.hibernate.envers.Audited;
import javax.persistence.Entity;
/**
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
@Entity
@Audited
@AuditOverrides({@AuditOverride(forClass = AuditedBaseEntity.class, isAudited = false),
@AuditOverride(forClass = AuditedBaseEntity.class, name = "number1", isAudited = true)})
public class MixedOverrideEntity extends AuditedBaseEntity {
private String str2;
public MixedOverrideEntity() {
}
public MixedOverrideEntity(String str1, Integer number, String str2) {
super(str1, number);
this.str2 = str2;
}
public MixedOverrideEntity(String str1, Integer number, Integer id, String str2) {
super(str1, number, id);
this.str2 = str2;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MixedOverrideEntity)) return false;
if (!super.equals(o)) return false;
MixedOverrideEntity that = (MixedOverrideEntity) o;
if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (str2 != null ? str2.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "MixedOverrideEntity(" + super.toString() + ", str2 = " + str2 + ")";
}
public String getStr2() {
return str2;
}
public void setStr2(String str2) {
this.str2 = str2;
}
}

View File

@ -0,0 +1,58 @@
package org.hibernate.envers.test.integration.superclass.auditoverride;
import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.envers.test.AbstractEntityTest;
import org.hibernate.envers.test.Priority;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Table;
import org.hibernate.testing.TestForIssue;
import org.junit.Assert;
import org.junit.Test;
import javax.persistence.EntityManager;
/**
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
@TestForIssue(jiraKey = "HHH-4439")
public class MixedOverrideTest extends AbstractEntityTest {
private Integer mixedEntityId = null;
private Table mixedTable = null;
@Override
public void configure(Ejb3Configuration cfg) {
cfg.addAnnotatedClass(MixedOverrideEntity.class);
}
@Test
@Priority(10)
public void initData() {
EntityManager em = getEntityManager();
// Revision 1
em.getTransaction().begin();
MixedOverrideEntity mixedEntity = new MixedOverrideEntity("data 1", 1, "data 2");
em.persist(mixedEntity);
em.getTransaction().commit();
mixedEntityId = mixedEntity.getId();
mixedTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditoverride.MixedOverrideEntity_AUD").getTable();
}
@Test
public void testAuditedProperty() {
Assert.assertNotNull(mixedTable.getColumn(new Column("number1")));
Assert.assertNotNull(mixedTable.getColumn(new Column("str2")));
}
@Test
public void testNotAuditedProperty() {
Assert.assertNull(mixedTable.getColumn(new Column("str1")));
}
@Test
public void testHistoryOfMixedEntity() {
MixedOverrideEntity ver1 = new MixedOverrideEntity(null, 1, mixedEntityId, "data 2");
Assert.assertEquals(ver1, getAuditReader().find(MixedOverrideEntity.class, mixedEntityId, 1));
}
}