HHH-9207 Added unit test.

This commit is contained in:
Felix Feisst 2014-05-20 09:41:19 +02:00 committed by Brett Meyer
parent 765cc6096f
commit 55f35cc239
2 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1,63 @@
/**
*
*/
package org.hibernate.envers.test.entities.collection;
import java.util.Set;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.envers.Audited;
import org.hibernate.envers.test.entities.customtype.Component;
import org.hibernate.envers.test.entities.customtype.CompositeTestUserType;
/**
* @author Felix Feisst (feisst dot felix at gmail dot com)
*/
@Entity
@TypeDef(name = "comp", typeClass = CompositeTestUserType.class)
public class CompositeCustomTypeSetEntity {
@Id
@GeneratedValue
private Integer id;
@Audited
@ElementCollection
@Type(type = "comp")
@CollectionTable(name = "components", joinColumns = @JoinColumn(name = "entity_id"))
@Columns(columns = { @Column(name = "str", nullable = true), @Column(name = "num", nullable = true) })
private Set<Component> components;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
/**
* @return the components
*/
public Set<Component> getComponents() {
return components;
}
/**
* @param components the components to set
*/
public void setComponents(Set<Component> components) {
this.components = components;
}
}

View File

@ -0,0 +1,59 @@
/**
*
*/
package org.hibernate.envers.test.integration.collection;
import static org.junit.Assert.assertEquals;
import java.util.HashSet;
import javax.persistence.EntityManager;
import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase;
import org.hibernate.envers.test.entities.collection.CompositeCustomTypeSetEntity;
import org.hibernate.envers.test.entities.customtype.Component;
import org.hibernate.envers.test.tools.TestTools;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
/**
* @author Felix Feisst (feisst dot felix at gmail dot com)
*/
public class CompositeCustomType extends BaseEnversJPAFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { CompositeCustomTypeSetEntity.class };
}
@Test
@TestForIssue(jiraKey = "HHH-9207")
@FailureExpected(jiraKey = "HHH-9207")
public void testRemoval() {
EntityManager em = getEntityManager();
final Component comp1 = new Component( null, 11 );
final Component comp2 = new Component( null, 22 );
final CompositeCustomTypeSetEntity entity = new CompositeCustomTypeSetEntity();
entity.setComponents( new HashSet<Component>() );
entity.getComponents().add( comp1 );
entity.getComponents().add( comp2 );
em.getTransaction().begin();
em.persist( entity );
em.getTransaction().commit();
em.getTransaction().begin();
entity.getComponents().remove( comp1 );
em.getTransaction().commit();
CompositeCustomTypeSetEntity rev1 = getAuditReader().find( CompositeCustomTypeSetEntity.class, entity.getId(), 1 );
CompositeCustomTypeSetEntity rev2 = getAuditReader().find( CompositeCustomTypeSetEntity.class, entity.getId(), 2 );
assertEquals( "Unexpected components", TestTools.makeSet( comp1, comp2 ), rev1.getComponents() );
assertEquals( "Unexpected components", TestTools.makeSet( comp2 ), rev2.getComponents() );
}
}