HHH-6069 - Tests moved
This commit is contained in:
parent
d7cc102b00
commit
33074dc2dc
|
@ -82,10 +82,9 @@ public class Column implements Selectable, Serializable, Cloneable {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
/* Envers passes 'name' parameter wrapped with '`' signs if quotation required. Set 'quoted' property accordingly. */
|
|
||||||
if (
|
if (
|
||||||
name.charAt(0)=='`' ||
|
name.charAt(0)=='`' ||
|
||||||
Dialect.QUOTE.indexOf( name.charAt(0) ) > -1
|
Dialect.QUOTE.indexOf( name.charAt(0) ) > -1 //TODO: deprecated, remove eventually
|
||||||
) {
|
) {
|
||||||
quoted=true;
|
quoted=true;
|
||||||
this.name=name.substring( 1, name.length()-1 );
|
this.name=name.substring( 1, name.length()-1 );
|
||||||
|
|
|
@ -36,7 +36,6 @@ import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
|
||||||
*/
|
*/
|
||||||
public class BasicNaming extends AbstractEntityTest {
|
public class BasicNaming extends AbstractEntityTest {
|
||||||
private Integer id1;
|
private Integer id1;
|
||||||
|
@ -116,18 +115,4 @@ public class BasicNaming extends AbstractEntityTest {
|
||||||
getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.NamingTestEntity1_AUD")
|
getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.NamingTestEntity1_AUD")
|
||||||
.getTable().getName());
|
.getTable().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEscapeEntityField() {
|
|
||||||
Table table = getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.NamingTestEntity1_AUD").getTable();
|
|
||||||
Iterator<Column> columnIterator = table.getColumnIterator();
|
|
||||||
while (columnIterator.hasNext()) {
|
|
||||||
Column column = columnIterator.next();
|
|
||||||
if ("nte_number#".equals(column.getName())) {
|
|
||||||
assert column.isQuoted();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.hibernate.envers.Audited;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="naming_test_entity_1")
|
@Table(name="naming_test_entity_1")
|
||||||
|
@ -47,10 +46,6 @@ public class NamingTestEntity1 {
|
||||||
@Audited
|
@Audited
|
||||||
private String data;
|
private String data;
|
||||||
|
|
||||||
@Column(name = "`nte_number#`")
|
|
||||||
@Audited
|
|
||||||
private Integer number;
|
|
||||||
|
|
||||||
public NamingTestEntity1() {
|
public NamingTestEntity1() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,12 +58,6 @@ public class NamingTestEntity1 {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NamingTestEntity1(Integer id, String data, Integer number) {
|
|
||||||
this.id = id;
|
|
||||||
this.data = data;
|
|
||||||
this.number = number;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -85,14 +74,6 @@ public class NamingTestEntity1 {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getNumber() {
|
|
||||||
return number;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNumber(Integer number) {
|
|
||||||
this.number = number;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (!(o instanceof NamingTestEntity1)) return false;
|
if (!(o instanceof NamingTestEntity1)) return false;
|
||||||
|
@ -100,7 +81,6 @@ public class NamingTestEntity1 {
|
||||||
NamingTestEntity1 that = (NamingTestEntity1) o;
|
NamingTestEntity1 that = (NamingTestEntity1) o;
|
||||||
|
|
||||||
if (data != null ? !data.equals(that.data) : that.data != null) return false;
|
if (data != null ? !data.equals(that.data) : that.data != null) return false;
|
||||||
if (number != null ? !number.equals(that.number) : that.number != null) return false;
|
|
||||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -110,7 +90,6 @@ public class NamingTestEntity1 {
|
||||||
int result;
|
int result;
|
||||||
result = (id != null ? id.hashCode() : 0);
|
result = (id != null ? id.hashCode() : 0);
|
||||||
result = 31 * result + (data != null ? data.hashCode() : 0);
|
result = 31 * result + (data != null ? data.hashCode() : 0);
|
||||||
result = 31 * result + (number != null ? number.hashCode() : 0);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
package org.hibernate.envers.test.integration.naming.quotation;
|
||||||
|
|
||||||
|
import org.hibernate.envers.Audited;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class QuotedFieldsEntity {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
@Column(name = "`id#`")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "`#data1`")
|
||||||
|
@Audited
|
||||||
|
private String data1;
|
||||||
|
|
||||||
|
@Column(name = "`#data2`")
|
||||||
|
@Audited
|
||||||
|
private Integer data2;
|
||||||
|
|
||||||
|
public QuotedFieldsEntity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuotedFieldsEntity(String data1, Integer data2) {
|
||||||
|
this.data1 = data1;
|
||||||
|
this.data2 = data2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuotedFieldsEntity(Long id, String data1, Integer data2) {
|
||||||
|
this.id = id;
|
||||||
|
this.data1 = data1;
|
||||||
|
this.data2 = data2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getData1() {
|
||||||
|
return data1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData1(String data1) {
|
||||||
|
this.data1 = data1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getData2() {
|
||||||
|
return data2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData2(Integer data2) {
|
||||||
|
this.data2 = data2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof QuotedFieldsEntity)) return false;
|
||||||
|
|
||||||
|
QuotedFieldsEntity that = (QuotedFieldsEntity) o;
|
||||||
|
|
||||||
|
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||||
|
if (data1 != null ? !data1.equals(that.data1) : that.data1 != null) return false;
|
||||||
|
if (data2 != null ? !data2.equals(that.data2) : that.data2 != null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
int result;
|
||||||
|
result = (id != null ? id.hashCode() : 0);
|
||||||
|
result = 31 * result + (data1 != null ? data1.hashCode() : 0);
|
||||||
|
result = 31 * result + (data2 != null ? data2.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,104 @@
|
||||||
|
package org.hibernate.envers.test.integration.naming.quotation;
|
||||||
|
|
||||||
|
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.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||||
|
*/
|
||||||
|
public class QuotedFieldsTest extends AbstractEntityTest {
|
||||||
|
private Long qfeId1 = null;
|
||||||
|
private Long qfeId2 = null;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(QuotedFieldsEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
QuotedFieldsEntity qfe1 = new QuotedFieldsEntity("data1", 1);
|
||||||
|
QuotedFieldsEntity qfe2 = new QuotedFieldsEntity("data2", 2);
|
||||||
|
|
||||||
|
// Revision 1
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
em.persist(qfe1);
|
||||||
|
em.persist(qfe2);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2
|
||||||
|
em.getTransaction().begin();
|
||||||
|
qfe1 = em.find(QuotedFieldsEntity.class, qfe1.getId());
|
||||||
|
qfe1.setData1("data1 changed");
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 3
|
||||||
|
em.getTransaction().begin();
|
||||||
|
qfe2 = em.find(QuotedFieldsEntity.class, qfe2.getId());
|
||||||
|
qfe2.setData2(3);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
qfeId1 = qfe1.getId();
|
||||||
|
qfeId2 = qfe2.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRevisionsCounts() {
|
||||||
|
assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(QuotedFieldsEntity.class, qfeId1));
|
||||||
|
assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(QuotedFieldsEntity.class, qfeId2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHistoryOfId1() {
|
||||||
|
QuotedFieldsEntity ver1 = new QuotedFieldsEntity(qfeId1, "data2", 1);
|
||||||
|
QuotedFieldsEntity ver2 = new QuotedFieldsEntity(qfeId1, "data1 changed", 1);
|
||||||
|
|
||||||
|
assert getAuditReader().find(QuotedFieldsEntity.class, qfeId1, 1).equals(ver1);
|
||||||
|
assert getAuditReader().find(QuotedFieldsEntity.class, qfeId1, 2).equals(ver2);
|
||||||
|
assert getAuditReader().find(QuotedFieldsEntity.class, qfeId1, 3).equals(ver2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHistoryOfId2() {
|
||||||
|
QuotedFieldsEntity ver1 = new QuotedFieldsEntity(qfeId2, "data2", 2);
|
||||||
|
QuotedFieldsEntity ver2 = new QuotedFieldsEntity(qfeId2, "data2", 3);
|
||||||
|
|
||||||
|
assert getAuditReader().find(QuotedFieldsEntity.class, qfeId2, 1).equals(ver1);
|
||||||
|
assert getAuditReader().find(QuotedFieldsEntity.class, qfeId2, 2).equals(ver1);
|
||||||
|
assert getAuditReader().find(QuotedFieldsEntity.class, qfeId2, 3).equals(ver2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEscapeEntityField() {
|
||||||
|
Table table = getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.quotation.QuotedFieldsEntity_AUD").getTable();
|
||||||
|
Column column1 = getColumnByName(table, "id#");
|
||||||
|
Column column2 = getColumnByName(table, "#data1");
|
||||||
|
Column column3 = getColumnByName(table, "#data2");
|
||||||
|
assert column1 != null;
|
||||||
|
assert column2 != null;
|
||||||
|
assert column3 != null;
|
||||||
|
assert column1.isQuoted();
|
||||||
|
assert column2.isQuoted();
|
||||||
|
assert column3.isQuoted();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Column getColumnByName(Table table, String columnName) {
|
||||||
|
Iterator<Column> columnIterator = table.getColumnIterator();
|
||||||
|
while (columnIterator.hasNext()) {
|
||||||
|
Column column = columnIterator.next();
|
||||||
|
if (columnName.equals(column.getName())) {
|
||||||
|
return column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue