HHH-5808 - Tests refactoring
This commit is contained in:
parent
d22b9571b7
commit
2cec03bce1
|
@ -1,85 +0,0 @@
|
|||
package org.hibernate.envers.test.integration.onetoone.unidirectional;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
|
||||
/**
|
||||
* @author Andrei Zagorneanu
|
||||
*/
|
||||
@Entity
|
||||
@Audited
|
||||
@IdClass(AddressPK.class)
|
||||
public class AddressCompositePKEntity {
|
||||
private Integer id;
|
||||
private Integer ver;
|
||||
private String street;
|
||||
|
||||
public AddressCompositePKEntity() {
|
||||
}
|
||||
|
||||
public AddressCompositePKEntity(Integer id, Integer ver, String street) {
|
||||
this.setId(id);
|
||||
this.setVer(ver);
|
||||
this.setStreet(street);
|
||||
}
|
||||
|
||||
@Id
|
||||
@Column(name = "ID", nullable = false, updatable = false)
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Id
|
||||
@Column(name = "VER", nullable = false, updatable = false)
|
||||
public Integer getVer() {
|
||||
return ver;
|
||||
}
|
||||
|
||||
public void setVer(Integer ver) {
|
||||
this.ver = ver;
|
||||
}
|
||||
|
||||
@Column(name = "STREET", nullable = false)
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "AddressCompositePKEntity[id = " + getId() + ", ver = " + getVer() + ", street = " + getStreet() + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
result = 31 * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = 31 * result + ((ver == null) ? 0 : ver.hashCode());
|
||||
result = 31 * result + ((street == null) ? 0 : street.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof AddressCompositePKEntity)) return false;
|
||||
|
||||
AddressCompositePKEntity that = (AddressCompositePKEntity) o;
|
||||
|
||||
if (ver != null ? !ver.equals(that.ver) : that.ver != null) return false;
|
||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||
if (street != null ? !street.equals(that.street) : that.street != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package org.hibernate.envers.test.integration.onetoone.unidirectional;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Andrei Zagorneanu
|
||||
*/
|
||||
public class AddressPK implements Serializable {
|
||||
private Integer id;
|
||||
private Integer ver;
|
||||
|
||||
public AddressPK() {
|
||||
}
|
||||
|
||||
public AddressPK(Integer id, Integer ver) {
|
||||
this.setId(id);
|
||||
this.setVer(ver);
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getVer() {
|
||||
return ver;
|
||||
}
|
||||
|
||||
public void setVer(Integer ver) {
|
||||
this.ver = ver;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "AddressPK[id = " + getId() + ", ver = " + getVer() + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
result = 31 * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = 31 * result + ((ver == null) ? 0 : ver.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof AddressPK)) return false;
|
||||
|
||||
AddressPK that = (AddressPK) o;
|
||||
|
||||
if (ver != null ? !ver.equals(that.ver) : that.ver != null) return false;
|
||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
package org.hibernate.envers.test.integration.onetoone.unidirectional;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* @author Andrei Zagorneanu
|
||||
*/
|
||||
@Entity
|
||||
@Audited
|
||||
public class PersonCompositeFKEntity {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private AddressCompositePKEntity address;
|
||||
|
||||
public PersonCompositeFKEntity() {
|
||||
}
|
||||
|
||||
public PersonCompositeFKEntity(Integer id, String name, AddressCompositePKEntity address) {
|
||||
this.setId(id);
|
||||
this.setName(name);
|
||||
this.setAddress(address);
|
||||
}
|
||||
|
||||
@Id
|
||||
@Column(name = "ID", nullable = false, updatable = false)
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Column(name = "NAME", nullable = false)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@OneToOne(cascade = {CascadeType.ALL}, orphanRemoval = true)
|
||||
@JoinColumns({@JoinColumn(name = "ID_ADDRESS", referencedColumnName = "ID"),
|
||||
@JoinColumn(name = "VER_ADDRESS", referencedColumnName = "VER")})
|
||||
public AddressCompositePKEntity getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(AddressCompositePKEntity address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "PersonCompositeFKEntity[id = " + getId() + ", name = " + getName() + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
result = 31 * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = 31 * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof PersonCompositeFKEntity)) return false;
|
||||
|
||||
PersonCompositeFKEntity that = (PersonCompositeFKEntity) o;
|
||||
|
||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||
if (name != null ? !name.equals(that.name) : that.name != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package org.hibernate.envers.test.integration.onetoone.unidirectional;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.hibernate.envers.test.entities.ids.EmbIdTestEntity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@Entity
|
||||
public class UniRefIngMulIdEntity {
|
||||
@Id
|
||||
private Integer id;
|
||||
|
||||
@Audited
|
||||
private String data;
|
||||
|
||||
@Audited
|
||||
@OneToOne
|
||||
private EmbIdTestEntity reference;
|
||||
|
||||
public UniRefIngMulIdEntity() {
|
||||
}
|
||||
|
||||
public UniRefIngMulIdEntity(Integer id, String data, EmbIdTestEntity reference) {
|
||||
this.id = id;
|
||||
this.data = data;
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public EmbIdTestEntity getReference() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
public void setReference(EmbIdTestEntity reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof UniRefIngMulIdEntity)) return false;
|
||||
|
||||
UniRefIngMulIdEntity that = (UniRefIngMulIdEntity) o;
|
||||
|
||||
if (data != null ? !data.equals(that.data) : that.data != null) return false;
|
||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (id != null ? id.hashCode() : 0);
|
||||
result = 31 * result + (data != null ? data.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UniRefIngMulIdEntity[id = " + id + ", data = " + data + "]";
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
package org.hibernate.envers.test.integration.onetoone.unidirectional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.Priority;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
||||
/**
|
||||
* @author Andrei Zagorneanu
|
||||
*/
|
||||
public class UnidirectionalCompositePKWithNulls extends AbstractEntityTest {
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(AddressCompositePKEntity.class);
|
||||
cfg.addAnnotatedClass(PersonCompositeFKEntity.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Priority(10)
|
||||
public void initData() {
|
||||
// address
|
||||
AddressCompositePKEntity address1 = new AddressCompositePKEntity(1, 1, "street1");
|
||||
|
||||
// person with an address
|
||||
PersonCompositeFKEntity person1 = new PersonCompositeFKEntity(1, "person1", address1);
|
||||
// person without an address
|
||||
PersonCompositeFKEntity person2 = new PersonCompositeFKEntity(2, "person2", null);
|
||||
|
||||
EntityManager em = getEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
em.persist(person1);
|
||||
em.persist(person2);
|
||||
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevisionsCounts() {
|
||||
assert Arrays.asList(1).equals(getAuditReader().getRevisions(PersonCompositeFKEntity.class, 1));
|
||||
assert Arrays.asList(1).equals(getAuditReader().getRevisions(PersonCompositeFKEntity.class, 2));
|
||||
assert Arrays.asList(1).equals(getAuditReader().getRevisions(AddressCompositePKEntity.class, new AddressPK(1, 1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHistoryOfPerson1() {
|
||||
AddressCompositePKEntity address1 = getEntityManager().find(AddressCompositePKEntity.class, new AddressPK(1, 1));
|
||||
PersonCompositeFKEntity revPerson1 = getAuditReader().find(PersonCompositeFKEntity.class, 1, 1);
|
||||
assert address1 != null;
|
||||
assert revPerson1.getAddress().equals(address1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHistoryOfPerson2NotNull() {
|
||||
PersonCompositeFKEntity revPerson2 = getAuditReader().find(PersonCompositeFKEntity.class, 2, 1);
|
||||
assert revPerson2.getAddress() == null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package org.hibernate.envers.test.integration.onetoone.unidirectional;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.Priority;
|
||||
import org.hibernate.envers.test.entities.ids.EmbId;
|
||||
import org.hibernate.envers.test.entities.ids.EmbIdTestEntity;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
public class UnidirectionalMulIdWithNulls extends AbstractEntityTest {
|
||||
private EmbId ei;
|
||||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(EmbIdTestEntity.class);
|
||||
cfg.addAnnotatedClass(UniRefIngMulIdEntity.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Priority(10)
|
||||
public void initData() {
|
||||
ei = new EmbId(1, 2);
|
||||
|
||||
EntityManager em = getEntityManager();
|
||||
|
||||
// Revision 1
|
||||
EmbIdTestEntity eite = new EmbIdTestEntity(ei, "data");
|
||||
UniRefIngMulIdEntity notNullRef = new UniRefIngMulIdEntity(1, "data 1", eite);
|
||||
UniRefIngMulIdEntity nullRef = new UniRefIngMulIdEntity(2, "data 2", null);
|
||||
|
||||
em.getTransaction().begin();
|
||||
em.persist(eite);
|
||||
em.persist(notNullRef);
|
||||
em.persist(nullRef);
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullReference() {
|
||||
UniRefIngMulIdEntity nullRef = getAuditReader().find(UniRefIngMulIdEntity.class, 2, 1);
|
||||
assert nullRef.getReference() == null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotNullReference() {
|
||||
EmbIdTestEntity eite = getAuditReader().find(EmbIdTestEntity.class, ei, 1);
|
||||
UniRefIngMulIdEntity notNullRef = getAuditReader().find(UniRefIngMulIdEntity.class, 1, 1);
|
||||
assert notNullRef.getReference() != null;
|
||||
assert notNullRef.getReference().equals(eite);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue