Re-enabled additional tests

This commit is contained in:
Andrea Boriero 2021-11-15 11:08:10 +01:00 committed by Andrea Boriero
parent 2e74d026f2
commit c1e16b4e4a
16 changed files with 418 additions and 339 deletions

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.timestamp;
package org.hibernate.orm.test.timestamp;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -14,28 +14,28 @@ import java.sql.Time;
import java.time.Instant;
import java.time.OffsetTime;
import java.util.Calendar;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider;
import org.junit.Test;
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import org.mockito.ArgumentCaptor;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.times;
@ -44,12 +44,15 @@ import static org.mockito.Mockito.verify;
/**
* @author Vlad Mihalcea
*/
@SkipForDialect(MySQL5Dialect.class)
@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class)
@SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsJdbcDriverProxying.class)
public class JdbcTimeCustomTimeZoneTest
extends BaseNonConfigCoreFunctionalTestCase {
extends BaseSessionFactoryFunctionalTest {
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider( true, false );
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider(
true,
false
);
private static final TimeZone TIME_ZONE = TimeZone.getTimeZone(
"America/Los_Angeles" );
@ -62,21 +65,21 @@ public class JdbcTimeCustomTimeZoneTest
}
@Override
protected void addSettings(Map settings) {
connectionProvider.setConnectionProvider( (ConnectionProvider) settings.get( AvailableSettings.CONNECTION_PROVIDER ) );
settings.put(
protected void applySettings(StandardServiceRegistryBuilder builder) {
connectionProvider.setConnectionProvider( (ConnectionProvider) builder.getSettings()
.get( AvailableSettings.CONNECTION_PROVIDER ) );
builder.applySetting(
AvailableSettings.CONNECTION_PROVIDER,
connectionProvider
);
settings.put(
builder.applySetting(
AvailableSettings.JDBC_TIME_ZONE,
TIME_ZONE
);
}
@Override
@AfterAll
protected void releaseResources() {
super.releaseResources();
connectionProvider.stop();
}
@ -84,7 +87,7 @@ public class JdbcTimeCustomTimeZoneTest
public void testTimeZone() {
connectionProvider.clear();
doInHibernate( this::sessionFactory, s -> {
inTransaction( s -> {
Person person = new Person();
person.id = 1L;
s.persist( person );
@ -107,16 +110,16 @@ public class JdbcTimeCustomTimeZoneTest
calendarArgumentCaptor.getValue().getTimeZone()
);
}
catch ( SQLException e ) {
catch (SQLException e) {
fail( e.getMessage() );
}
connectionProvider.clear();
doInHibernate( this::sessionFactory, s -> {
inTransaction( s -> {
s.doWork( connection -> {
try ( Statement st = connection.createStatement() ) {
try ( ResultSet rs = st.executeQuery(
"select createdOn from Person" ) ) {
try (Statement st = connection.createStatement()) {
try (ResultSet rs = st.executeQuery(
"select createdOn from Person" )) {
while ( rs.next() ) {
Time time = rs.getTime( 1 );
Time offsetTime = Time.valueOf( OffsetTime.ofInstant(

View File

@ -4,28 +4,29 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.timestamp;
package org.hibernate.orm.test.timestamp;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Time;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider;
import org.junit.Test;
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.times;
@ -34,12 +35,14 @@ import static org.mockito.Mockito.verify;
/**
* @author Vlad Mihalcea
*/
@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsJdbcDriverProxying.class)
public class JdbcTimeDefaultTimeZoneTest
extends BaseNonConfigCoreFunctionalTestCase {
extends BaseSessionFactoryFunctionalTest {
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider( true, false );
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider(
true,
false
);
@Override
protected Class<?>[] getAnnotatedClasses() {
@ -49,17 +52,17 @@ public class JdbcTimeDefaultTimeZoneTest
}
@Override
protected void addSettings(Map settings) {
connectionProvider.setConnectionProvider( (ConnectionProvider) settings.get( AvailableSettings.CONNECTION_PROVIDER ) );
settings.put(
protected void applySettings(StandardServiceRegistryBuilder builder) {
connectionProvider.setConnectionProvider( (ConnectionProvider) builder.getSettings()
.get( AvailableSettings.CONNECTION_PROVIDER ) );
builder.applySetting(
AvailableSettings.CONNECTION_PROVIDER,
connectionProvider
);
}
@Override
@AfterAll
protected void releaseResources() {
super.releaseResources();
connectionProvider.stop();
}
@ -67,7 +70,7 @@ public class JdbcTimeDefaultTimeZoneTest
public void testTimeZone() {
connectionProvider.clear();
doInHibernate( this::sessionFactory, s -> {
inTransaction( s -> {
Person person = new Person();
person.id = 1L;
s.persist( person );
@ -80,11 +83,11 @@ public class JdbcTimeDefaultTimeZoneTest
try {
verify( ps, times( 1 ) ).setTime( anyInt(), any( Time.class ) );
}
catch ( SQLException e ) {
catch (SQLException e) {
fail( e.getMessage() );
}
doInHibernate( this::sessionFactory, s -> {
inTransaction( s -> {
Person person = s.find( Person.class, 1L );
assertEquals(
0,

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.timestamp;
package org.hibernate.orm.test.timestamp;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -12,27 +12,27 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Map;
import java.util.TimeZone;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider;
import org.junit.Test;
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import org.mockito.ArgumentCaptor;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernateSessionBuilder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.times;
@ -41,10 +41,10 @@ import static org.mockito.Mockito.verify;
/**
* @author Vlad Mihalcea
*/
@SkipForDialect(MySQL5Dialect.class)
@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class)
@SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsJdbcDriverProxying.class)
public class JdbcTimestampCustomSessionLevelTimeZoneTest
extends BaseNonConfigCoreFunctionalTestCase {
extends BaseSessionFactoryFunctionalTest {
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider( true, false );
@ -59,17 +59,16 @@ public class JdbcTimestampCustomSessionLevelTimeZoneTest
}
@Override
protected void addSettings(Map settings) {
connectionProvider.setConnectionProvider( (ConnectionProvider) settings.get( AvailableSettings.CONNECTION_PROVIDER ) );
settings.put(
protected void applySettings(StandardServiceRegistryBuilder builder) {
connectionProvider.setConnectionProvider( (ConnectionProvider) builder.getSettings().get( AvailableSettings.CONNECTION_PROVIDER ) );
builder.applySetting(
AvailableSettings.CONNECTION_PROVIDER,
connectionProvider
);
}
@Override
@AfterAll
protected void releaseResources() {
super.releaseResources();
connectionProvider.stop();
}

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.timestamp;
package org.hibernate.orm.test.timestamp;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -12,27 +12,27 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Map;
import java.util.TimeZone;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider;
import org.junit.Test;
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import org.mockito.ArgumentCaptor;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.times;
@ -41,12 +41,15 @@ import static org.mockito.Mockito.verify;
/**
* @author Vlad Mihalcea
*/
@SkipForDialect(MySQL5Dialect.class)
@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class)
@SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsJdbcDriverProxying.class)
public class JdbcTimestampCustomTimeZoneTest
extends BaseNonConfigCoreFunctionalTestCase {
extends BaseSessionFactoryFunctionalTest {
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider( true, false );
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider(
true,
false
);
private static final TimeZone TIME_ZONE = TimeZone.getTimeZone(
"America/Los_Angeles" );
@ -59,21 +62,21 @@ public class JdbcTimestampCustomTimeZoneTest
}
@Override
protected void addSettings(Map settings) {
connectionProvider.setConnectionProvider( (ConnectionProvider) settings.get( AvailableSettings.CONNECTION_PROVIDER ) );
settings.put(
protected void applySettings(StandardServiceRegistryBuilder builder) {
connectionProvider.setConnectionProvider( (ConnectionProvider) builder.getSettings()
.get( AvailableSettings.CONNECTION_PROVIDER ) );
builder.applySetting(
AvailableSettings.CONNECTION_PROVIDER,
connectionProvider
);
settings.put(
builder.applySetting(
AvailableSettings.JDBC_TIME_ZONE,
TIME_ZONE
);
}
@Override
@AfterAll
protected void releaseResources() {
super.releaseResources();
connectionProvider.stop();
}
@ -81,7 +84,7 @@ public class JdbcTimestampCustomTimeZoneTest
public void testTimeZone() {
connectionProvider.clear();
doInHibernate( this::sessionFactory, s -> {
inTransaction( s -> {
Person person = new Person();
person.id = 1L;
s.persist( person );
@ -104,16 +107,16 @@ public class JdbcTimestampCustomTimeZoneTest
calendarArgumentCaptor.getValue().getTimeZone()
);
}
catch ( SQLException e ) {
catch (SQLException e) {
fail( e.getMessage() );
}
connectionProvider.clear();
doInHibernate( this::sessionFactory, s -> {
inTransaction( s -> {
s.doWork( connection -> {
try ( Statement st = connection.createStatement() ) {
try ( ResultSet rs = st.executeQuery(
"select createdOn from Person" ) ) {
try (Statement st = connection.createStatement()) {
try (ResultSet rs = st.executeQuery(
"select createdOn from Person" )) {
while ( rs.next() ) {
Timestamp timestamp = rs.getTimestamp( 1 );
int offsetDiff = TimeZone.getDefault()

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.timestamp;
package org.hibernate.orm.test.timestamp;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -12,60 +12,59 @@ import java.sql.Statement;
import java.sql.Time;
import java.time.LocalTime;
import java.util.GregorianCalendar;
import java.util.Map;
import java.util.TimeZone;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.jboss.logging.Logger;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Vlad Mihalcea
*/
@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsJdbcDriverProxying.class)
@TestForIssue(jiraKey = "HHH-12988")
@SkipForDialect(MySQL5Dialect.class)
public class JdbcTimestampDSTWithUTCTest
extends BaseNonConfigCoreFunctionalTestCase {
@SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true)
@DomainModel(
annotatedClasses = JdbcTimestampDSTWithUTCTest.Person.class
)
@SessionFactory
@ServiceRegistry(
settings = @Setting(name = AvailableSettings.JDBC_TIME_ZONE, value = "UTC")
)
public class JdbcTimestampDSTWithUTCTest {
protected final Logger log = Logger.getLogger( getClass() );
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Person.class
};
}
@Override
protected void addSettings(Map settings) {
settings.put(
AvailableSettings.JDBC_TIME_ZONE,
"UTC"
@AfterEach
public void tearDown(SessionFactoryScope scope) {
scope.inTransaction(
session ->
session.createQuery( "delete from Person" ).executeUpdate()
);
}
@Override
protected boolean isCleanupTestDataRequired() {
return true;
}
@Test
public void testHibernate() {
doInHibernate( this::sessionFactory, session -> {
public void testHibernate(SessionFactoryScope scope) {
scope.inTransaction( session -> {
Person person = new Person();
person.setId( 1L );
@ -74,7 +73,7 @@ public class JdbcTimestampDSTWithUTCTest
session.persist( person );
} );
doInHibernate( this::sessionFactory, session -> {
scope.inTransaction( session -> {
Person person = session.find( Person.class, 1L );
assertEquals( LocalTime.of( 12, 0, 0 ), person.getShiftStartTime() );
@ -82,8 +81,8 @@ public class JdbcTimestampDSTWithUTCTest
}
@Test
public void testJDBC() {
doInHibernate( this::sessionFactory, session -> {
public void testJDBC(SessionFactoryScope scope) {
scope.inTransaction( session -> {
session.doWork( connection -> {
Time time = Time.valueOf( LocalTime.of( 12, 0, 0 ) );
@ -110,8 +109,8 @@ public class JdbcTimestampDSTWithUTCTest
}
@Test
public void testDBTimeValueAsEpochDST() {
doInHibernate( this::sessionFactory, session -> {
public void testDBTimeValueAsEpochDST(SessionFactoryScope scope) {
scope.inTransaction( session -> {
session.doWork( connection -> {
Time time = Time.valueOf( LocalTime.of( 12, 0, 0 ) );

View File

@ -4,27 +4,28 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.timestamp;
package org.hibernate.orm.test.timestamp;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Map;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider;
import org.junit.Test;
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.times;
@ -33,11 +34,14 @@ import static org.mockito.Mockito.verify;
/**
* @author Vlad Mihalcea
*/
@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsJdbcDriverProxying.class)
public class JdbcTimestampDefaultTimeZoneTest
extends BaseNonConfigCoreFunctionalTestCase {
extends BaseSessionFactoryFunctionalTest {
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider( true, false );
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider(
true,
false
);
@Override
protected Class<?>[] getAnnotatedClasses() {
@ -47,17 +51,17 @@ public class JdbcTimestampDefaultTimeZoneTest
}
@Override
protected void addSettings(Map settings) {
connectionProvider.setConnectionProvider( (ConnectionProvider) settings.get( AvailableSettings.CONNECTION_PROVIDER ) );
settings.put(
protected void applySettings(StandardServiceRegistryBuilder builder) {
connectionProvider.setConnectionProvider( (ConnectionProvider) builder.getSettings()
.get( AvailableSettings.CONNECTION_PROVIDER ) );
builder.applySetting(
AvailableSettings.CONNECTION_PROVIDER,
connectionProvider
);
}
@Override
@AfterAll
protected void releaseResources() {
super.releaseResources();
connectionProvider.stop();
}
@ -65,7 +69,7 @@ public class JdbcTimestampDefaultTimeZoneTest
public void testTimeZone() {
connectionProvider.clear();
doInHibernate( this::sessionFactory, s -> {
inTransaction( s -> {
Person person = new Person();
person.id = 1L;
s.persist( person );
@ -81,11 +85,11 @@ public class JdbcTimestampDefaultTimeZoneTest
any( Timestamp.class )
);
}
catch ( SQLException e ) {
catch (SQLException e) {
fail( e.getMessage() );
}
doInHibernate( this::sessionFactory, s -> {
inTransaction( s -> {
Person person = s.find( Person.class, 1L );
assertEquals( 0, person.createdOn.getTime() );
} );

View File

@ -4,47 +4,50 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.timestamp;
package org.hibernate.orm.test.timestamp;
import java.util.Map;
import java.util.TimeZone;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.PostgreSQL82Dialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.orm.jdbc.TimeZoneConnectionProvider;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.junit.jupiter.api.AfterAll;
/**
* @author Vlad Mihalcea
*/
@RequiresDialect(value = PostgreSQL82Dialect.class)
public class JdbcTimestampUTCTimeZoneTest
extends JdbcTimestampWithoutUTCTimeZoneTest {
@RequiresDialect(value = PostgreSQLDialect.class, version = 820)
public class JdbcTimestampUTCTimeZoneTest extends JdbcTimestampWithoutUTCTimeZoneTest {
private TimeZoneConnectionProvider connectionProvider = new TimeZoneConnectionProvider(
"America/Los_Angeles" );
private TimeZoneConnectionProvider connectionProvider;
private static final TimeZone TIME_ZONE = TimeZone.getTimeZone( "UTC" );
@Override
protected void addSettings(Map settings) {
connectionProvider.setConnectionProvider( (ConnectionProvider) settings.get( AvailableSettings.CONNECTION_PROVIDER ) );
settings.put(
protected void applySettings(StandardServiceRegistryBuilder builder) {
connectionProvider = new TimeZoneConnectionProvider(
"America/Los_Angeles" );
connectionProvider.setConnectionProvider( (ConnectionProvider) builder.getSettings()
.get( AvailableSettings.CONNECTION_PROVIDER ) );
builder.applySetting(
AvailableSettings.CONNECTION_PROVIDER,
connectionProvider
);
settings.put(
builder.applySetting(
AvailableSettings.JDBC_TIME_ZONE,
TIME_ZONE
);
}
@Override
@AfterAll
protected void releaseResources() {
super.releaseResources();
connectionProvider.stop();
if ( connectionProvider != null ) {
connectionProvider.stop();
}
}
protected String expectedTimestampValue() {

View File

@ -4,40 +4,43 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.timestamp;
import java.util.Map;
package org.hibernate.orm.test.timestamp;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.PostgreSQL82Dialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.orm.jdbc.TimeZoneConnectionProvider;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.junit.jupiter.api.AfterAll;
/**
* @author Vlad Mihalcea
*/
@RequiresDialect(value = PostgreSQL82Dialect.class)
@RequiresDialect(value = PostgreSQLDialect.class, version = 820)
public class JdbcTimestampWithDefaultUTCTimeZoneTest
extends JdbcTimestampWithoutUTCTimeZoneTest {
private TimeZoneConnectionProvider connectionProvider = new TimeZoneConnectionProvider(
"UTC" );
private TimeZoneConnectionProvider connectionProvider;
@Override
protected void addSettings(Map settings) {
connectionProvider.setConnectionProvider( (ConnectionProvider) settings.get( AvailableSettings.CONNECTION_PROVIDER ) );
settings.put(
protected void applySettings(StandardServiceRegistryBuilder builder) {
connectionProvider = new TimeZoneConnectionProvider(
"UTC" );
connectionProvider.setConnectionProvider( (ConnectionProvider) builder.getSettings()
.get( AvailableSettings.CONNECTION_PROVIDER ) );
builder.applySetting(
AvailableSettings.CONNECTION_PROVIDER,
connectionProvider
);
}
@Override
@AfterAll
protected void releaseResources() {
super.releaseResources();
connectionProvider.stop();
if ( connectionProvider != null ) {
connectionProvider.stop();
}
}
protected String expectedTimestampValue() {

View File

@ -4,40 +4,39 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.timestamp;
package org.hibernate.orm.test.timestamp;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Map;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.CockroachDialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.testing.orm.jdbc.TimeZoneConnectionProvider;
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.CockroachDialect;
import org.hibernate.dialect.PostgreSQL82Dialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.hibernate.testing.orm.jdbc.TimeZoneConnectionProvider;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Vlad Mihalcea
*/
@RequiresDialect(value = PostgreSQL82Dialect.class)
public class JdbcTimestampWithoutUTCTimeZoneTest
extends BaseNonConfigCoreFunctionalTestCase {
@RequiresDialect(value = PostgreSQLDialect.class, version = 820)
public class JdbcTimestampWithoutUTCTimeZoneTest extends BaseSessionFactoryFunctionalTest {
private TimeZoneConnectionProvider connectionProvider = new TimeZoneConnectionProvider(
"America/Los_Angeles" );
private TimeZoneConnectionProvider connectionProvider;
@Override
protected Class<?>[] getAnnotatedClasses() {
@ -47,24 +46,27 @@ public class JdbcTimestampWithoutUTCTimeZoneTest
}
@Override
protected void addSettings(Map settings) {
connectionProvider.setConnectionProvider( (ConnectionProvider) settings.get( AvailableSettings.CONNECTION_PROVIDER ) );
settings.put(
protected void applySettings(StandardServiceRegistryBuilder builder) {
connectionProvider = new TimeZoneConnectionProvider( "America/Los_Angeles" );
connectionProvider.setConnectionProvider( (ConnectionProvider) builder.getSettings()
.get( AvailableSettings.CONNECTION_PROVIDER ) );
builder.applySetting(
AvailableSettings.CONNECTION_PROVIDER,
connectionProvider
);
}
@Override
@AfterAll
protected void releaseResources() {
super.releaseResources();
connectionProvider.stop();
if ( connectionProvider != null ) {
connectionProvider.stop();
}
}
@Test
@SkipForDialect(value = CockroachDialect.class, comment = "https://github.com/cockroachdb/cockroach/issues/3781")
@SkipForDialect(dialectClass = CockroachDialect.class, matchSubTypes = true, reason = "https://github.com/cockroachdb/cockroach/issues/3781")
public void testTimeZone() {
doInHibernate( this::sessionFactory, session -> {
inTransaction( session -> {
Person person = new Person();
person.id = 1L;
long y2kMillis = LocalDateTime.of( 2000, 1, 1, 0, 0, 0 )
@ -77,12 +79,12 @@ public class JdbcTimestampWithoutUTCTimeZoneTest
session.persist( person );
} );
doInHibernate( this::sessionFactory, s -> {
inTransaction( s -> {
s.doWork( connection -> {
try ( Statement st = connection.createStatement() ) {
try ( ResultSet rs = st.executeQuery(
try (Statement st = connection.createStatement()) {
try (ResultSet rs = st.executeQuery(
"SELECT to_char(createdon, 'YYYY-MM-DD HH24:MI:SS.US') " +
"FROM person" ) ) {
"FROM person" )) {
while ( rs.next() ) {
String timestamp = rs.getString( 1 );
assertEquals( expectedTimestampValue(), timestamp );

View File

@ -6,7 +6,7 @@
*/
//$Id: Person.java 8054 2005-08-31 20:12:24Z oneovthafew $
package org.hibernate.test.timestamp;
package org.hibernate.orm.test.timestamp;
import java.util.Date;
/**

View File

@ -0,0 +1,92 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.timestamp;
import java.util.Date;
import org.hibernate.cfg.Environment;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Gavin King
*/
@DomainModel(
xmlMappings = "org/hibernate/orm/test/timestamp/User.hbm.xml"
)
@SessionFactory
@ServiceRegistry(
settings = @Setting(name = Environment.GENERATE_STATISTICS,value = "true")
)
public class TimestampTest {
@Test
public void testUpdateFalse(SessionFactoryScope scope) {
final StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
statistics.clear();
scope.inTransaction(
session -> {
User u = new User( "gavin", "secret", new Person( "Gavin King", new Date(), "Karbarook Ave" ) );
session.persist( u );
session.flush();
u.getPerson().setName( "XXXXYYYYY" );
}
);
assertEquals( 1, statistics.getEntityInsertCount() );
assertEquals( 0, statistics.getEntityUpdateCount() );
scope.inTransaction(
session -> {
User u = session.get( User.class, "gavin" );
assertEquals( u.getPerson().getName(), "Gavin King" );
session.delete( u );
}
);
assertEquals( 1, statistics.getEntityDeleteCount() );
}
@Test
public void testComponent(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
User u = new User( "gavin", "secret", new Person( "Gavin King", new Date(), "Karbarook Ave" ) );
session.persist( u );
session.flush();
u.getPerson().setCurrentAddress( "Peachtree Rd" );
}
);
scope.inTransaction(
session -> {
User u = session.get( User.class, "gavin" );
u.setPassword( "$ecret" );
}
);
scope.inTransaction(
session -> {
User u = session.get( User.class, "gavin" );
assertEquals( u.getPassword(), "$ecret" );
session.delete( u );
}
);
}
}

View File

@ -13,7 +13,7 @@
-->
<hibernate-mapping package="org.hibernate.test.timestamp">
<hibernate-mapping package="org.hibernate.orm.test.timestamp">
<class name="User" table="T_USER" dynamic-update="true">
<id name="userName"/>

View File

@ -6,7 +6,7 @@
*/
//$Id: User.java 8054 2005-08-31 20:12:24Z oneovthafew $
package org.hibernate.test.timestamp;
package org.hibernate.orm.test.timestamp;
import java.util.Date;
/**

View File

@ -9,27 +9,29 @@ package org.hibernate.test.timestamp;
import java.time.LocalDate;
import java.util.Map;
import java.util.TimeZone;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.jdbc.ConnectionProviderDelegate;
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.jdbc.ConnectionProviderDelegate;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernateSessionBuilder;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Vlad Mihalcea
*/
@RequiresDialect(MySQL5Dialect.class)
public class LocalDateCustomSessionLevelTimeZoneTest
extends BaseNonConfigCoreFunctionalTestCase {
@RequiresDialect(value = MySQLDialect.class)
public class LocalDateCustomSessionLevelTimeZoneTest extends BaseSessionFactoryFunctionalTest {
private static final TimeZone TIME_ZONE = TimeZone.getTimeZone(
"Europe/Berlin" );
@ -38,16 +40,16 @@ public class LocalDateCustomSessionLevelTimeZoneTest
@Override
public void configure(Map configurationValues) {
String url = (String) configurationValues.get( AvailableSettings.URL );
if(!url.contains( "?" )) {
if ( !url.contains( "?" ) ) {
url += "?";
}
else if(!url.endsWith( "&" )) {
else if ( !url.endsWith( "&" ) ) {
url += "&";
}
url += "useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Europe/Berlin";
configurationValues.put( AvailableSettings.URL, url);
configurationValues.put( AvailableSettings.URL, url );
super.configure( configurationValues );
}
};
@ -60,21 +62,22 @@ public class LocalDateCustomSessionLevelTimeZoneTest
}
@Override
protected void addSettings(Map settings) {
settings.put(
protected void applySettings(StandardServiceRegistryBuilder builder) {
connectionProvider.setConnectionProvider( (ConnectionProvider) builder.getSettings()
.get( AvailableSettings.CONNECTION_PROVIDER ) );
builder.applySetting(
AvailableSettings.CONNECTION_PROVIDER,
connectionProvider
);
}
@Override
@AfterAll
protected void releaseResources() {
super.releaseResources();
connectionProvider.stop();
}
@Test
@TestForIssue( jiraKey = "HHH-11396" )
@TestForIssue(jiraKey = "HHH-11396")
public void testTimeZone() {
TimeZone old = TimeZone.getDefault();
try {

View File

@ -1,88 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.timestamp;
import java.util.Date;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author Gavin King
*/
public class TimestampTest extends BaseCoreFunctionalTestCase {
public String[] getMappings() {
return new String[] { "timestamp/User.hbm.xml" };
}
public void configure(Configuration cfg) {
cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
}
@Test
public void testUpdateFalse() {
sessionFactory().getStatistics().clear();
Session s = openSession();
Transaction t = s.beginTransaction();
User u = new User( "gavin", "secret", new Person("Gavin King", new Date(), "Karbarook Ave") );
s.persist(u);
s.flush();
u.getPerson().setName("XXXXYYYYY");
t.commit();
s.close();
assertEquals( 1, sessionFactory().getStatistics().getEntityInsertCount() );
assertEquals( 0, sessionFactory().getStatistics().getEntityUpdateCount() );
s = openSession();
t = s.beginTransaction();
u = (User) s.get(User.class, "gavin");
assertEquals( u.getPerson().getName(), "Gavin King" );
s.delete(u);
t.commit();
s.close();
assertEquals( 1, sessionFactory().getStatistics().getEntityDeleteCount() );
}
@Test
public void testComponent() {
Session s = openSession();
Transaction t = s.beginTransaction();
User u = new User( "gavin", "secret", new Person("Gavin King", new Date(), "Karbarook Ave") );
s.persist(u);
s.flush();
u.getPerson().setCurrentAddress("Peachtree Rd");
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
u = (User) s.get(User.class, "gavin");
u.setPassword("$ecret");
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
u = (User) s.get(User.class, "gavin");
assertEquals( u.getPassword(), "$ecret" );
s.delete(u);
t.commit();
s.close();
}
}

View File

@ -16,7 +16,11 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.hibernate.Session;
import org.hibernate.SessionBuilder;
import org.hibernate.Transaction;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataBuilder;
import org.hibernate.boot.MetadataSources;
@ -37,6 +41,7 @@ import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.testing.jdbc.SharedDriverManagerConnectionProviderImpl;
import org.hibernate.testing.transaction.TransactionUtil;
import org.junit.jupiter.api.AfterEach;
import org.jboss.logging.Logger;
@ -320,4 +325,52 @@ public abstract class BaseSessionFactoryFunctionalTest
}
}
/**
* Execute function in a Hibernate transaction without return value
*
* @param sessionBuilderSupplier SessionFactory supplier
* @param function function
*/
public static void doInHibernateSessionBuilder(
Supplier<SessionBuilder> sessionBuilderSupplier,
TransactionUtil.HibernateTransactionConsumer function) {
Session session = null;
Transaction txn = null;
try {
session = sessionBuilderSupplier.get().openSession();
function.beforeTransactionCompletion();
txn = session.beginTransaction();
function.accept( session );
if ( !txn.getRollbackOnly() ) {
txn.commit();
}
else {
try {
txn.rollback();
}
catch (Exception e) {
log.error( "Rollback failure", e );
}
}
}
catch ( Throwable t ) {
if ( txn != null && txn.isActive() ) {
try {
txn.rollback();
}
catch (Exception e) {
log.error( "Rollback failure", e );
}
}
throw t;
}
finally {
function.afterTransactionCompletion();
if ( session != null ) {
session.close();
}
}
}
}