HHH-11851 - Fix for native envers test cases to execute against validity and default audit strategies.

This commit is contained in:
Chris Cranford 2017-07-03 11:16:06 -04:00
parent c42df6a11b
commit 0d5f9c16ff
2 changed files with 18 additions and 69 deletions

View File

@ -30,8 +30,8 @@ public abstract class BaseEnversFunctionalTestCase extends BaseNonConfigCoreFunc
@Parameterized.Parameters
public static List<Object[]> data() {
return Arrays.asList(
new Object[] {null},
new Object[] {"org.hibernate.envers.strategy.ValidityAuditStrategy"}
new Object[]{ null },
new Object[]{ "org.hibernate.envers.strategy.ValidityAuditStrategy" }
);
}
@ -66,6 +66,10 @@ public abstract class BaseEnversFunctionalTestCase extends BaseNonConfigCoreFunc
super.addSettings( settings );
settings.put( EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, "false" );
if ( getAuditStrategy() != null ) {
settings.put( EnversSettings.AUDIT_STRATEGY, getAuditStrategy() );
}
}
@Override

View File

@ -6,96 +6,38 @@
*/
package org.hibernate.envers.test.integration.customtype;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.hibernate.Session;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.envers.test.BaseEnversFunctionalTestCase;
import org.hibernate.envers.test.Priority;
import org.hibernate.envers.test.entities.customtype.UnspecifiedEnumTypeEntity;
import org.hibernate.jdbc.Work;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.junit.Assert;
import org.junit.Test;
import org.hibernate.testing.TestForIssue;
/**
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
@TestForIssue(jiraKey = "HHH-7780")
@RequiresDialect(value = H2Dialect.class)
public class UnspecifiedEnumTypeTest extends BaseEnversFunctionalTestCase {
private Long id = null;
@Override
protected String[] getMappings() {
return new String[] {"mappings/customType/mappings.hbm.xml"};
return new String[]{ "mappings/customType/mappings.hbm.xml" };
}
@Override
protected void addSettings(Map settings) {
super.addSettings( settings );
settings.put( Environment.HBM2DDL_AUTO, "" );
}
@Test
@Priority(10)
public void prepareSchema() {
Session session = openSession();
dropSchema( session );
createSchema( session );
session.close();
}
@Test
@Priority(1)
public void dropSchema() {
dropSchema( getSession() );
}
public void dropSchema(Session session) {
executeUpdateSafety( session, "drop table ENUM_ENTITY if exists" );
executeUpdateSafety( session, "drop table ENUM_ENTITY_AUD if exists" );
executeUpdateSafety( session, "drop table REVINFO if exists" );
executeUpdateSafety( session, "drop sequence REVISION_GENERATOR if exists" );
}
private void createSchema(Session session) {
executeUpdateSafety(
session,
"create table ENUM_ENTITY (ID bigint not null, enum1 integer, enum2 integer, primary key (ID))"
);
executeUpdateSafety(
session,
"create table ENUM_ENTITY_AUD (ID bigint not null, REV integer not null, REVTYPE tinyint, enum1 integer, enum2 integer, primary key (ID, REV))"
);
executeUpdateSafety(
session,
"create table REVINFO (REV integer not null, REVTSTMP bigint, primary key (REV))"
);
executeUpdateSafety(
session,
"alter table ENUM_ENTITY_AUD add constraint FK_AUD_REV foreign key (REV) references REVINFO"
);
executeUpdateSafety( session, "create sequence REVISION_GENERATOR start with 1 increment by 1" );
}
private void executeUpdateSafety(Session session, String query) {
session.doWork(
new Work() {
@Override
public void execute(Connection connection) throws SQLException {
connection.createStatement().execute( query );
}
}
);
settings.put( AvailableSettings.SHOW_SQL, "true" );
settings.put( AvailableSettings.FORMAT_SQL, "true" );
}
@Test
@ -158,13 +100,16 @@ public class UnspecifiedEnumTypeTest extends BaseEnversFunctionalTestCase {
@Priority(6)
public void testEnumRepresentation() {
Session session = getSession();
List<Object[]> values = session.createSQLQuery( "SELECT enum1, enum2 FROM enum_entity_aud ORDER BY rev ASC" )
@SuppressWarnings("unchecked")
List<Object[]> values = session
.createSQLQuery( "SELECT enum1, enum2 FROM enum_entity_aud ORDER BY rev ASC" )
.list();
session.close();
Assert.assertNotNull( values );
Assert.assertEquals( 2, values.size() );
Assert.assertArrayEquals( new Object[] {0, 0}, values.get( 0 ) );
Assert.assertArrayEquals( new Object[] {1, 1}, values.get( 1 ) );
Assert.assertArrayEquals( new Object[]{ 0, 0 }, values.get( 0 ) );
Assert.assertArrayEquals( new Object[]{ 1, 1 }, values.get( 1 ) );
}
}