HHH-8908 : Column of Embedded missing in Audit Table; reorg tests

This commit is contained in:
Gail Badner 2014-04-17 13:55:01 -07:00
parent b3b2312482
commit f693f5c320
8 changed files with 228 additions and 78 deletions

View File

@ -97,6 +97,6 @@ public class CollectionOfMappedSuperclassComponentsTest extends BaseEnversJPAFun
Set<Code> comps1 = entity.getComps();
assertEquals( 1, comps1.size() );
assertTrue( comps1.contains( new Code( 1 ) ) );
assertEquals( 0, entity.getCompsNotAudited().size() );
// The contents of entity.getCompsNotAudited() is unspecified, so no need to test.
}
}

View File

@ -33,7 +33,7 @@ import javax.persistence.MappedSuperclass;
@MappedSuperclass
@Access(AccessType.FIELD)
public abstract class AbstractCode {
public abstract class AbstractEmbeddable {
/**
* Initial Value
@ -43,19 +43,17 @@ public abstract class AbstractCode {
private int code = UNDEFINED;
protected AbstractCode() {
protected AbstractEmbeddable() {
this( UNDEFINED );
}
/**
* Constructor with code
*/
public AbstractCode(int code) {
public AbstractEmbeddable(int code) {
this.code = code;
}
public abstract String getCodeart();
public int getCode() {
return code;
}
@ -79,7 +77,7 @@ public abstract class AbstractCode {
if ( getClass() != obj.getClass() ) {
return false;
}
AbstractCode other = (AbstractCode) obj;
AbstractEmbeddable other = (AbstractEmbeddable) obj;
if ( code != other.code ) {
return false;
}

View File

@ -25,26 +25,26 @@ package org.hibernate.envers.test.integration.components.mappedsuperclass;
/**
* @author Jakob Braeuchi.
* @author Gail Badner
*/
import javax.persistence.Embeddable;
@Embeddable
public class Code extends AbstractCode {
public class EmbeddableWithDeclaredData extends AbstractEmbeddable {
private String codeArt;
public Code(int code, String codeArt) {
public EmbeddableWithDeclaredData(int code, String codeArt) {
super( code );
this.codeArt = codeArt;
}
// Needed for @Embeddable
protected Code() {
protected EmbeddableWithDeclaredData() {
this( UNDEFINED, null );
}
@Override
public String getCodeart() {
return codeArt;
}
@ -68,7 +68,7 @@ public class Code extends AbstractCode {
if ( getClass() != obj.getClass() ) {
return false;
}
Code other = (Code) obj;
EmbeddableWithDeclaredData other = (EmbeddableWithDeclaredData) obj;
if ( codeArt == null ) {
if ( other.codeArt != null ) {
return false;

View File

@ -38,14 +38,15 @@ import org.hibernate.testing.TestForIssue;
/**
* @author Jakob Braeuchi.
* @author Gail Badner
*/
@TestForIssue(jiraKey = "HHH-8908")
public class MappedSuperclassEmbeddableTest extends BaseEnversJPAFunctionalTestCase {
public class EmbeddableWithDeclaredDataTest extends BaseEnversJPAFunctionalTestCase {
private long id;
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { SimplePerson.class, AbstractCode.class, Code.class, TestCode.class };
return new Class[] { EntityWithEmbeddableWithDeclaredData.class, AbstractEmbeddable.class, EmbeddableWithDeclaredData.class };
}
@Test
@ -53,18 +54,17 @@ public class MappedSuperclassEmbeddableTest extends BaseEnversJPAFunctionalTestC
public void initData() {
EntityManager em = getEntityManager();
SimplePerson person = new SimplePerson();
person.setName( "Person 1" );
person.setTestCode( new TestCode( 84 ) );
person.setGenericCode( new Code( 42, "TestCodeart" ) );
EntityWithEmbeddableWithDeclaredData entity = new EntityWithEmbeddableWithDeclaredData();
entity.setName( "Entity 1" );
entity.setValue( new EmbeddableWithDeclaredData( 42, "TestCodeart" ) );
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist( person );
em.persist( entity );
tx.commit();
em.close();
id = person.getId();
id = entity.getId();
}
@Test
@ -72,21 +72,18 @@ public class MappedSuperclassEmbeddableTest extends BaseEnversJPAFunctionalTestC
// Reload and Compare Revision
EntityManager em = getEntityManager();
SimplePerson personLoaded = em.find( SimplePerson.class, id );
EntityWithEmbeddableWithDeclaredData entityLoaded = em.find( EntityWithEmbeddableWithDeclaredData.class, id );
AuditReader reader = AuditReaderFactory.get( em );
List<Number> revs = reader.getRevisions( SimplePerson.class, id );
List<Number> revs = reader.getRevisions( EntityWithEmbeddableWithDeclaredData.class, id );
Assert.assertEquals( 1, revs.size() );
SimplePerson personRev1 = reader.find( SimplePerson.class, id, revs.get( 0 ) );
EntityWithEmbeddableWithDeclaredData entityRev1 = reader.find( EntityWithEmbeddableWithDeclaredData.class, id, revs.get( 0 ) );
Assert.assertEquals( personLoaded.getName(), personRev1.getName() );
Assert.assertEquals( entityLoaded.getName(), entityRev1.getName() );
// Generic Code is read from AUD Table
Assert.assertEquals( personLoaded.getGenericCode(), personRev1.getGenericCode() );
// Test Code is read from AUD Table
Assert.assertEquals( personLoaded.getTestCode(), personRev1.getTestCode() );
// value is read from AUD Table
Assert.assertEquals( entityLoaded.getValue(), entityRev1.getValue() );
}
}

View File

@ -28,26 +28,16 @@ import javax.persistence.Transient;
/**
* @author Jakob Braeuchi.
* @author Gail Badner
*/
@Embeddable
public class TestCode extends AbstractCode {
public class EmbeddableWithNoDeclaredData extends AbstractEmbeddable {
public static final int _TEST = 1;
public static final TestCode TEST = new TestCode( _TEST );
public TestCode(int code) {
public EmbeddableWithNoDeclaredData(int code) {
super( code );
}
// Needed for @Embeddable
protected TestCode() {
super( UNDEFINED );
}
@Override
@Transient
public String getCodeart() {
return "TestCode";
protected EmbeddableWithNoDeclaredData() {
}
}

View File

@ -0,0 +1,89 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. 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 Inc.
*
* 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.components.mappedsuperclass;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import org.junit.Assert;
import org.junit.Test;
import org.hibernate.envers.AuditReader;
import org.hibernate.envers.AuditReaderFactory;
import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase;
import org.hibernate.envers.test.Priority;
import org.hibernate.testing.TestForIssue;
/**
* @author Jakob Braeuchi.
* @author Gail Badner
*/
@TestForIssue(jiraKey = "HHH-8908")
public class EmbeddableWithNoDeclaredDataTest extends BaseEnversJPAFunctionalTestCase {
private long id;
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { EntityWithEmbeddableWithNoDeclaredData.class, AbstractEmbeddable.class, EmbeddableWithNoDeclaredData.class };
}
@Test
@Priority(10)
public void initData() {
EntityManager em = getEntityManager();
EntityWithEmbeddableWithNoDeclaredData entity = new EntityWithEmbeddableWithNoDeclaredData();
entity.setName( "Entity 1" );
entity.setValue( new EmbeddableWithNoDeclaredData( 84 ) );
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist( entity );
tx.commit();
em.close();
id = entity.getId();
}
@Test
public void testEmbeddableThatExtendsMappedSuperclass() {
// Reload and Compare Revision
EntityManager em = getEntityManager();
EntityWithEmbeddableWithNoDeclaredData entityLoaded = em.find( EntityWithEmbeddableWithNoDeclaredData.class, id );
AuditReader reader = AuditReaderFactory.get( em );
List<Number> revs = reader.getRevisions( EntityWithEmbeddableWithNoDeclaredData.class, id );
Assert.assertEquals( 1, revs.size() );
EntityWithEmbeddableWithNoDeclaredData entityRev1 = reader.find( EntityWithEmbeddableWithNoDeclaredData.class, id, revs.get( 0 ) );
Assert.assertEquals( entityLoaded.getName(), entityRev1.getName() );
// value is read from AUD Table
Assert.assertEquals( entityLoaded.getValue(), entityRev1.getValue() );
}
}

View File

@ -26,15 +26,11 @@ package org.hibernate.envers.test.integration.components.mappedsuperclass;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
import org.hibernate.envers.Audited;
@ -42,31 +38,19 @@ import org.hibernate.envers.Audited;
* @author Jakob Braeuchi.
*/
@Entity
@Table(name = "TEST_SIMPLE_PERSON")
@Access(AccessType.FIELD)
@Audited
public class SimplePerson {
public class EntityWithEmbeddableWithDeclaredData {
@Id
@GeneratedValue
private long id;
@Version
private long version;
@Column(name = "NAME", length = 100)
private String name;
@Embedded
@AttributeOverrides({ @AttributeOverride(name = "code", column = @Column(name = "THE_TEST")) })
private TestCode testCode = TestCode.TEST;
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "code", column = @Column(name = "THE_CODE")),
@AttributeOverride(name = "codeArt", column = @Column(name = "THE_CODEART"))
})
private Code genericCode;
private EmbeddableWithDeclaredData value;
public long getId() {
return id;
@ -76,10 +60,6 @@ public class SimplePerson {
this.id = id;
}
public long getVersion() {
return version;
}
public String getName() {
return name;
}
@ -88,20 +68,12 @@ public class SimplePerson {
this.name = name;
}
public TestCode getTestCode() {
return testCode;
public EmbeddableWithDeclaredData getValue() {
return value;
}
public void setTestCode(TestCode testCode) {
this.testCode = testCode;
}
public Code getGenericCode() {
return genericCode;
}
public void setGenericCode(Code genericCode) {
this.genericCode = genericCode;
public void setValue(EmbeddableWithDeclaredData value) {
this.value = value;
}
@Override
@ -123,7 +95,7 @@ public class SimplePerson {
if ( getClass() != obj.getClass() ) {
return false;
}
SimplePerson other = (SimplePerson) obj;
EntityWithEmbeddableWithDeclaredData other = (EntityWithEmbeddableWithDeclaredData) obj;
if ( id != other.id ) {
return false;
}

View File

@ -0,0 +1,104 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. 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 Inc.
*
* 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.components.mappedsuperclass;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.envers.Audited;
/**
* @author Jakob Braeuchi.
*/
@Entity
@Access(AccessType.FIELD)
@Audited
public class EntityWithEmbeddableWithNoDeclaredData {
@Id
@GeneratedValue
private long id;
@Column(name = "NAME", length = 100)
private String name;
@Embedded
private EmbeddableWithNoDeclaredData value;
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 EmbeddableWithNoDeclaredData getValue() {
return value;
}
public void setValue(EmbeddableWithNoDeclaredData value) {
this.value = value;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) ( id ^ ( id >>> 32 ) );
return result;
}
@Override
public boolean equals(Object obj) {
if ( this == obj ) {
return true;
}
if ( obj == null ) {
return false;
}
if ( getClass() != obj.getClass() ) {
return false;
}
EntityWithEmbeddableWithNoDeclaredData other = (EntityWithEmbeddableWithNoDeclaredData) obj;
if ( id != other.id ) {
return false;
}
return true;
}
}