From 61d1891f5503b1e6737fa873aed2cc8e47203b3b Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Tue, 21 Sep 2021 09:11:49 +0200 Subject: [PATCH] Re-enabled additional tests --- .../test/annotations/comment/CommentTest.java | 11 ++-- .../OneToOneCacheEnableSelectingTest.java | 62 ++++++++++--------- 2 files changed, 38 insertions(+), 35 deletions(-) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/comment/CommentTest.java (90%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/onetoone/cache/OneToOneCacheEnableSelectingTest.java (61%) diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/comment/CommentTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/comment/CommentTest.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/comment/CommentTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/comment/CommentTest.java index e9b16c52b5..0a14bf3f7b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/comment/CommentTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/comment/CommentTest.java @@ -4,10 +4,10 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.annotations.comment; +package org.hibernate.orm.test.annotations.comment; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; import java.util.Iterator; import java.util.stream.StreamSupport; @@ -26,13 +26,14 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.mapping.Column; import org.hibernate.mapping.Table; import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.junit.Test; +import org.hibernate.testing.orm.junit.BaseUnitTest; +import org.junit.jupiter.api.Test; /** * @author Yanming Zhou */ -public class CommentTest extends BaseUnitTestCase { +@BaseUnitTest +public class CommentTest { private static final String TABLE_NAME = "TestEntity"; private static final String TABLE_COMMENT = "I am table"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/onetoone/cache/OneToOneCacheEnableSelectingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/onetoone/cache/OneToOneCacheEnableSelectingTest.java similarity index 61% rename from hibernate-core/src/test/java/org/hibernate/test/onetoone/cache/OneToOneCacheEnableSelectingTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/onetoone/cache/OneToOneCacheEnableSelectingTest.java index 35b0aa031e..4f9caa439d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/onetoone/cache/OneToOneCacheEnableSelectingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/onetoone/cache/OneToOneCacheEnableSelectingTest.java @@ -1,4 +1,4 @@ -package org.hibernate.test.onetoone.cache; +package org.hibernate.orm.test.onetoone.cache; import java.util.concurrent.atomic.AtomicLong; import javax.persistence.Cacheable; @@ -11,65 +11,67 @@ import javax.persistence.OneToOne; import javax.persistence.Version; import org.hibernate.cfg.AvailableSettings; -import org.hibernate.cfg.Configuration; import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Test; +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.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; @TestForIssue( jiraKey = "HHH-14826") -public class OneToOneCacheEnableSelectingTest extends BaseCoreFunctionalTestCase { - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - Product.class, - ProductConfig.class - }; - } - - @Override - protected void configure(Configuration configuration) { - configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "true"); - configuration.setProperty(AvailableSettings.JPA_SHARED_CACHE_MODE, "ENABLE_SELECTIVE"); - configuration.setProperty(AvailableSettings.GENERATE_STATISTICS, "true"); - } +@DomainModel( + annotatedClasses = { + OneToOneCacheEnableSelectingTest.Product.class, + OneToOneCacheEnableSelectingTest.ProductConfig.class + } +) +@SessionFactory(generateStatistics = true) +@ServiceRegistry( + settings = { + @Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true"), + @Setting( name = AvailableSettings.JPA_SHARED_CACHE_MODE, value = "ENABLE_SELECTIVE") + } +) +public class OneToOneCacheEnableSelectingTest { @Test - public void testFieldShouldNotBeNull() { + public void testFieldShouldNotBeNull(SessionFactoryScope scope) { final AtomicLong pid = new AtomicLong(); // create Product - inTransaction(s -> { + scope.inTransaction(s -> { Product product = new Product(); s.persist(product); pid.set(product.getId()); }); // create ProductConfig and associate with a Product - inTransaction(s -> { + scope.inTransaction(s -> { Product product = s.find(Product.class, pid.get()); ProductConfig config = new ProductConfig(); config.setProduct(product); s.persist(config); }); - assertTrue(sessionFactory().getCache().containsEntity(Product.class, pid.get())); + assertTrue(scope.getSessionFactory().getCache().containsEntity(Product.class, pid.get())); - sessionFactory().getStatistics().clear(); + scope.getSessionFactory().getStatistics().clear(); // now fetch the Product again - inTransaction(s -> { + scope.inTransaction(s -> { Product product = s.find(Product.class, pid.get()); // should have been from cache - assertNotEquals (0, sessionFactory().getStatistics().getSecondLevelCacheHitCount()); + assertNotEquals (0, scope.getSessionFactory().getStatistics().getSecondLevelCacheHitCount()); // this should not fail - assertNotNull("one-to-one field should not be null", product.getConfig()); + assertNotNull( product.getConfig(), "one-to-one field should not be null"); }); }