From 1c203f35ec10602041fb10bca640efa2ed86195e Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Sat, 12 Mar 2011 12:19:56 -0600 Subject: [PATCH] HHH-5942 - Migrate to JUnit 4 --- build.gradle | 2 +- .../SequenceHiLoGeneratorNoIncrementTest.java | 4 +- .../annotations/backquotes/BackquoteTest.java | 2 +- .../fetchprofile/FetchProfileTest.java | 344 ++-- .../fkcircularity/FkCircularityTest.java | 124 +- .../test/annotations/id/EnumIdTest.java | 2 +- .../id/JoinColumnOverrideTest.java | 118 +- .../annotations/id/sequences/EnumIdTest.java | 2 +- .../id/sequences/JoinColumnOverrideTest.java | 2 +- .../annotations/immutable/ImmutableTest.java | 2 +- .../namingstrategy/NamingStrategyTest.java | 2 +- .../NaturalIdOnSingleManyToOneTest.java | 2 +- .../primarykey/NullablePrimaryKeyTest.java | 2 +- .../annotations/reflection/LogListener.java | 44 +- .../reflection/OtherLogListener.java | 42 +- .../common/BasicTestingJdbcServiceImpl.java | 4 +- .../test/common/jta/AtomikosJtaPlatform.java | 2 +- .../connections/SuppliedConnectionTest.java | 2 +- .../cache/SQLFunctionsInterSystemsTest.java | 1542 ++++++++--------- .../test/filter/DynamicFilterTest.java | 38 +- .../test/hql/ASTParserLoadingTest.java | 2 +- .../test/hql/BulkManipulationTest.java | 21 +- .../test/jdbc/proxies/BatchingTest.java | 2 +- .../test/jpa/cascade/CascadeTest.java | 2 +- .../org/hibernate/test/legacy/FooBarTest.java | 281 +-- .../test/legacy/SQLFunctionsTest.java | 2 +- .../namingstrategy/NamingStrategyTest.java | 2 +- .../service/ServiceBootstrappingTest.java | 2 +- .../StatelessSessionFetchingTest.java | 2 +- .../transaction/jdbc/TestExpectedUsage.java | 2 +- .../transaction/jta/BasicDrivingTest.java | 2 +- .../transaction/jta/ManagedDrivingTest.java | 2 +- .../DefaultValueIntegerType.java | 2 +- .../hibernate/test/util/StringHelperTest.java | 99 +- .../annotations/HibernateTestCase.java | 1 - .../testing/tm/ConnectionProviderImpl.java | 3 +- .../testing/tm/SimpleJtaTransactionImpl.java | 2 +- .../test/java/org/hibernate/ejb/test/Cat.java | 2 +- .../java/org/hibernate/ejb/test/TestCase.java | 2 +- .../hibernate/ejb/test/emops/RemoveTest.java | 206 +-- .../ejb/test/exception/ExceptionTest.java | 266 +-- .../org/hibernate/ejb/test/lock/LockTest.java | 2 +- .../components/DefaultValueComponents.java | 2 +- .../hibernate-infinispan.gradle | 2 +- ...bstractEntityCollectionRegionTestCase.java | 139 +- .../AbstractGeneralDataRegionTestCase.java | 2 +- .../AbstractNonFunctionalTestCase.java | 2 +- ...ollectionRegionAccessStrategyTestCase.java | 2 +- .../AbstractReadOnlyAccessTestCase.java | 4 +- .../TransactionalExtraAPITestCase.java | 1 + ...actEntityRegionAccessStrategyTestCase.java | 2 +- .../AbstractTransactionalAccessTestCase.java | 2 +- .../entity/TransactionalExtraAPITestCase.java | 4 +- .../BasicTransactionalTestCase.java | 42 +- .../functional/JndiRegionFactoryTestCase.java | 3 + .../classloader/CacheAccessListener.java | 2 +- .../classloader/IsolatedClassLoaderTest.java | 29 +- .../SelectedClassnameClassLoader.java | 2 +- .../DualNodeConnectionProviderImpl.java | 13 +- .../cluster/SessionRefreshTestCase.java | 2 +- .../query/QueryRegionImplTestCase.java | 2 +- .../infinispan/tm/XaConnectionProvider.java | 3 +- .../infinispan/util/CacheTestSupport.java | 2 +- hibernate-testing/hibernate-testing.gradle | 23 + .../java/org/hibernate/testing/SkipLog.java | 6 +- .../org/hibernate/testing}/TestLogger.java | 5 +- .../org/hibernate/testing/TestingLogger.java | 35 - .../env}/ConnectionProviderBuilder.java | 8 +- 68 files changed, 1782 insertions(+), 1746 deletions(-) rename {hibernate-core/src/test/java/org/hibernate => hibernate-testing/src/main/java/org/hibernate/testing}/TestLogger.java (93%) delete mode 100644 hibernate-testing/src/main/java/org/hibernate/testing/TestingLogger.java rename {hibernate-core/src/test/java/org/hibernate/test/common => hibernate-testing/src/main/java/org/hibernate/testing/env}/ConnectionProviderBuilder.java (91%) diff --git a/build.gradle b/build.gradle index f730375059..4268fd6139 100644 --- a/build.gradle +++ b/build.gradle @@ -70,7 +70,7 @@ libraries = [ // testing atomikos: 'com.atomikos:transactions-jdbc:3.7.0', - junit: 'junit:junit:3.8.2', + junit: 'junit:junit:4.8.2', testng: 'org.testng:testng:5.8:jdk15', jpa_modelgen: 'org.hibernate:hibernate-jpamodelgen:1.1.1.Final', shrinkwrap_api: 'org.jboss.shrinkwrap:shrinkwrap-api:1.0.0-alpha-6', diff --git a/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java b/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java index c8ac1bb968..f4e9b1e7d0 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java @@ -69,7 +69,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase { private SequenceHiLoGenerator generator; @Before - protected void setUp() throws Exception { + public void setUp() throws Exception { Properties properties = new Properties(); properties.setProperty( SequenceGenerator.SEQUENCE, TEST_SEQUENCE ); properties.setProperty( SequenceHiLoGenerator.MAX_LO, "0" ); // JPA allocationSize of 1 @@ -107,7 +107,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase { } @After - protected void tearDown() throws Exception { + public void tearDown() throws Exception { if ( sessionFactory != null ) { sessionFactory.close(); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/backquotes/BackquoteTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/backquotes/BackquoteTest.java index 37c2948350..387d445e9b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/backquotes/BackquoteTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/backquotes/BackquoteTest.java @@ -1,7 +1,7 @@ //$Id$ package org.hibernate.test.annotations.backquotes; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.io.PrintWriter; import java.io.StringWriter; import junit.framework.TestCase; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java index 2da3122e84..1659e92650 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java @@ -1,175 +1,175 @@ -// $Id$ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2010, Red Hat Middleware LLC or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - * - */ +// $Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Middleware LLC or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Middleware LLC. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + * + */ package org.hibernate.test.annotations.fetchprofile; - -import static org.hibernate.TestLogger.LOG; -import java.io.InputStream; -import junit.framework.TestCase; -import org.hibernate.MappingException; -import org.hibernate.cfg.AnnotationConfiguration; -import org.hibernate.cfg.Environment; -import org.hibernate.engine.SessionFactoryImplementor; -import org.hibernate.service.spi.ServiceRegistry; -import org.hibernate.testing.ServiceRegistryBuilder; - -/** - * Test case for HHH-4812 - * - * @author Hardy Ferentschik - */ -public class FetchProfileTest extends TestCase { - - private ServiceRegistry serviceRegistry; - - @Override - protected void setUp() { - serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() ); - } - - @Override - protected void tearDown() { - if (serviceRegistry != null) ServiceRegistryBuilder.destroy(serviceRegistry); - } - - public void testFetchProfileConfigured() { - AnnotationConfiguration config = new AnnotationConfiguration(); - config.addAnnotatedClass( Customer.class ); - config.addAnnotatedClass( Order.class ); - config.addAnnotatedClass( SupportTickets.class ); - config.addAnnotatedClass( Country.class ); - SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory( - serviceRegistry - ); - - assertTrue( - "fetch profile not parsed properly", - sessionImpl.containsFetchProfileDefinition( "customer-with-orders" ) - ); - assertFalse( - "package info should not be parsed", - sessionImpl.containsFetchProfileDefinition( "package-profile-1" ) - ); - } - - public void testWrongAssociationName() { - AnnotationConfiguration config = new AnnotationConfiguration(); - config.addAnnotatedClass( Customer2.class ); - config.addAnnotatedClass( Order.class ); - config.addAnnotatedClass( Country.class ); - - try { - config.buildSessionFactory( serviceRegistry ); - fail(); - } - catch ( MappingException e ) { - LOG.trace("success"); - } - } - - public void testWrongClass() { - AnnotationConfiguration config = new AnnotationConfiguration(); - config.addAnnotatedClass( Customer3.class ); - config.addAnnotatedClass( Order.class ); - config.addAnnotatedClass( Country.class ); - - try { - config.buildSessionFactory( serviceRegistry ); - fail(); - } - catch ( MappingException e ) { - LOG.trace("success"); - } - } - - public void testUnsupportedFetchMode() { - AnnotationConfiguration config = new AnnotationConfiguration(); - config.addAnnotatedClass( Customer4.class ); - config.addAnnotatedClass( Order.class ); - config.addAnnotatedClass( Country.class ); - - try { - config.buildSessionFactory( serviceRegistry ); - fail(); - } - catch ( MappingException e ) { - LOG.trace("success"); - } - } - - public void testXmlOverride() { - AnnotationConfiguration config = new AnnotationConfiguration(); - config.addAnnotatedClass( Customer5.class ); - config.addAnnotatedClass( Order.class ); - config.addAnnotatedClass( Country.class ); - InputStream is = Thread.currentThread() - .getContextClassLoader() - .getResourceAsStream( "org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml" ); - config.addInputStream( is ); - SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory( - serviceRegistry - ); - - assertTrue( - "fetch profile not parsed properly", - sessionImpl.containsFetchProfileDefinition( "orders-profile" ) - ); - - // now the same with no xml - config = new AnnotationConfiguration(); - config.addAnnotatedClass( Customer5.class ); - config.addAnnotatedClass( Order.class ); - config.addAnnotatedClass( Country.class ); - try { - config.buildSessionFactory( serviceRegistry ); - fail(); - } - catch ( MappingException e ) { - LOG.trace("success"); - } - } - - public void testPackageConfiguredFetchProfile() { - AnnotationConfiguration config = new AnnotationConfiguration(); - config.addAnnotatedClass( Customer.class ); - config.addAnnotatedClass( Order.class ); - config.addAnnotatedClass( SupportTickets.class ); - config.addAnnotatedClass( Country.class ); - config.addPackage( Customer.class.getPackage().getName() ); - SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory( - serviceRegistry - ); - - assertTrue( - "fetch profile not parsed properly", - sessionImpl.containsFetchProfileDefinition( "package-profile-1" ) - ); - assertTrue( - "fetch profile not parsed properly", - sessionImpl.containsFetchProfileDefinition( "package-profile-2" ) - ); - } + +import static org.hibernate.testing.TestLogger.LOG; +import java.io.InputStream; +import junit.framework.TestCase; +import org.hibernate.MappingException; +import org.hibernate.cfg.AnnotationConfiguration; +import org.hibernate.cfg.Environment; +import org.hibernate.engine.SessionFactoryImplementor; +import org.hibernate.service.spi.ServiceRegistry; +import org.hibernate.testing.ServiceRegistryBuilder; + +/** + * Test case for HHH-4812 + * + * @author Hardy Ferentschik + */ +public class FetchProfileTest extends TestCase { + + private ServiceRegistry serviceRegistry; + + @Override + protected void setUp() { + serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() ); + } + + @Override + protected void tearDown() { + if (serviceRegistry != null) ServiceRegistryBuilder.destroy(serviceRegistry); + } + + public void testFetchProfileConfigured() { + AnnotationConfiguration config = new AnnotationConfiguration(); + config.addAnnotatedClass( Customer.class ); + config.addAnnotatedClass( Order.class ); + config.addAnnotatedClass( SupportTickets.class ); + config.addAnnotatedClass( Country.class ); + SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory( + serviceRegistry + ); + + assertTrue( + "fetch profile not parsed properly", + sessionImpl.containsFetchProfileDefinition( "customer-with-orders" ) + ); + assertFalse( + "package info should not be parsed", + sessionImpl.containsFetchProfileDefinition( "package-profile-1" ) + ); + } + + public void testWrongAssociationName() { + AnnotationConfiguration config = new AnnotationConfiguration(); + config.addAnnotatedClass( Customer2.class ); + config.addAnnotatedClass( Order.class ); + config.addAnnotatedClass( Country.class ); + + try { + config.buildSessionFactory( serviceRegistry ); + fail(); + } + catch ( MappingException e ) { + LOG.trace("success"); + } + } + + public void testWrongClass() { + AnnotationConfiguration config = new AnnotationConfiguration(); + config.addAnnotatedClass( Customer3.class ); + config.addAnnotatedClass( Order.class ); + config.addAnnotatedClass( Country.class ); + + try { + config.buildSessionFactory( serviceRegistry ); + fail(); + } + catch ( MappingException e ) { + LOG.trace("success"); + } + } + + public void testUnsupportedFetchMode() { + AnnotationConfiguration config = new AnnotationConfiguration(); + config.addAnnotatedClass( Customer4.class ); + config.addAnnotatedClass( Order.class ); + config.addAnnotatedClass( Country.class ); + + try { + config.buildSessionFactory( serviceRegistry ); + fail(); + } + catch ( MappingException e ) { + LOG.trace("success"); + } + } + + public void testXmlOverride() { + AnnotationConfiguration config = new AnnotationConfiguration(); + config.addAnnotatedClass( Customer5.class ); + config.addAnnotatedClass( Order.class ); + config.addAnnotatedClass( Country.class ); + InputStream is = Thread.currentThread() + .getContextClassLoader() + .getResourceAsStream( "org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml" ); + config.addInputStream( is ); + SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory( + serviceRegistry + ); + + assertTrue( + "fetch profile not parsed properly", + sessionImpl.containsFetchProfileDefinition( "orders-profile" ) + ); + + // now the same with no xml + config = new AnnotationConfiguration(); + config.addAnnotatedClass( Customer5.class ); + config.addAnnotatedClass( Order.class ); + config.addAnnotatedClass( Country.class ); + try { + config.buildSessionFactory( serviceRegistry ); + fail(); + } + catch ( MappingException e ) { + LOG.trace("success"); + } + } + + public void testPackageConfiguredFetchProfile() { + AnnotationConfiguration config = new AnnotationConfiguration(); + config.addAnnotatedClass( Customer.class ); + config.addAnnotatedClass( Order.class ); + config.addAnnotatedClass( SupportTickets.class ); + config.addAnnotatedClass( Country.class ); + config.addPackage( Customer.class.getPackage().getName() ); + SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory( + serviceRegistry + ); + + assertTrue( + "fetch profile not parsed properly", + sessionImpl.containsFetchProfileDefinition( "package-profile-1" ) + ); + assertTrue( + "fetch profile not parsed properly", + sessionImpl.containsFetchProfileDefinition( "package-profile-2" ) + ); + } } \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java index 73ba10f0cd..8bbfaac1ca 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java @@ -1,7 +1,7 @@ // $Id$ package org.hibernate.test.annotations.fkcircularity; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.io.PrintWriter; import java.io.StringWriter; import junit.framework.TestCase; @@ -11,67 +11,67 @@ import org.hibernate.dialect.HSQLDialect; import org.hibernate.dialect.SQLServerDialect; import org.hibernate.service.spi.ServiceRegistry; import org.hibernate.testing.ServiceRegistryBuilder; - -/** - * Test case for ANN-722 and ANN-730. - * - * @author Hardy Ferentschik - */ -public class FkCircularityTest extends TestCase { - - private ServiceRegistry serviceRegistry; - + +/** + * Test case for ANN-722 and ANN-730. + * + * @author Hardy Ferentschik + */ +public class FkCircularityTest extends TestCase { + + private ServiceRegistry serviceRegistry; + @Override - protected void setUp() { - serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() ); - } - + protected void setUp() { + serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() ); + } + @Override - protected void tearDown() { - if (serviceRegistry != null) ServiceRegistryBuilder.destroy(serviceRegistry); - } - - public void testJoinedSublcassesInPK() { - try { - AnnotationConfiguration config = new AnnotationConfiguration(); - config.addAnnotatedClass(A.class); - config.addAnnotatedClass(B.class); - config.addAnnotatedClass(C.class); - config.addAnnotatedClass(D.class); - config.buildSessionFactory( serviceRegistry ); - String[] schema = config - .generateSchemaCreationScript(new SQLServerDialect()); - for (String s : schema) { - LOG.debug(s); - } - LOG.debug("success"); - } catch (Exception e) { - StringWriter writer = new StringWriter(); - e.printStackTrace(new PrintWriter(writer)); - LOG.debug(writer.toString()); - fail(e.getMessage()); - } - } - - public void testDeepJoinedSuclassesHierachy() { - try { - AnnotationConfiguration config = new AnnotationConfiguration(); - config.addAnnotatedClass(ClassA.class); - config.addAnnotatedClass(ClassB.class); - config.addAnnotatedClass(ClassC.class); - config.addAnnotatedClass(ClassD.class); - config.buildSessionFactory( serviceRegistry ); - String[] schema = config - .generateSchemaCreationScript(new HSQLDialect()); - for (String s : schema) { - LOG.debug(s); - } - LOG.debug("success"); - } catch (Exception e) { - StringWriter writer = new StringWriter(); - e.printStackTrace(new PrintWriter(writer)); - LOG.debug(writer.toString()); - fail(e.getMessage()); - } - } + protected void tearDown() { + if (serviceRegistry != null) ServiceRegistryBuilder.destroy(serviceRegistry); + } + + public void testJoinedSublcassesInPK() { + try { + AnnotationConfiguration config = new AnnotationConfiguration(); + config.addAnnotatedClass(A.class); + config.addAnnotatedClass(B.class); + config.addAnnotatedClass(C.class); + config.addAnnotatedClass(D.class); + config.buildSessionFactory( serviceRegistry ); + String[] schema = config + .generateSchemaCreationScript(new SQLServerDialect()); + for (String s : schema) { + LOG.debug(s); + } + LOG.debug("success"); + } catch (Exception e) { + StringWriter writer = new StringWriter(); + e.printStackTrace(new PrintWriter(writer)); + LOG.debug(writer.toString()); + fail(e.getMessage()); + } + } + + public void testDeepJoinedSuclassesHierachy() { + try { + AnnotationConfiguration config = new AnnotationConfiguration(); + config.addAnnotatedClass(ClassA.class); + config.addAnnotatedClass(ClassB.class); + config.addAnnotatedClass(ClassC.class); + config.addAnnotatedClass(ClassD.class); + config.buildSessionFactory( serviceRegistry ); + String[] schema = config + .generateSchemaCreationScript(new HSQLDialect()); + for (String s : schema) { + LOG.debug(s); + } + LOG.debug("success"); + } catch (Exception e) { + StringWriter writer = new StringWriter(); + e.printStackTrace(new PrintWriter(writer)); + LOG.debug(writer.toString()); + fail(e.getMessage()); + } + } } \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/EnumIdTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/EnumIdTest.java index 07b6143b13..fce31619ac 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/EnumIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/EnumIdTest.java @@ -1,6 +1,6 @@ //$Id$ package org.hibernate.test.annotations.id; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.test.annotations.TestCase; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/JoinColumnOverrideTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/JoinColumnOverrideTest.java index 995d1e2480..c8454c617f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/JoinColumnOverrideTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/JoinColumnOverrideTest.java @@ -1,60 +1,60 @@ -//$Id$ +//$Id$ package org.hibernate.test.annotations.id; -import static org.hibernate.TestLogger.LOG; -import java.io.PrintWriter; -import java.io.StringWriter; -import org.hibernate.cfg.AnnotationConfiguration; -import org.hibernate.dialect.SQLServerDialect; -import org.hibernate.test.annotations.TestCase; -import org.hibernate.test.annotations.id.entities.Bunny; -import org.hibernate.test.annotations.id.entities.PointyTooth; -import org.hibernate.test.annotations.id.entities.TwinkleToes; - -/** - * Tests for JIRA issue ANN-748. - * - * @author Hardy Ferentschik - */ -@SuppressWarnings("unchecked") -public class JoinColumnOverrideTest extends TestCase { - - public JoinColumnOverrideTest(String x) { - super(x); - } - - public void testBlownPrecision() throws Exception { - - try { - AnnotationConfiguration config = new AnnotationConfiguration(); - config.addAnnotatedClass(Bunny.class); - config.addAnnotatedClass(PointyTooth.class); - config.addAnnotatedClass(TwinkleToes.class); - config.buildSessionFactory( getServiceRegistry() ); - String[] schema = config - .generateSchemaCreationScript(new SQLServerDialect()); - for (String s : schema) { - LOG.debug(s); - } - String expectedSqlPointyTooth = "create table PointyTooth (id numeric(128,0) not null, " + - "bunny_id numeric(128,0) null, primary key (id))"; - assertEquals("Wrong SQL", expectedSqlPointyTooth, schema[1]); - - String expectedSqlTwinkleToes = "create table TwinkleToes (id numeric(128,0) not null, " + - "bunny_id numeric(128,0) null, primary key (id))"; - assertEquals("Wrong SQL", expectedSqlTwinkleToes, schema[2]); - } catch (Exception e) { - StringWriter writer = new StringWriter(); - e.printStackTrace(new PrintWriter(writer)); - LOG.debug(writer.toString()); - fail(e.getMessage()); - } - } - - /** - * @see org.hibernate.test.annotations.TestCase#getAnnotatedClasses() - */ - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] {}; - } -} +import static org.hibernate.testing.TestLogger.LOG; +import java.io.PrintWriter; +import java.io.StringWriter; +import org.hibernate.cfg.AnnotationConfiguration; +import org.hibernate.dialect.SQLServerDialect; +import org.hibernate.test.annotations.TestCase; +import org.hibernate.test.annotations.id.entities.Bunny; +import org.hibernate.test.annotations.id.entities.PointyTooth; +import org.hibernate.test.annotations.id.entities.TwinkleToes; + +/** + * Tests for JIRA issue ANN-748. + * + * @author Hardy Ferentschik + */ +@SuppressWarnings("unchecked") +public class JoinColumnOverrideTest extends TestCase { + + public JoinColumnOverrideTest(String x) { + super(x); + } + + public void testBlownPrecision() throws Exception { + + try { + AnnotationConfiguration config = new AnnotationConfiguration(); + config.addAnnotatedClass(Bunny.class); + config.addAnnotatedClass(PointyTooth.class); + config.addAnnotatedClass(TwinkleToes.class); + config.buildSessionFactory( getServiceRegistry() ); + String[] schema = config + .generateSchemaCreationScript(new SQLServerDialect()); + for (String s : schema) { + LOG.debug(s); + } + String expectedSqlPointyTooth = "create table PointyTooth (id numeric(128,0) not null, " + + "bunny_id numeric(128,0) null, primary key (id))"; + assertEquals("Wrong SQL", expectedSqlPointyTooth, schema[1]); + + String expectedSqlTwinkleToes = "create table TwinkleToes (id numeric(128,0) not null, " + + "bunny_id numeric(128,0) null, primary key (id))"; + assertEquals("Wrong SQL", expectedSqlTwinkleToes, schema[2]); + } catch (Exception e) { + StringWriter writer = new StringWriter(); + e.printStackTrace(new PrintWriter(writer)); + LOG.debug(writer.toString()); + fail(e.getMessage()); + } + } + + /** + * @see org.hibernate.test.annotations.TestCase#getAnnotatedClasses() + */ + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {}; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/EnumIdTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/EnumIdTest.java index c281659c98..f6037309d3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/EnumIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/EnumIdTest.java @@ -1,6 +1,6 @@ //$Id$ package org.hibernate.test.annotations.id.sequences; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.test.annotations.TestCase; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/JoinColumnOverrideTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/JoinColumnOverrideTest.java index 609f22228a..0ad6dbf3b8 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/JoinColumnOverrideTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/JoinColumnOverrideTest.java @@ -1,6 +1,6 @@ //$Id$ package org.hibernate.test.annotations.id.sequences; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.io.PrintWriter; import java.io.StringWriter; import org.hibernate.cfg.AnnotationConfiguration; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableTest.java index 9e31848c43..15550a88c8 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableTest.java @@ -1,6 +1,6 @@ //$Id$ package org.hibernate.test.annotations.immutable; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.util.ArrayList; import java.util.List; import org.hibernate.AnnotationException; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/namingstrategy/NamingStrategyTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/namingstrategy/NamingStrategyTest.java index e18a9660cb..890801bbbc 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/namingstrategy/NamingStrategyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/namingstrategy/NamingStrategyTest.java @@ -1,7 +1,7 @@ // $Id$ package org.hibernate.test.annotations.namingstrategy; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.io.PrintWriter; import java.io.StringWriter; import java.util.Iterator; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/naturalid/NaturalIdOnSingleManyToOneTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/naturalid/NaturalIdOnSingleManyToOneTest.java index f167afef4c..db2b3c1d21 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/naturalid/NaturalIdOnSingleManyToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/naturalid/NaturalIdOnSingleManyToOneTest.java @@ -1,6 +1,6 @@ //$Id$ package org.hibernate.test.annotations.naturalid; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Session; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/primarykey/NullablePrimaryKeyTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/primarykey/NullablePrimaryKeyTest.java index 18b8495812..a562ad605f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/primarykey/NullablePrimaryKeyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/primarykey/NullablePrimaryKeyTest.java @@ -1,7 +1,7 @@ //$Id: A320.java 14736 2008-06-04 14:23:42Z hardy.ferentschik $ package org.hibernate.test.annotations.onetoone.primarykey; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import junit.framework.TestCase; import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.Environment; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/reflection/LogListener.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/reflection/LogListener.java index 5adbd07864..8dd2ecbf54 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/reflection/LogListener.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/reflection/LogListener.java @@ -1,23 +1,23 @@ -//$Id$ +//$Id$ package org.hibernate.test.annotations.reflection; -import static org.hibernate.TestLogger.LOG; -import javax.persistence.PostPersist; -import javax.persistence.PrePersist; - - -/** - * @author Emmanuel Bernard - */ -public class LogListener { - - @PrePersist - @PostPersist - public void log(Object entity) { - LOG.debug("Logging entity " + entity.getClass().getName() + " with hashCode: " + entity.hashCode()); - } - - - public void noLog(Object entity) { - LOG.debug("NoLogging entity " + entity.getClass().getName() + " with hashCode: " + entity.hashCode()); - } -} +import static org.hibernate.testing.TestLogger.LOG; +import javax.persistence.PostPersist; +import javax.persistence.PrePersist; + + +/** + * @author Emmanuel Bernard + */ +public class LogListener { + + @PrePersist + @PostPersist + public void log(Object entity) { + LOG.debug("Logging entity " + entity.getClass().getName() + " with hashCode: " + entity.hashCode()); + } + + + public void noLog(Object entity) { + LOG.debug("NoLogging entity " + entity.getClass().getName() + " with hashCode: " + entity.hashCode()); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/reflection/OtherLogListener.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/reflection/OtherLogListener.java index 0c8de378e3..a3fb3e861e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/reflection/OtherLogListener.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/reflection/OtherLogListener.java @@ -1,22 +1,22 @@ -//$Id$ +//$Id$ package org.hibernate.test.annotations.reflection; -import static org.hibernate.TestLogger.LOG; -import javax.persistence.PostPersist; -import javax.persistence.PrePersist; - -/** - * @author Emmanuel Bernard - */ -public class OtherLogListener { - - @PrePersist - @PostPersist - public void log(Object entity) { - LOG.debug("Logging entity " + entity.getClass().getName() + " with hashCode: " + entity.hashCode()); - } - - - public void noLog(Object entity) { - LOG.debug("NoLogging entity " + entity.getClass().getName() + " with hashCode: " + entity.hashCode()); - } -} +import static org.hibernate.testing.TestLogger.LOG; +import javax.persistence.PostPersist; +import javax.persistence.PrePersist; + +/** + * @author Emmanuel Bernard + */ +public class OtherLogListener { + + @PrePersist + @PostPersist + public void log(Object entity) { + LOG.debug("Logging entity " + entity.getClass().getName() + " with hashCode: " + entity.hashCode()); + } + + + public void noLog(Object entity) { + LOG.debug("NoLogging entity " + entity.getClass().getName() + " with hashCode: " + entity.hashCode()); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/common/BasicTestingJdbcServiceImpl.java b/hibernate-core/src/test/java/org/hibernate/test/common/BasicTestingJdbcServiceImpl.java index 12bca3ff8b..a173554f28 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/common/BasicTestingJdbcServiceImpl.java +++ b/hibernate-core/src/test/java/org/hibernate/test/common/BasicTestingJdbcServiceImpl.java @@ -23,12 +23,10 @@ */ package org.hibernate.test.common; -import java.sql.ResultSet; import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; import org.hibernate.dialect.Dialect; -import org.hibernate.engine.jdbc.ColumnNameCache; import org.hibernate.engine.jdbc.LobCreationContext; import org.hibernate.engine.jdbc.LobCreator; import org.hibernate.engine.jdbc.internal.ResultSetWrapperImpl; @@ -41,6 +39,8 @@ import org.hibernate.engine.jdbc.spi.SqlStatementLogger; import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; import org.hibernate.service.spi.Stoppable; +import org.hibernate.testing.env.ConnectionProviderBuilder; + /** * Implementation of the {@link JdbcServices} contract for use by these diff --git a/hibernate-core/src/test/java/org/hibernate/test/common/jta/AtomikosJtaPlatform.java b/hibernate-core/src/test/java/org/hibernate/test/common/jta/AtomikosJtaPlatform.java index 521d81aeaf..a2460308eb 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/common/jta/AtomikosJtaPlatform.java +++ b/hibernate-core/src/test/java/org/hibernate/test/common/jta/AtomikosJtaPlatform.java @@ -33,7 +33,7 @@ import org.hibernate.service.jta.platform.internal.TransactionManagerBasedSynchr import org.hibernate.service.jta.platform.spi.JtaPlatformException; import org.hibernate.service.spi.Startable; import org.hibernate.service.spi.Stoppable; -import org.hibernate.test.common.ConnectionProviderBuilder; +import org.hibernate.testing.env.ConnectionProviderBuilder; import org.jboss.logging.Logger; import com.atomikos.icatch.jta.UserTransactionImp; import com.atomikos.icatch.jta.UserTransactionManager; diff --git a/hibernate-core/src/test/java/org/hibernate/test/connections/SuppliedConnectionTest.java b/hibernate-core/src/test/java/org/hibernate/test/connections/SuppliedConnectionTest.java index d85336d1fe..3e33a4497d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/connections/SuppliedConnectionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/connections/SuppliedConnectionTest.java @@ -35,7 +35,7 @@ import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; import org.hibernate.service.spi.Stoppable; import org.hibernate.tool.hbm2ddl.SchemaExport; -import org.hibernate.test.common.ConnectionProviderBuilder; +import org.hibernate.testing.env.ConnectionProviderBuilder; /** * Implementation of SuppliedConnectionTest. diff --git a/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java b/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java index 7e7eed9523..b8cc91ffc8 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java @@ -1,771 +1,771 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2010, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.test.dialect.functional.cache; - -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.hibernate.LockMode; -import org.hibernate.Query; -import org.hibernate.ScrollableResults; -import org.hibernate.Transaction; -import org.hibernate.classic.Session; -import org.hibernate.dialect.Cache71Dialect; -import org.hibernate.dialect.function.SQLFunction; -import org.hibernate.jdbc.Work; - -import org.junit.Test; - -import org.hibernate.testing.RequiresDialect; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.test.legacy.Blobber; -import org.hibernate.test.legacy.Broken; -import org.hibernate.test.legacy.Fixed; -import org.hibernate.test.legacy.Simple; -import org.hibernate.test.legacy.Single; - -import static org.hibernate.TestLogger.LOG; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * Tests for function support on CacheSQL... - * - * @author Jonathan Levinson - */ -@RequiresDialect( value = Cache71Dialect.class ) -public class SQLFunctionsInterSystemsTest extends BaseCoreFunctionalTestCase { - public String[] getMappings() { - return new String[] { - "legacy/AltSimple.hbm.xml", - "legacy/Broken.hbm.xml", - "legacy/Blobber.hbm.xml", - "dialect/cache/TestInterSystemsFunctionsClass.hbm.xml" - }; - } - - @Test - @SuppressWarnings( {"UnnecessaryBoxing"}) - public void testDialectSQLFunctions() throws Exception { - Session s = openSession(); - Transaction t = s.beginTransaction(); - - Simple simple = new Simple(); - simple.setName("Simple Dialect Function Test"); - simple.setAddress("Simple Address"); - simple.setPay(new Float(45.8)); - simple.setCount(2); - s.save(simple, Long.valueOf( 10 ) ); - - // Test to make sure allocating an specified object operates correctly. - assertTrue( - s.createQuery( "select new org.hibernate.test.legacy.S(s.count, s.address) from Simple s" ).list().size() == 1 - ); - - // Quick check the base dialect functions operate correctly - assertTrue( - s.createQuery( "select max(s.count) from Simple s" ).list().size() == 1 - ); - assertTrue( - s.createQuery( "select count(*) from Simple s" ).list().size() == 1 - ); - - List rset = s.createQuery( "select s.name, sysdate, floor(s.pay), round(s.pay,0) from Simple s" ).list(); - assertNotNull("Name string should have been returned",(((Object[])rset.get(0))[0])); - assertNotNull("Todays Date should have been returned",(((Object[])rset.get(0))[1])); - assertEquals("floor(45.8) result was incorrect ", new Integer(45), ( (Object[]) rset.get(0) )[2] ); - assertEquals("round(45.8) result was incorrect ", new Float(46), ( (Object[]) rset.get(0) )[3] ); - - simple.setPay(new Float(-45.8)); - s.update(simple); - - // Test type conversions while using nested functions (Float to Int). - rset = s.createQuery( "select abs(round(s.pay,0)) from Simple s" ).list(); - assertEquals("abs(round(-45.8)) result was incorrect ", new Float(46), rset.get(0)); - - // Test a larger depth 3 function example - Not a useful combo other than for testing - assertTrue( - s.createQuery( "select floor(round(sysdate,1)) from Simple s" ).list().size() == 1 - ); - - // Test the oracle standard NVL funtion as a test of multi-param functions... - simple.setPay(null); - s.update(simple); - Double value = (Double) s.createQuery("select mod( nvl(s.pay, 5000), 2 ) from Simple as s where s.id = 10").list().get(0); - assertTrue( 0 == value.intValue() ); - - // Test the hsql standard MOD funtion as a test of multi-param functions... - value = (Double) s.createQuery( "select MOD(s.count, 2) from Simple as s where s.id = 10" ) - .list() - .get(0); - assertTrue( 0 == value.intValue() ); - - s.delete(simple); - t.commit(); - s.close(); - } - - @SuppressWarnings( {"UnnecessaryBoxing", "unchecked"}) - public void testSetProperties() throws Exception { - Session s = openSession(); - Transaction t = s.beginTransaction(); - Simple simple = new Simple(); - simple.setName("Simple 1"); - s.save(simple, Long.valueOf( 10 ) ); - Query q = s.createQuery("from Simple s where s.name=:name and s.count=:count"); - q.setProperties(simple); - assertTrue( q.list().get(0)==simple ); - //misuse of "Single" as a propertyobject, but it was the first testclass i found with a collection ;) - Single single = new Single() { // trivial hack to test properties with arrays. - @SuppressWarnings( {"unchecked"}) - String[] getStuff() { - return (String[]) getSeveral().toArray(new String[getSeveral().size()]); - } - }; - - List l = new ArrayList(); - l.add("Simple 1"); - l.add("Slimeball"); - single.setSeveral(l); - q = s.createQuery("from Simple s where s.name in (:several)"); - q.setProperties(single); - assertTrue( q.list().get(0)==simple ); - - - q = s.createQuery("from Simple s where s.name in (:stuff)"); - q.setProperties(single); - assertTrue( q.list().get(0)==simple ); - s.delete(simple); - t.commit(); - s.close(); - } - - @SuppressWarnings( {"UnnecessaryBoxing"}) - public void testBroken() throws Exception { - Session s = openSession(); - Transaction t = s.beginTransaction(); - Broken b = new Fixed(); - b.setId( Long.valueOf( 123 )); - b.setOtherId("foobar"); - s.save(b); - s.flush(); - b.setTimestamp( new Date() ); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - s.update(b); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - b = (Broken) s.load( Broken.class, b ); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - s.delete(b); - t.commit(); - s.close(); - } - - @SuppressWarnings( {"UnnecessaryBoxing"}) - public void testNothinToUpdate() throws Exception { - Session s = openSession(); - Transaction t = s.beginTransaction(); - Simple simple = new Simple(); - simple.setName("Simple 1"); - s.save( simple, Long.valueOf(10) ); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - s.update( simple, Long.valueOf(10) ); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - s.update( simple, Long.valueOf(10) ); - s.delete(simple); - t.commit(); - s.close(); - } - - @SuppressWarnings( {"UnnecessaryBoxing"}) - public void testCachedQuery() throws Exception { - Session s = openSession(); - Transaction t = s.beginTransaction(); - Simple simple = new Simple(); - simple.setName("Simple 1"); - s.save( simple, Long.valueOf(10) ); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - Query q = s.createQuery("from Simple s where s.name=?"); - q.setCacheable(true); - q.setString(0, "Simple 1"); - assertTrue( q.list().size()==1 ); - assertTrue( q.list().size()==1 ); - assertTrue( q.list().size()==1 ); - q = s.createQuery("from Simple s where s.name=:name"); - q.setCacheable(true); - q.setString("name", "Simple 1"); - assertTrue( q.list().size()==1 ); - simple = (Simple) q.list().get(0); - - q.setString("name", "Simple 2"); - assertTrue( q.list().size()==0 ); - assertTrue( q.list().size()==0 ); - simple.setName("Simple 2"); - assertTrue( q.list().size()==1 ); - assertTrue( q.list().size()==1 ); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - q = s.createQuery("from Simple s where s.name=:name"); - q.setString("name", "Simple 2"); - q.setCacheable(true); - assertTrue( q.list().size()==1 ); - assertTrue( q.list().size()==1 ); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - s.update( simple, Long.valueOf(10) ); - s.delete(simple); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - q = s.createQuery("from Simple s where s.name=?"); - q.setCacheable(true); - q.setString(0, "Simple 1"); - assertTrue( q.list().size()==0 ); - assertTrue( q.list().size()==0 ); - t.commit(); - s.close(); - } - - @SuppressWarnings( {"UnnecessaryBoxing"}) - public void testCachedQueryRegion() throws Exception { - Session s = openSession(); - Transaction t = s.beginTransaction(); - Simple simple = new Simple(); - simple.setName("Simple 1"); - s.save( simple, Long.valueOf(10) ); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - Query q = s.createQuery("from Simple s where s.name=?"); - q.setCacheRegion("foo"); - q.setCacheable(true); - q.setString(0, "Simple 1"); - assertTrue( q.list().size()==1 ); - assertTrue( q.list().size()==1 ); - assertTrue( q.list().size()==1 ); - q = s.createQuery("from Simple s where s.name=:name"); - q.setCacheRegion("foo"); - q.setCacheable(true); - q.setString("name", "Simple 1"); - assertTrue( q.list().size()==1 ); - simple = (Simple) q.list().get(0); - - q.setString("name", "Simple 2"); - assertTrue( q.list().size()==0 ); - assertTrue( q.list().size()==0 ); - simple.setName("Simple 2"); - assertTrue( q.list().size()==1 ); - assertTrue( q.list().size()==1 ); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - s.update( simple, Long.valueOf(10) ); - s.delete(simple); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - q = s.createQuery("from Simple s where s.name=?"); - q.setCacheRegion("foo"); - q.setCacheable(true); - q.setString(0, "Simple 1"); - assertTrue( q.list().size()==0 ); - assertTrue( q.list().size()==0 ); - t.commit(); - s.close(); - } - - @SuppressWarnings( {"UnnecessaryBoxing", "unchecked"}) - public void testSQLFunctions() throws Exception { - Session s = openSession(); - Transaction t = s.beginTransaction(); - Simple simple = new Simple(); - simple.setName("Simple 1"); - s.save(simple, Long.valueOf(10) ); - - s.createQuery( "from Simple s where repeat('foo', 3) = 'foofoofoo'" ).list(); - s.createQuery( "from Simple s where repeat(s.name, 3) = 'foofoofoo'" ).list(); - s.createQuery( "from Simple s where repeat( lower(s.name), (3 + (1-1)) / 2) = 'foofoofoo'" ).list(); - - assertTrue( - s.createQuery( "from Simple s where upper( s.name ) ='SIMPLE 1'" ).list().size()==1 - ); - assertTrue( - s.createQuery( - "from Simple s where not( upper( s.name ) ='yada' or 1=2 or 'foo'='bar' or not('foo'='foo') or 'foo' like 'bar' )" - ).list() - .size()==1 - ); - - assertTrue( - s.createQuery( "from Simple s where lower( s.name || ' foo' ) ='simple 1 foo'" ).list().size()==1 - ); - assertTrue( - s.createQuery( "from Simple s where lower( concat(s.name, ' foo') ) ='simple 1 foo'" ).list().size()==1 - ); - - Simple other = new Simple(); - other.setName( "Simple 2" ); - other.setCount( 12 ); - simple.setOther( other ); - s.save( other, Long.valueOf(20) ); - //s.find("from Simple s where s.name ## 'cat|rat|bag'"); - assertTrue( - s.createQuery( "from Simple s where upper( s.other.name ) ='SIMPLE 2'" ).list().size()==1 - ); - assertTrue( - s.createQuery( "from Simple s where not ( upper( s.other.name ) ='SIMPLE 2' )" ).list().size()==0 - ); - assertTrue( - s.createQuery( - "select distinct s from Simple s where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2" - ).list() - .size()==1 - ); - assertTrue( - s.createQuery( - "select s from Simple s where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2 order by s.other.count" - ).list() - .size()==1 - ); - Simple min = new Simple(); - min.setCount( -1 ); - s.save(min, Long.valueOf(30) ); - - assertTrue( - s.createQuery( "from Simple s where s.count > ( select min(sim.count) from Simple sim )" ) - .list() - .size()==2 - ); - t.commit(); - t = s.beginTransaction(); - assertTrue( - s.createQuery( - "from Simple s where s = some( select sim from Simple sim where sim.count>=0 ) and s.count >= 0" - ).list() - .size()==2 - ); - assertTrue( - s.createQuery( - "from Simple s where s = some( select sim from Simple sim where sim.other.count=s.other.count ) and s.other.count > 0" - ).list() - .size()==1 - ); - - Iterator iter = s.createQuery( "select sum(s.count) from Simple s group by s.count having sum(s.count) > 10" ) - .iterate(); - assertTrue( iter.hasNext() ); - assertEquals( Long.valueOf( 12 ), iter.next() ); - assertTrue( !iter.hasNext() ); - iter = s.createQuery( "select s.count from Simple s group by s.count having s.count = 12" ).iterate(); - assertTrue( iter.hasNext() ); - - s.createQuery( - "select s.id, s.count, count(t), max(t.date) from Simple s, Simple t where s.count = t.count group by s.id, s.count order by s.count" - ).iterate(); - - Query q = s.createQuery("from Simple s"); - q.setMaxResults( 10 ); - assertTrue( q.list().size()==3 ); - q = s.createQuery("from Simple s"); - q.setMaxResults( 1 ); - assertTrue( q.list().size()==1 ); - q = s.createQuery("from Simple s"); - assertTrue( q.list().size() == 3 ); - q = s.createQuery("from Simple s where s.name = ?"); - q.setString( 0, "Simple 1" ); - assertTrue( q.list().size()==1 ); - q = s.createQuery("from Simple s where s.name = ? and upper(s.name) = ?"); - q.setString(1, "SIMPLE 1"); - q.setString( 0, "Simple 1" ); - q.setFirstResult(0); - assertTrue( q.iterate().hasNext() ); - q = s.createQuery("from Simple s where s.name = :foo and upper(s.name) = :bar or s.count=:count or s.count=:count + 1"); - q.setParameter( "bar", "SIMPLE 1" ); - q.setString( "foo", "Simple 1" ); - q.setInteger("count", 69); - q.setFirstResult(0); - assertTrue( q.iterate().hasNext() ); - q = s.createQuery("select s.id from Simple s"); - q.setFirstResult(1); - q.setMaxResults( 2 ); - iter = q.iterate(); - int i=0; - while ( iter.hasNext() ) { - assertTrue( iter.next() instanceof Long ); - i++; - } - assertTrue( i == 2 ); - q = s.createQuery("select all s, s.other from Simple s where s = :s"); - q.setParameter("s", simple); - assertTrue( q.list().size()==1 ); - - - q = s.createQuery("from Simple s where s.name in (:name_list) and s.count > :count"); - HashSet set = new HashSet(); - set.add("Simple 1"); - set.add("foo"); - q.setParameterList( "name_list", set ); - q.setParameter("count", new Integer(-1) ); - assertTrue( q.list().size()==1 ); - - ScrollableResults sr = s.createQuery("from Simple s").scroll(); - sr.next(); - sr.get(0); - sr.close(); - - s.delete(other); - s.delete(simple); - s.delete(min); - t.commit(); - s.close(); - - } - - public void testBlobClob() throws Exception { - - Session s = openSession(); - s.beginTransaction(); - Blobber b = new Blobber(); - b.setBlob( s.getLobHelper().createBlob( "foo/bar/baz".getBytes() ) ); - b.setClob( s.getLobHelper().createClob("foo/bar/baz") ); - s.save(b); - //s.refresh(b); - //assertTrue( b.getClob() instanceof ClobImpl ); - s.flush(); - s.refresh(b); - //b.getBlob().setBytes( 2, "abc".getBytes() ); - LOG.debug("levinson: just bfore b.getClob()"); - b.getClob().getSubString(2, 3); - //b.getClob().setString(2, "abc"); - s.flush(); - s.getTransaction().commit(); - s.close(); - - s = openSession(); - s.beginTransaction(); - b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) ); - Blobber b2 = new Blobber(); - s.save(b2); - b2.setBlob( b.getBlob() ); - b.setBlob(null); - //assertTrue( b.getClob().getSubString(1, 3).equals("fab") ); - b.getClob().getSubString(1, 6); - //b.getClob().setString(1, "qwerty"); - s.flush(); - s.getTransaction().commit(); - s.close(); - - s = openSession(); - s.beginTransaction(); - b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) ); - b.setClob( s.getLobHelper().createClob("xcvfxvc xcvbx cvbx cvbx cvbxcvbxcvbxcvb") ); - s.flush(); - s.getTransaction().commit(); - s.close(); - - s = openSession(); - s.beginTransaction(); - b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) ); - assertTrue( b.getClob().getSubString(1, 7).equals("xcvfxvc") ); - //b.getClob().setString(5, "1234567890"); - s.flush(); - s.getTransaction().commit(); - s.close(); - } - - @SuppressWarnings( {"UnnecessaryBoxing"}) - public void testSqlFunctionAsAlias() throws Exception { - String functionName = locateAppropriateDialectFunctionNameForAliasTest(); - if (functionName == null) { - LOG.info("Dialect does not list any no-arg functions"); - return; - } - - LOG.info("Using function named [" + functionName + "] for 'function as alias' test"); - String query = "select " + functionName + " from Simple as " + functionName + " where " + functionName + ".id = 10"; - - Session s = openSession(); - Transaction t = s.beginTransaction(); - Simple simple = new Simple(); - simple.setName("Simple 1"); - s.save( simple, Long.valueOf(10) ); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - List result = s.createQuery( query ).list(); - assertTrue( result.size() == 1 ); - assertTrue(result.get(0) instanceof Simple); - s.delete( result.get(0) ); - t.commit(); - s.close(); - } - - @SuppressWarnings( {"ForLoopReplaceableByForEach"}) - private String locateAppropriateDialectFunctionNameForAliasTest() { - for (Iterator itr = getDialect().getFunctions().entrySet().iterator(); itr.hasNext(); ) { - final Map.Entry entry = (Map.Entry) itr.next(); - final SQLFunction function = (SQLFunction) entry.getValue(); - if ( !function.hasArguments() && !function.hasParenthesesIfNoArguments() ) { - return (String) entry.getKey(); - } - } - return null; - } - - @SuppressWarnings( {"UnnecessaryBoxing"}) - public void testCachedQueryOnInsert() throws Exception { - Session s = openSession(); - Transaction t = s.beginTransaction(); - Simple simple = new Simple(); - simple.setName("Simple 1"); - s.save( simple, Long.valueOf(10) ); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - Query q = s.createQuery("from Simple s"); - List list = q.setCacheable(true).list(); - assertTrue( list.size()==1 ); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - q = s.createQuery("from Simple s"); - list = q.setCacheable(true).list(); - assertTrue( list.size()==1 ); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - Simple simple2 = new Simple(); - simple2.setCount(133); - s.save( simple2, Long.valueOf(12) ); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - q = s.createQuery("from Simple s"); - list = q.setCacheable(true).list(); - assertTrue( list.size()==2 ); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - q = s.createQuery("from Simple s"); - list = q.setCacheable(true).list(); - assertTrue( list.size()==2 ); - for ( Object o : list ) { - s.delete( o ); - } - t.commit(); - s.close(); - - } - - @SuppressWarnings( {"UnnecessaryBoxing", "UnnecessaryUnboxing"}) - public void testInterSystemsFunctions() throws Exception { - Calendar cal = new GregorianCalendar(); - cal.set(1977,6,3,0,0,0); - java.sql.Timestamp testvalue = new java.sql.Timestamp(cal.getTimeInMillis()); - testvalue.setNanos(0); - Calendar cal3 = new GregorianCalendar(); - cal3.set(1976,2,3,0,0,0); - java.sql.Timestamp testvalue3 = new java.sql.Timestamp(cal3.getTimeInMillis()); - testvalue3.setNanos(0); - - Session s = openSession(); - s.beginTransaction(); - try { - s.doWork( - new Work() { - @Override - public void execute(Connection connection) throws SQLException { - Statement stmt = connection.createStatement(); - stmt.executeUpdate( "DROP FUNCTION spLock FROM TestInterSystemsFunctionsClass" ); - } - } - ); - } - catch (Exception ex) { - System.out.println("as we expected stored procedure sp does not exist when we drop it"); - - } - s.getTransaction().commit(); - - s.beginTransaction(); - s.doWork( - new Work() { - @Override - public void execute(Connection connection) throws SQLException { - Statement stmt = connection.createStatement(); - String create_function = "CREATE FUNCTION SQLUser.TestInterSystemsFunctionsClass_spLock\n" + - " ( INOUT pHandle %SQLProcContext, \n" + - " ROWID INTEGER \n" + - " )\n" + - " FOR User.TestInterSystemsFunctionsClass " + - " PROCEDURE\n" + - " RETURNS INTEGER\n" + - " LANGUAGE OBJECTSCRIPT\n" + - " {\n" + - " q 0\n" + - " }"; - stmt.executeUpdate(create_function); - } - } - ); - s.getTransaction().commit(); - - s.beginTransaction(); - - TestInterSystemsFunctionsClass object = new TestInterSystemsFunctionsClass(); - object.setDateText("1977-07-03"); - object.setDate1( testvalue ); - object.setDate3( testvalue3 ); - s.save( object, Long.valueOf( 10 ) ); - s.getTransaction().commit(); - s.close(); - - s = openSession(); - s.beginTransaction(); - TestInterSystemsFunctionsClass test = (TestInterSystemsFunctionsClass) s.get(TestInterSystemsFunctionsClass.class, Long.valueOf(10)); - assertTrue( test.getDate1().equals(testvalue)); - test = (TestInterSystemsFunctionsClass) s.get(TestInterSystemsFunctionsClass.class, Long.valueOf(10), LockMode.UPGRADE); - assertTrue( test.getDate1().equals(testvalue)); - Date value = (Date) s.createQuery( "select nvl(o.date,o.dateText) from TestInterSystemsFunctionsClass as o" ) - .list() - .get(0); - assertTrue( value.equals(testvalue)); - Object nv = s.createQuery( "select nullif(o.dateText,o.dateText) from TestInterSystemsFunctionsClass as o" ) - .list() - .get(0); - assertTrue( nv == null); - String dateText = (String) s.createQuery( - "select nvl(o.dateText,o.date) from TestInterSystemsFunctionsClass as o" - ).list() - .get(0); - assertTrue( dateText.equals("1977-07-03")); - value = (Date) s.createQuery( "select ifnull(o.date,o.date1) from TestInterSystemsFunctionsClass as o" ) - .list() - .get(0); - assertTrue( value.equals(testvalue)); - value = (Date) s.createQuery( "select ifnull(o.date3,o.date,o.date1) from TestInterSystemsFunctionsClass as o" ) - .list() - .get(0); - assertTrue( value.equals(testvalue)); - Integer pos = (Integer) s.createQuery( - "select position('07', o.dateText) from TestInterSystemsFunctionsClass as o" - ).list() - .get(0); - assertTrue(pos.intValue() == 6); - String st = (String) s.createQuery( "select convert(o.date1, SQL_TIME) from TestInterSystemsFunctionsClass as o" ) - .list() - .get(0); - assertTrue( st.equals("00:00:00")); - java.sql.Time tm = (java.sql.Time) s.createQuery( - "select cast(o.date1, time) from TestInterSystemsFunctionsClass as o" - ).list() - .get(0); - assertTrue( tm.toString().equals("00:00:00")); - Double diff = (Double) s.createQuery( - "select timestampdiff(SQL_TSI_FRAC_SECOND, o.date3, o.date1) from TestInterSystemsFunctionsClass as o" - ).list() - .get(0); - assertTrue(diff.doubleValue() != 0.0); - diff = (Double) s.createQuery( - "select timestampdiff(SQL_TSI_MONTH, o.date3, o.date1) from TestInterSystemsFunctionsClass as o" - ).list() - .get(0); - assertTrue(diff.doubleValue() == 16.0); - diff = (Double) s.createQuery( - "select timestampdiff(SQL_TSI_WEEK, o.date3, o.date1) from TestInterSystemsFunctionsClass as o" - ).list() - .get(0); - assertTrue(diff.doubleValue() >= 16*4); - diff = (Double) s.createQuery( - "select timestampdiff(SQL_TSI_YEAR, o.date3, o.date1) from TestInterSystemsFunctionsClass as o" - ).list() - .get(0); - assertTrue(diff.doubleValue() == 1.0); - - s.getTransaction().commit(); - s.close(); - - - } - -} +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.dialect.functional.cache; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.hibernate.LockMode; +import org.hibernate.Query; +import org.hibernate.ScrollableResults; +import org.hibernate.Transaction; +import org.hibernate.classic.Session; +import org.hibernate.dialect.Cache71Dialect; +import org.hibernate.dialect.function.SQLFunction; +import org.hibernate.jdbc.Work; + +import org.junit.Test; + +import org.hibernate.testing.RequiresDialect; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.hibernate.test.legacy.Blobber; +import org.hibernate.test.legacy.Broken; +import org.hibernate.test.legacy.Fixed; +import org.hibernate.test.legacy.Simple; +import org.hibernate.test.legacy.Single; + +import static org.hibernate.testing.TestLogger.LOG; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** + * Tests for function support on CacheSQL... + * + * @author Jonathan Levinson + */ +@RequiresDialect( value = Cache71Dialect.class ) +public class SQLFunctionsInterSystemsTest extends BaseCoreFunctionalTestCase { + public String[] getMappings() { + return new String[] { + "legacy/AltSimple.hbm.xml", + "legacy/Broken.hbm.xml", + "legacy/Blobber.hbm.xml", + "dialect/cache/TestInterSystemsFunctionsClass.hbm.xml" + }; + } + + @Test + @SuppressWarnings( {"UnnecessaryBoxing"}) + public void testDialectSQLFunctions() throws Exception { + Session s = openSession(); + Transaction t = s.beginTransaction(); + + Simple simple = new Simple(); + simple.setName("Simple Dialect Function Test"); + simple.setAddress("Simple Address"); + simple.setPay(new Float(45.8)); + simple.setCount(2); + s.save(simple, Long.valueOf( 10 ) ); + + // Test to make sure allocating an specified object operates correctly. + assertTrue( + s.createQuery( "select new org.hibernate.test.legacy.S(s.count, s.address) from Simple s" ).list().size() == 1 + ); + + // Quick check the base dialect functions operate correctly + assertTrue( + s.createQuery( "select max(s.count) from Simple s" ).list().size() == 1 + ); + assertTrue( + s.createQuery( "select count(*) from Simple s" ).list().size() == 1 + ); + + List rset = s.createQuery( "select s.name, sysdate, floor(s.pay), round(s.pay,0) from Simple s" ).list(); + assertNotNull("Name string should have been returned",(((Object[])rset.get(0))[0])); + assertNotNull("Todays Date should have been returned",(((Object[])rset.get(0))[1])); + assertEquals("floor(45.8) result was incorrect ", new Integer(45), ( (Object[]) rset.get(0) )[2] ); + assertEquals("round(45.8) result was incorrect ", new Float(46), ( (Object[]) rset.get(0) )[3] ); + + simple.setPay(new Float(-45.8)); + s.update(simple); + + // Test type conversions while using nested functions (Float to Int). + rset = s.createQuery( "select abs(round(s.pay,0)) from Simple s" ).list(); + assertEquals("abs(round(-45.8)) result was incorrect ", new Float(46), rset.get(0)); + + // Test a larger depth 3 function example - Not a useful combo other than for testing + assertTrue( + s.createQuery( "select floor(round(sysdate,1)) from Simple s" ).list().size() == 1 + ); + + // Test the oracle standard NVL funtion as a test of multi-param functions... + simple.setPay(null); + s.update(simple); + Double value = (Double) s.createQuery("select mod( nvl(s.pay, 5000), 2 ) from Simple as s where s.id = 10").list().get(0); + assertTrue( 0 == value.intValue() ); + + // Test the hsql standard MOD funtion as a test of multi-param functions... + value = (Double) s.createQuery( "select MOD(s.count, 2) from Simple as s where s.id = 10" ) + .list() + .get(0); + assertTrue( 0 == value.intValue() ); + + s.delete(simple); + t.commit(); + s.close(); + } + + @SuppressWarnings( {"UnnecessaryBoxing", "unchecked"}) + public void testSetProperties() throws Exception { + Session s = openSession(); + Transaction t = s.beginTransaction(); + Simple simple = new Simple(); + simple.setName("Simple 1"); + s.save(simple, Long.valueOf( 10 ) ); + Query q = s.createQuery("from Simple s where s.name=:name and s.count=:count"); + q.setProperties(simple); + assertTrue( q.list().get(0)==simple ); + //misuse of "Single" as a propertyobject, but it was the first testclass i found with a collection ;) + Single single = new Single() { // trivial hack to test properties with arrays. + @SuppressWarnings( {"unchecked"}) + String[] getStuff() { + return (String[]) getSeveral().toArray(new String[getSeveral().size()]); + } + }; + + List l = new ArrayList(); + l.add("Simple 1"); + l.add("Slimeball"); + single.setSeveral(l); + q = s.createQuery("from Simple s where s.name in (:several)"); + q.setProperties(single); + assertTrue( q.list().get(0)==simple ); + + + q = s.createQuery("from Simple s where s.name in (:stuff)"); + q.setProperties(single); + assertTrue( q.list().get(0)==simple ); + s.delete(simple); + t.commit(); + s.close(); + } + + @SuppressWarnings( {"UnnecessaryBoxing"}) + public void testBroken() throws Exception { + Session s = openSession(); + Transaction t = s.beginTransaction(); + Broken b = new Fixed(); + b.setId( Long.valueOf( 123 )); + b.setOtherId("foobar"); + s.save(b); + s.flush(); + b.setTimestamp( new Date() ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + s.update(b); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + b = (Broken) s.load( Broken.class, b ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + s.delete(b); + t.commit(); + s.close(); + } + + @SuppressWarnings( {"UnnecessaryBoxing"}) + public void testNothinToUpdate() throws Exception { + Session s = openSession(); + Transaction t = s.beginTransaction(); + Simple simple = new Simple(); + simple.setName("Simple 1"); + s.save( simple, Long.valueOf(10) ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + s.update( simple, Long.valueOf(10) ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + s.update( simple, Long.valueOf(10) ); + s.delete(simple); + t.commit(); + s.close(); + } + + @SuppressWarnings( {"UnnecessaryBoxing"}) + public void testCachedQuery() throws Exception { + Session s = openSession(); + Transaction t = s.beginTransaction(); + Simple simple = new Simple(); + simple.setName("Simple 1"); + s.save( simple, Long.valueOf(10) ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + Query q = s.createQuery("from Simple s where s.name=?"); + q.setCacheable(true); + q.setString(0, "Simple 1"); + assertTrue( q.list().size()==1 ); + assertTrue( q.list().size()==1 ); + assertTrue( q.list().size()==1 ); + q = s.createQuery("from Simple s where s.name=:name"); + q.setCacheable(true); + q.setString("name", "Simple 1"); + assertTrue( q.list().size()==1 ); + simple = (Simple) q.list().get(0); + + q.setString("name", "Simple 2"); + assertTrue( q.list().size()==0 ); + assertTrue( q.list().size()==0 ); + simple.setName("Simple 2"); + assertTrue( q.list().size()==1 ); + assertTrue( q.list().size()==1 ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + q = s.createQuery("from Simple s where s.name=:name"); + q.setString("name", "Simple 2"); + q.setCacheable(true); + assertTrue( q.list().size()==1 ); + assertTrue( q.list().size()==1 ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + s.update( simple, Long.valueOf(10) ); + s.delete(simple); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + q = s.createQuery("from Simple s where s.name=?"); + q.setCacheable(true); + q.setString(0, "Simple 1"); + assertTrue( q.list().size()==0 ); + assertTrue( q.list().size()==0 ); + t.commit(); + s.close(); + } + + @SuppressWarnings( {"UnnecessaryBoxing"}) + public void testCachedQueryRegion() throws Exception { + Session s = openSession(); + Transaction t = s.beginTransaction(); + Simple simple = new Simple(); + simple.setName("Simple 1"); + s.save( simple, Long.valueOf(10) ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + Query q = s.createQuery("from Simple s where s.name=?"); + q.setCacheRegion("foo"); + q.setCacheable(true); + q.setString(0, "Simple 1"); + assertTrue( q.list().size()==1 ); + assertTrue( q.list().size()==1 ); + assertTrue( q.list().size()==1 ); + q = s.createQuery("from Simple s where s.name=:name"); + q.setCacheRegion("foo"); + q.setCacheable(true); + q.setString("name", "Simple 1"); + assertTrue( q.list().size()==1 ); + simple = (Simple) q.list().get(0); + + q.setString("name", "Simple 2"); + assertTrue( q.list().size()==0 ); + assertTrue( q.list().size()==0 ); + simple.setName("Simple 2"); + assertTrue( q.list().size()==1 ); + assertTrue( q.list().size()==1 ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + s.update( simple, Long.valueOf(10) ); + s.delete(simple); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + q = s.createQuery("from Simple s where s.name=?"); + q.setCacheRegion("foo"); + q.setCacheable(true); + q.setString(0, "Simple 1"); + assertTrue( q.list().size()==0 ); + assertTrue( q.list().size()==0 ); + t.commit(); + s.close(); + } + + @SuppressWarnings( {"UnnecessaryBoxing", "unchecked"}) + public void testSQLFunctions() throws Exception { + Session s = openSession(); + Transaction t = s.beginTransaction(); + Simple simple = new Simple(); + simple.setName("Simple 1"); + s.save(simple, Long.valueOf(10) ); + + s.createQuery( "from Simple s where repeat('foo', 3) = 'foofoofoo'" ).list(); + s.createQuery( "from Simple s where repeat(s.name, 3) = 'foofoofoo'" ).list(); + s.createQuery( "from Simple s where repeat( lower(s.name), (3 + (1-1)) / 2) = 'foofoofoo'" ).list(); + + assertTrue( + s.createQuery( "from Simple s where upper( s.name ) ='SIMPLE 1'" ).list().size()==1 + ); + assertTrue( + s.createQuery( + "from Simple s where not( upper( s.name ) ='yada' or 1=2 or 'foo'='bar' or not('foo'='foo') or 'foo' like 'bar' )" + ).list() + .size()==1 + ); + + assertTrue( + s.createQuery( "from Simple s where lower( s.name || ' foo' ) ='simple 1 foo'" ).list().size()==1 + ); + assertTrue( + s.createQuery( "from Simple s where lower( concat(s.name, ' foo') ) ='simple 1 foo'" ).list().size()==1 + ); + + Simple other = new Simple(); + other.setName( "Simple 2" ); + other.setCount( 12 ); + simple.setOther( other ); + s.save( other, Long.valueOf(20) ); + //s.find("from Simple s where s.name ## 'cat|rat|bag'"); + assertTrue( + s.createQuery( "from Simple s where upper( s.other.name ) ='SIMPLE 2'" ).list().size()==1 + ); + assertTrue( + s.createQuery( "from Simple s where not ( upper( s.other.name ) ='SIMPLE 2' )" ).list().size()==0 + ); + assertTrue( + s.createQuery( + "select distinct s from Simple s where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2" + ).list() + .size()==1 + ); + assertTrue( + s.createQuery( + "select s from Simple s where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2 order by s.other.count" + ).list() + .size()==1 + ); + Simple min = new Simple(); + min.setCount( -1 ); + s.save(min, Long.valueOf(30) ); + + assertTrue( + s.createQuery( "from Simple s where s.count > ( select min(sim.count) from Simple sim )" ) + .list() + .size()==2 + ); + t.commit(); + t = s.beginTransaction(); + assertTrue( + s.createQuery( + "from Simple s where s = some( select sim from Simple sim where sim.count>=0 ) and s.count >= 0" + ).list() + .size()==2 + ); + assertTrue( + s.createQuery( + "from Simple s where s = some( select sim from Simple sim where sim.other.count=s.other.count ) and s.other.count > 0" + ).list() + .size()==1 + ); + + Iterator iter = s.createQuery( "select sum(s.count) from Simple s group by s.count having sum(s.count) > 10" ) + .iterate(); + assertTrue( iter.hasNext() ); + assertEquals( Long.valueOf( 12 ), iter.next() ); + assertTrue( !iter.hasNext() ); + iter = s.createQuery( "select s.count from Simple s group by s.count having s.count = 12" ).iterate(); + assertTrue( iter.hasNext() ); + + s.createQuery( + "select s.id, s.count, count(t), max(t.date) from Simple s, Simple t where s.count = t.count group by s.id, s.count order by s.count" + ).iterate(); + + Query q = s.createQuery("from Simple s"); + q.setMaxResults( 10 ); + assertTrue( q.list().size()==3 ); + q = s.createQuery("from Simple s"); + q.setMaxResults( 1 ); + assertTrue( q.list().size()==1 ); + q = s.createQuery("from Simple s"); + assertTrue( q.list().size() == 3 ); + q = s.createQuery("from Simple s where s.name = ?"); + q.setString( 0, "Simple 1" ); + assertTrue( q.list().size()==1 ); + q = s.createQuery("from Simple s where s.name = ? and upper(s.name) = ?"); + q.setString(1, "SIMPLE 1"); + q.setString( 0, "Simple 1" ); + q.setFirstResult(0); + assertTrue( q.iterate().hasNext() ); + q = s.createQuery("from Simple s where s.name = :foo and upper(s.name) = :bar or s.count=:count or s.count=:count + 1"); + q.setParameter( "bar", "SIMPLE 1" ); + q.setString( "foo", "Simple 1" ); + q.setInteger("count", 69); + q.setFirstResult(0); + assertTrue( q.iterate().hasNext() ); + q = s.createQuery("select s.id from Simple s"); + q.setFirstResult(1); + q.setMaxResults( 2 ); + iter = q.iterate(); + int i=0; + while ( iter.hasNext() ) { + assertTrue( iter.next() instanceof Long ); + i++; + } + assertTrue( i == 2 ); + q = s.createQuery("select all s, s.other from Simple s where s = :s"); + q.setParameter("s", simple); + assertTrue( q.list().size()==1 ); + + + q = s.createQuery("from Simple s where s.name in (:name_list) and s.count > :count"); + HashSet set = new HashSet(); + set.add("Simple 1"); + set.add("foo"); + q.setParameterList( "name_list", set ); + q.setParameter("count", new Integer(-1) ); + assertTrue( q.list().size()==1 ); + + ScrollableResults sr = s.createQuery("from Simple s").scroll(); + sr.next(); + sr.get(0); + sr.close(); + + s.delete(other); + s.delete(simple); + s.delete(min); + t.commit(); + s.close(); + + } + + public void testBlobClob() throws Exception { + + Session s = openSession(); + s.beginTransaction(); + Blobber b = new Blobber(); + b.setBlob( s.getLobHelper().createBlob( "foo/bar/baz".getBytes() ) ); + b.setClob( s.getLobHelper().createClob("foo/bar/baz") ); + s.save(b); + //s.refresh(b); + //assertTrue( b.getClob() instanceof ClobImpl ); + s.flush(); + s.refresh(b); + //b.getBlob().setBytes( 2, "abc".getBytes() ); + LOG.debug("levinson: just bfore b.getClob()"); + b.getClob().getSubString(2, 3); + //b.getClob().setString(2, "abc"); + s.flush(); + s.getTransaction().commit(); + s.close(); + + s = openSession(); + s.beginTransaction(); + b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) ); + Blobber b2 = new Blobber(); + s.save(b2); + b2.setBlob( b.getBlob() ); + b.setBlob(null); + //assertTrue( b.getClob().getSubString(1, 3).equals("fab") ); + b.getClob().getSubString(1, 6); + //b.getClob().setString(1, "qwerty"); + s.flush(); + s.getTransaction().commit(); + s.close(); + + s = openSession(); + s.beginTransaction(); + b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) ); + b.setClob( s.getLobHelper().createClob("xcvfxvc xcvbx cvbx cvbx cvbxcvbxcvbxcvb") ); + s.flush(); + s.getTransaction().commit(); + s.close(); + + s = openSession(); + s.beginTransaction(); + b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) ); + assertTrue( b.getClob().getSubString(1, 7).equals("xcvfxvc") ); + //b.getClob().setString(5, "1234567890"); + s.flush(); + s.getTransaction().commit(); + s.close(); + } + + @SuppressWarnings( {"UnnecessaryBoxing"}) + public void testSqlFunctionAsAlias() throws Exception { + String functionName = locateAppropriateDialectFunctionNameForAliasTest(); + if (functionName == null) { + LOG.info("Dialect does not list any no-arg functions"); + return; + } + + LOG.info("Using function named [" + functionName + "] for 'function as alias' test"); + String query = "select " + functionName + " from Simple as " + functionName + " where " + functionName + ".id = 10"; + + Session s = openSession(); + Transaction t = s.beginTransaction(); + Simple simple = new Simple(); + simple.setName("Simple 1"); + s.save( simple, Long.valueOf(10) ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + List result = s.createQuery( query ).list(); + assertTrue( result.size() == 1 ); + assertTrue(result.get(0) instanceof Simple); + s.delete( result.get(0) ); + t.commit(); + s.close(); + } + + @SuppressWarnings( {"ForLoopReplaceableByForEach"}) + private String locateAppropriateDialectFunctionNameForAliasTest() { + for (Iterator itr = getDialect().getFunctions().entrySet().iterator(); itr.hasNext(); ) { + final Map.Entry entry = (Map.Entry) itr.next(); + final SQLFunction function = (SQLFunction) entry.getValue(); + if ( !function.hasArguments() && !function.hasParenthesesIfNoArguments() ) { + return (String) entry.getKey(); + } + } + return null; + } + + @SuppressWarnings( {"UnnecessaryBoxing"}) + public void testCachedQueryOnInsert() throws Exception { + Session s = openSession(); + Transaction t = s.beginTransaction(); + Simple simple = new Simple(); + simple.setName("Simple 1"); + s.save( simple, Long.valueOf(10) ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + Query q = s.createQuery("from Simple s"); + List list = q.setCacheable(true).list(); + assertTrue( list.size()==1 ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + q = s.createQuery("from Simple s"); + list = q.setCacheable(true).list(); + assertTrue( list.size()==1 ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + Simple simple2 = new Simple(); + simple2.setCount(133); + s.save( simple2, Long.valueOf(12) ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + q = s.createQuery("from Simple s"); + list = q.setCacheable(true).list(); + assertTrue( list.size()==2 ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + q = s.createQuery("from Simple s"); + list = q.setCacheable(true).list(); + assertTrue( list.size()==2 ); + for ( Object o : list ) { + s.delete( o ); + } + t.commit(); + s.close(); + + } + + @SuppressWarnings( {"UnnecessaryBoxing", "UnnecessaryUnboxing"}) + public void testInterSystemsFunctions() throws Exception { + Calendar cal = new GregorianCalendar(); + cal.set(1977,6,3,0,0,0); + java.sql.Timestamp testvalue = new java.sql.Timestamp(cal.getTimeInMillis()); + testvalue.setNanos(0); + Calendar cal3 = new GregorianCalendar(); + cal3.set(1976,2,3,0,0,0); + java.sql.Timestamp testvalue3 = new java.sql.Timestamp(cal3.getTimeInMillis()); + testvalue3.setNanos(0); + + Session s = openSession(); + s.beginTransaction(); + try { + s.doWork( + new Work() { + @Override + public void execute(Connection connection) throws SQLException { + Statement stmt = connection.createStatement(); + stmt.executeUpdate( "DROP FUNCTION spLock FROM TestInterSystemsFunctionsClass" ); + } + } + ); + } + catch (Exception ex) { + System.out.println("as we expected stored procedure sp does not exist when we drop it"); + + } + s.getTransaction().commit(); + + s.beginTransaction(); + s.doWork( + new Work() { + @Override + public void execute(Connection connection) throws SQLException { + Statement stmt = connection.createStatement(); + String create_function = "CREATE FUNCTION SQLUser.TestInterSystemsFunctionsClass_spLock\n" + + " ( INOUT pHandle %SQLProcContext, \n" + + " ROWID INTEGER \n" + + " )\n" + + " FOR User.TestInterSystemsFunctionsClass " + + " PROCEDURE\n" + + " RETURNS INTEGER\n" + + " LANGUAGE OBJECTSCRIPT\n" + + " {\n" + + " q 0\n" + + " }"; + stmt.executeUpdate(create_function); + } + } + ); + s.getTransaction().commit(); + + s.beginTransaction(); + + TestInterSystemsFunctionsClass object = new TestInterSystemsFunctionsClass(); + object.setDateText("1977-07-03"); + object.setDate1( testvalue ); + object.setDate3( testvalue3 ); + s.save( object, Long.valueOf( 10 ) ); + s.getTransaction().commit(); + s.close(); + + s = openSession(); + s.beginTransaction(); + TestInterSystemsFunctionsClass test = (TestInterSystemsFunctionsClass) s.get(TestInterSystemsFunctionsClass.class, Long.valueOf(10)); + assertTrue( test.getDate1().equals(testvalue)); + test = (TestInterSystemsFunctionsClass) s.get(TestInterSystemsFunctionsClass.class, Long.valueOf(10), LockMode.UPGRADE); + assertTrue( test.getDate1().equals(testvalue)); + Date value = (Date) s.createQuery( "select nvl(o.date,o.dateText) from TestInterSystemsFunctionsClass as o" ) + .list() + .get(0); + assertTrue( value.equals(testvalue)); + Object nv = s.createQuery( "select nullif(o.dateText,o.dateText) from TestInterSystemsFunctionsClass as o" ) + .list() + .get(0); + assertTrue( nv == null); + String dateText = (String) s.createQuery( + "select nvl(o.dateText,o.date) from TestInterSystemsFunctionsClass as o" + ).list() + .get(0); + assertTrue( dateText.equals("1977-07-03")); + value = (Date) s.createQuery( "select ifnull(o.date,o.date1) from TestInterSystemsFunctionsClass as o" ) + .list() + .get(0); + assertTrue( value.equals(testvalue)); + value = (Date) s.createQuery( "select ifnull(o.date3,o.date,o.date1) from TestInterSystemsFunctionsClass as o" ) + .list() + .get(0); + assertTrue( value.equals(testvalue)); + Integer pos = (Integer) s.createQuery( + "select position('07', o.dateText) from TestInterSystemsFunctionsClass as o" + ).list() + .get(0); + assertTrue(pos.intValue() == 6); + String st = (String) s.createQuery( "select convert(o.date1, SQL_TIME) from TestInterSystemsFunctionsClass as o" ) + .list() + .get(0); + assertTrue( st.equals("00:00:00")); + java.sql.Time tm = (java.sql.Time) s.createQuery( + "select cast(o.date1, time) from TestInterSystemsFunctionsClass as o" + ).list() + .get(0); + assertTrue( tm.toString().equals("00:00:00")); + Double diff = (Double) s.createQuery( + "select timestampdiff(SQL_TSI_FRAC_SECOND, o.date3, o.date1) from TestInterSystemsFunctionsClass as o" + ).list() + .get(0); + assertTrue(diff.doubleValue() != 0.0); + diff = (Double) s.createQuery( + "select timestampdiff(SQL_TSI_MONTH, o.date3, o.date1) from TestInterSystemsFunctionsClass as o" + ).list() + .get(0); + assertTrue(diff.doubleValue() == 16.0); + diff = (Double) s.createQuery( + "select timestampdiff(SQL_TSI_WEEK, o.date3, o.date1) from TestInterSystemsFunctionsClass as o" + ).list() + .get(0); + assertTrue(diff.doubleValue() >= 16*4); + diff = (Double) s.createQuery( + "select timestampdiff(SQL_TSI_YEAR, o.date3, o.date1) from TestInterSystemsFunctionsClass as o" + ).list() + .get(0); + assertTrue(diff.doubleValue() == 1.0); + + s.getTransaction().commit(); + s.close(); + + + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java b/hibernate-core/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java index 9e7902e021..b482d5c2fd 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java @@ -22,7 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.test.filter; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -164,7 +164,7 @@ public class DynamicFilterTest extends BaseCoreFunctionalTestCase { session.clear(); - session.disableFilter("regionlist"); + session.disableFilter( "regionlist" ); session.enableFilter( "regionlist" ).setParameterList( "regions", new String[]{"LA", "APAC", "APAC"} ); // Second test retreival through hql with the collection as non-eager with different region list salespersons = session.createQuery( "select s from Salesperson as s" ).list(); @@ -190,7 +190,7 @@ public class DynamicFilterTest extends BaseCoreFunctionalTestCase { //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // HQL test //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - LOG.info("Starting HQL filter tests"); + LOG.info( "Starting HQL filter tests" ); TestData testData = new TestData(); testData.prepare(); @@ -200,13 +200,13 @@ public class DynamicFilterTest extends BaseCoreFunctionalTestCase { session.enableFilter( "effectiveDate" ) .setParameter( "asOfDate", testData.lastMonth.getTime() ); - LOG.info("HQL against Salesperson..."); + LOG.info( "HQL against Salesperson..." ); List results = session.createQuery( "select s from Salesperson as s left join fetch s.orders" ).list(); assertTrue( "Incorrect filtered HQL result count [" + results.size() + "]", results.size() == 1 ); Salesperson result = ( Salesperson ) results.get( 0 ); assertTrue( "Incorrect collectionfilter count", result.getOrders().size() == 1 ); - LOG.info("HQL against Product..."); + LOG.info( "HQL against Product..." ); results = session.createQuery( "from Product as p where p.stockNumber = ?" ).setInteger( 0, 124 ).list(); assertTrue( results.size() == 1 ); @@ -225,7 +225,7 @@ public class DynamicFilterTest extends BaseCoreFunctionalTestCase { Session session = openSession(); session.enableFilter( "heavyProducts" ).setParameter("weightKilograms", 4d); - LOG.info("HQL against Product..."); + LOG.info( "HQL against Product..." ); List results = session.createQuery( "from Product").list(); assertEquals( 1, results.size() ); @@ -280,7 +280,7 @@ public class DynamicFilterTest extends BaseCoreFunctionalTestCase { Session session = openSession(); session.beginTransaction(); session.enableFilter( "fulfilledOrders" ).setParameter( "asOfDate", testData.lastMonth.getTime() ); - session.enableFilter( "regionlist" ).setParameterList( "regions", new String[] { "APAC" } ); + session.enableFilter( "regionlist" ).setParameterList( "regions", new String[] {"APAC"} ); List result = session.createCriteria( Order.class ) .add( Subqueries.in( "steve", subquery ) ) @@ -389,43 +389,47 @@ public class DynamicFilterTest extends BaseCoreFunctionalTestCase { LOG.info("query against Department with a subquery on Salesperson in the APAC reqion..."); - List departments = session.createQuery("select d from Department as d where d.id in (select s.department from Salesperson s where s.name = ?)").setString(0, "steve").list(); + List departments = session.createQuery( + "select d from Department as d where d.id in (select s.department from Salesperson s where s.name = ?)" + ).setString( 0, "steve" ).list(); assertEquals("Incorrect department count", 1, departments.size()); LOG.info("query against Department with a subquery on Salesperson in the FooBar reqion..."); - session.enableFilter("region").setParameter("region", "Foobar"); + session.enableFilter("region").setParameter( "region", "Foobar" ); departments = session.createQuery("select d from Department as d where d.id in (select s.department from Salesperson s where s.name = ?)").setString(0, "steve").list(); - assertEquals("Incorrect department count", 0, departments.size()); + assertEquals( "Incorrect department count", 0, departments.size() ); LOG.info("query against Order with a subquery for line items with a subquery line items where the product name is Acme Hair Gel and the quantity is greater than 1 in a given region for a given buyer"); - session.enableFilter("region").setParameter("region", "APAC"); + session.enableFilter("region").setParameter( "region", "APAC" ); List orders = session.createQuery("select o from Order as o where exists (select li.id from LineItem li, Product as p where p.id = li.product and li.quantity >= ? and p.name = ?) and o.buyer = ?") .setLong(0, 1L).setString(1, "Acme Hair Gel").setString(2, "gavin").list(); - assertEquals("Incorrect orders count", 1, orders.size()); + assertEquals( "Incorrect orders count", 1, orders.size() ); LOG.info("query against Order with a subquery for line items with a subquery line items where the product name is Acme Hair Gel and the quantity is greater than 1 in a given region and the product is effective as of last month"); session.enableFilter("region").setParameter("region", "APAC"); - session.enableFilter("effectiveDate").setParameter("asOfDate", testData.lastMonth.getTime()); + session.enableFilter("effectiveDate").setParameter( "asOfDate", testData.lastMonth.getTime() ); orders = session.createQuery("select o from Order as o where exists (select li.id from LineItem li where li.quantity >= ? and li.product in (select p.id from Product p where p.name = ?)) and o.buyer = ?") .setLong(0, 1L).setString(1, "Acme Hair Gel").setString(2, "gavin").list(); - assertEquals("Incorrect orders count", 1, orders.size()); + assertEquals( "Incorrect orders count", 1, orders.size() ); - LOG.info("query against Order with a subquery for line items with a subquery line items where the product name is Acme Hair Gel and the quantity is greater than 1 in a given region and the product is effective as of 4 months ago"); + LOG.info( + "query against Order with a subquery for line items with a subquery line items where the product name is Acme Hair Gel and the quantity is greater than 1 in a given region and the product is effective as of 4 months ago" + ); session.enableFilter("region").setParameter("region", "APAC"); session.enableFilter("effectiveDate").setParameter("asOfDate", testData.fourMonthsAgo.getTime()); orders = session.createQuery("select o from Order as o where exists (select li.id from LineItem li where li.quantity >= ? and li.product in (select p.id from Product p where p.name = ?)) and o.buyer = ?") - .setLong(0, 1L).setString(1, "Acme Hair Gel").setString(2, "gavin").list(); + .setLong( 0, 1L ).setString( 1, "Acme Hair Gel" ).setString( 2, "gavin" ).list(); assertEquals("Incorrect orders count", 0, orders.size()); @@ -445,7 +449,7 @@ public class DynamicFilterTest extends BaseCoreFunctionalTestCase { session.enableFilter("effectiveDate").setParameter("asOfDate", testData.lastMonth.getTime()); orders = session.createQuery("select o from Order as o where exists (select li.id from LineItem li where li.quantity >= ? and li.product in (select p.id from Product p where p.name = ?)) and o.buyer = :buyer") - .setLong(0, 1L).setString(1, "Acme Hair Gel").setString("buyer", "gavin").list(); + .setLong( 0, 1L ).setString( 1, "Acme Hair Gel" ).setString( "buyer", "gavin" ).list(); assertEquals("Incorrect orders count", 1, orders.size()); diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java index 1e1b8dea0d..f77d35d56a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java @@ -66,7 +66,7 @@ import org.hibernate.type.ComponentType; import org.hibernate.type.ManyToOneType; import org.hibernate.type.Type; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java index 8c3bc0b703..975e7d1cbd 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java @@ -22,7 +22,6 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.test.hql; -import static org.hibernate.TestLogger.LOG; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -201,7 +200,7 @@ public class BulkManipulationTest extends BaseCoreFunctionalTestCase { s.createSQLQuery( "insert into Pickup (id, vin, owner) select id, vin, owner from Car" ).executeUpdate(); l = s.createQuery("from Vehicle").list(); - assertEquals(l.size(),5); + assertEquals( l.size(), 5 ); t.commit(); t = s.beginTransaction(); @@ -212,13 +211,21 @@ public class BulkManipulationTest extends BaseCoreFunctionalTestCase { assertEquals(l.size(),4); Car c = (Car) s.createQuery( "from Car where owner = 'Kirsten'" ).uniqueResult(); - c.setOwner("NotKirsten"); - assertEquals(0,s.getNamedQuery( "native-delete-car" ).setString( 0, "Kirsten" ).executeUpdate()); - assertEquals(1,s.getNamedQuery( "native-delete-car" ).setString( 0, "NotKirsten" ).executeUpdate()); + c.setOwner( "NotKirsten" ); + assertEquals( 0, s.getNamedQuery( "native-delete-car" ).setString( 0, "Kirsten" ).executeUpdate() ); + assertEquals( 1, s.getNamedQuery( "native-delete-car" ).setString( 0, "NotKirsten" ).executeUpdate() ); - assertEquals(0,s.createSQLQuery( "delete from SUV where owner = :owner" ).setString( "owner", "NotThere" ).executeUpdate()); - assertEquals(1,s.createSQLQuery( "delete from SUV where owner = :owner" ).setString( "owner", "Joe" ).executeUpdate()); + assertEquals( + 0, s.createSQLQuery( "delete from SUV where owner = :owner" ) + .setString( "owner", "NotThere" ) + .executeUpdate() + ); + assertEquals( + 1, s.createSQLQuery( "delete from SUV where owner = :owner" ) + .setString( "owner", "Joe" ) + .executeUpdate() + ); s.createSQLQuery( "delete from Pickup" ).executeUpdate(); l = s.createQuery("from Vehicle").list(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/jdbc/proxies/BatchingTest.java b/hibernate-core/src/test/java/org/hibernate/test/jdbc/proxies/BatchingTest.java index 54bbd710a4..44017628ae 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jdbc/proxies/BatchingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jdbc/proxies/BatchingTest.java @@ -48,8 +48,8 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.hibernate.testing.env.ConnectionProviderBuilder; import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.test.common.ConnectionProviderBuilder; import org.hibernate.test.common.JournalingBatchObserver; import org.hibernate.test.common.JournalingTransactionObserver; import org.hibernate.test.common.TransactionContextImpl; diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/cascade/CascadeTest.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/cascade/CascadeTest.java index 0f0f36311e..9f4986d588 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jpa/cascade/CascadeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/cascade/CascadeTest.java @@ -26,7 +26,7 @@ package org.hibernate.test.jpa.cascade; import org.hibernate.Session; import org.hibernate.TransientObjectException; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import static org.junit.Assert.fail; import org.junit.Test; diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java index e9f7c2de21..7d36c5d680 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java @@ -23,7 +23,7 @@ */ package org.hibernate.test.legacy; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.io.Serializable; import java.sql.Connection; import java.sql.Time; @@ -83,7 +83,7 @@ import org.junit.Test; import org.hibernate.testing.DialectChecks; import org.hibernate.testing.RequiresDialectFeature; -import org.hibernate.test.common.ConnectionProviderBuilder; +import org.hibernate.testing.env.ConnectionProviderBuilder; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -232,9 +232,9 @@ public class FooBarTest extends LegacyTestCase { Qux q2 = (Qux) s.load( Qux.class, q.getKey() ); assertTrue( "loaded same object", q==q2 ); assertTrue( "loaded same object", b==b2 ); - assertTrue( Math.round( b.getFormula() ) == b.getInt()/2 ); + assertTrue( Math.round( b.getFormula() ) == b.getInt() / 2 ); s.delete(q2); - s.delete(b2); + s.delete( b2 ); s.getTransaction().commit(); s.close(); } @@ -245,12 +245,12 @@ public class FooBarTest extends LegacyTestCase { s.beginTransaction(); Foo foo = new Foo(); foo.setJoinedProp("foo"); - s.save(foo); + s.save( foo ); s.flush(); foo.setJoinedProp("bar"); s.flush(); String fid = foo.getKey(); - s.delete(foo); + s.delete( foo ); s.getTransaction().commit(); s.close(); @@ -375,9 +375,9 @@ public class FooBarTest extends LegacyTestCase { Session s = openSession(); s.beginTransaction(); Baz bb = (Baz) s.createCriteria(Baz.class).uniqueResult(); - assertTrue(bb==null); + assertTrue( bb == null ); Baz baz = new Baz(); - s.save(baz); + s.save( baz ); s.getTransaction().commit(); s.close(); @@ -385,8 +385,8 @@ public class FooBarTest extends LegacyTestCase { s.beginTransaction(); Baz b = (Baz) s.createCriteria(Baz.class).uniqueResult(); assertTrue( Hibernate.isInitialized( b.getTopGlarchez() ) ); - assertTrue( b.getTopGlarchez().size()==0 ); - s.delete(b); + assertTrue( b.getTopGlarchez().size() == 0 ); + s.delete( b ); s.getTransaction().commit(); s.close(); } @@ -839,8 +839,8 @@ public class FooBarTest extends LegacyTestCase { Baz baz = new Baz(); List list = new ArrayList(); list.add( new Fee() ); - baz.setFees(list); - s.save(baz); + baz.setFees( list ); + s.save( baz ); s.getTransaction().commit(); s.close(); @@ -854,7 +854,7 @@ public class FooBarTest extends LegacyTestCase { s = openSession(); s.beginTransaction(); - s.delete(baz); + s.delete( baz ); s.flush(); assertFalse( s.createQuery( "from Fee" ).iterate().hasNext() ); s.getTransaction().commit(); @@ -867,7 +867,7 @@ public class FooBarTest extends LegacyTestCase { list.add( new Fee() ); list.add( new Fee() ); baz.setFees(list); - s.save(baz); + s.save( baz ); s.getTransaction().commit(); s.close(); @@ -878,7 +878,7 @@ public class FooBarTest extends LegacyTestCase { s.getTransaction().commit(); s.close(); - assertTrue( baz.getFees().size()==2 ); + assertTrue( baz.getFees().size() == 2 ); s = openSession(); s.beginTransaction(); @@ -917,7 +917,7 @@ public class FooBarTest extends LegacyTestCase { Session s = openSession(); s.beginTransaction(); Baz baz = new Baz(); - s.save(baz); + s.save( baz ); s.getTransaction().commit(); s.close(); @@ -1112,12 +1112,12 @@ public class FooBarTest extends LegacyTestCase { Collection fooBag = new ArrayList(); fooBag.add( new Foo() ); fooBag.add( new Foo() ); - baz.setFooBag(fooBag); + baz.setFooBag( fooBag ); s.save(baz); s.flush(); fooBag = baz.getFooBag(); s.createQuery( "from Baz baz left join fetch baz.fooBag" ).list(); - assertTrue( fooBag==baz.getFooBag() ); + assertTrue( fooBag == baz.getFooBag() ); s.getTransaction().commit(); s.close(); @@ -1125,10 +1125,10 @@ public class FooBarTest extends LegacyTestCase { s.beginTransaction(); baz = (Baz) s.load( Baz.class, baz.getCode() ); Object bag = baz.getFooBag(); - assertFalse( Hibernate.isInitialized(bag) ); + assertFalse( Hibernate.isInitialized( bag ) ); s.createQuery( "from Baz baz left join fetch baz.fooBag" ).list(); assertTrue( bag==baz.getFooBag() ); - assertTrue( baz.getFooBag().size()==2 ); + assertTrue( baz.getFooBag().size() == 2 ); s.delete(baz); s.getTransaction().commit(); s.close(); @@ -1141,18 +1141,18 @@ public class FooBarTest extends LegacyTestCase { Baz baz = new Baz(); List l = new ArrayList(); baz.setStringList(l); - l.add("foo"); + l.add( "foo" ); Serializable id = s.save(baz); l.add("bar"); s.flush(); - l.add("baz"); + l.add( "baz" ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); baz = (Baz) s.load(Baz.class, id); - assertTrue( baz.getStringList().size()==3 && baz.getStringList().contains("bar") ); + assertTrue( baz.getStringList().size() == 3 && baz.getStringList().contains( "bar" ) ); s.delete(baz); s.getTransaction().commit(); s.close(); @@ -1163,7 +1163,7 @@ public class FooBarTest extends LegacyTestCase { Session s = openSession(); s.beginTransaction(); Foo foo = new Foo(); - s.save(foo); + s.save( foo ); s.getTransaction().commit(); s.close(); @@ -1173,24 +1173,24 @@ public class FooBarTest extends LegacyTestCase { s.beginTransaction(); FooProxy foo2 = (FooProxy) s.load( Foo.class, foo.getKey() ); foo2.setString("dirty"); - foo2.setBoolean( new Boolean(false) ); - foo2.setBytes( new byte[] { 1,2,3} ); - foo2.setDate(null); - foo2.setShort( new Short("69") ); + foo2.setBoolean( new Boolean( false ) ); + foo2.setBytes( new byte[] {1, 2, 3} ); + foo2.setDate( null ); + foo2.setShort( new Short( "69" ) ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); - foo2.setString("dirty again"); + foo2.setString( "dirty again" ); s.update(foo2); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); - foo2.setString("dirty again 2"); - s.update(foo2); + foo2.setString( "dirty again 2" ); + s.update( foo2 ); s.getTransaction().commit(); s.close(); @@ -1200,7 +1200,7 @@ public class FooBarTest extends LegacyTestCase { s.load( foo3, foo.getKey() ); // There is an interbase bug that causes null integers to return as 0, also numeric precision is <= 15 assertTrue( "update", foo2.equalsFoo(foo3) ); - s.delete(foo3); + s.delete( foo3 ); doDelete( s, "from Glarch" ); s.getTransaction().commit(); s.close(); @@ -1252,13 +1252,13 @@ public class FooBarTest extends LegacyTestCase { fooBag.add( new Foo() ); fooBag.add( new Foo() ); baz.setFooBag(fooBag); - s.save(baz); + s.save( baz ); s.flush(); fooBag = baz.getFooBag(); s.createQuery( "from Baz baz left join fetch baz.fooBag" ).list(); - assertTrue( Hibernate.isInitialized(fooBag) ); - assertTrue( fooBag==baz.getFooBag() ); - assertTrue( baz.getFooBag().size()==2 ); + assertTrue( Hibernate.isInitialized( fooBag ) ); + assertTrue( fooBag == baz.getFooBag() ); + assertTrue( baz.getFooBag().size() == 2 ); s.getTransaction().commit(); s.close(); @@ -1268,7 +1268,7 @@ public class FooBarTest extends LegacyTestCase { Object bag = baz.getFooBag(); assertFalse( Hibernate.isInitialized(bag) ); s.createQuery( "from Baz baz left join fetch baz.fooBag" ).list(); - assertTrue( Hibernate.isInitialized(bag) ); + assertTrue( Hibernate.isInitialized( bag ) ); assertTrue( bag==baz.getFooBag() ); assertTrue( baz.getFooBag().size()==2 ); s.delete(baz); @@ -1569,9 +1569,9 @@ public class FooBarTest extends LegacyTestCase { s.beginTransaction(); Baz baz = (Baz) s.load(Baz.class, id); Set foos = baz.getFooSet(); - assertTrue( foos.size()==0 ); + assertTrue( foos.size() == 0 ); Foo foo = new Foo(); - foos.add(foo); + foos.add( foo ); s.save(foo); s.flush(); s.delete(foo); @@ -1688,7 +1688,7 @@ public class FooBarTest extends LegacyTestCase { s = openSession(); s.beginTransaction(); //g = (Glarch) s.createQuery( "from Glarch g where g.multiple.count=12" ).list().get(0); - s.createQuery( "from Glarch g where g.multiple.count=12" ).list().get(0); + s.createQuery( "from Glarch g where g.multiple.count=12" ).list().get( 0 ); s.getTransaction().commit(); s.close(); @@ -1704,9 +1704,9 @@ public class FooBarTest extends LegacyTestCase { s = openSession(); s.beginTransaction(); g = (GlarchProxy) s.load(Glarch.class, gid); - assertTrue( g.getMultiple()!=null ); + assertTrue( g.getMultiple() != null ); assertEquals( g.getMultiple().count, 12 ); - assertSame(g.getMultiple().glarch, g); + assertSame( g.getMultiple().glarch, g ); s.delete(g); s.getTransaction().commit(); s.close(); @@ -1718,8 +1718,8 @@ public class FooBarTest extends LegacyTestCase { s.beginTransaction(); Baz baz = new Baz(); Set bars = new HashSet(); - baz.setCascadingBars(bars); - s.save(baz); + baz.setCascadingBars( bars ); + s.save( baz ); s.flush(); baz.getCascadingBars().add( new Bar() ); s.delete(baz); @@ -1734,16 +1734,16 @@ public class FooBarTest extends LegacyTestCase { Bar bar2 = new Bar(); bar.setName("Bar"); bar2.setName("Bar Two"); - bar.setX(10); - bar2.setX(1000);Baz baz = new Baz(); + bar.setX( 10 ); + bar2.setX( 1000 );Baz baz = new Baz(); baz.setCascadingBars( new HashSet() ); baz.getCascadingBars().add(bar); bar.setBaz(baz); Session s = openSession(); Transaction txn = s.beginTransaction(); - s.save(baz); - s.save(bar2); + s.save( baz ); + s.save( bar2 ); List list = s.createQuery( "from Bar bar left join bar.baz baz left join baz.cascadingBars b where bar.name like 'Bar %'" @@ -1757,11 +1757,11 @@ public class FooBarTest extends LegacyTestCase { q = s.createQuery("select bar, b from Bar bar left join bar.baz baz left join baz.cascadingBars b where ( bar.name in (:nameList) or bar.name in (:nameList) ) and bar.string = :stringVal"); HashSet nameList = new HashSet(); - nameList.add("bar"); - nameList.add("Bar"); - nameList.add("Bar Two"); - q.setParameterList("nameList", nameList); - q.setParameter("stringVal", "a string"); + nameList.add( "bar" ); + nameList.add( "Bar" ); + nameList.add( "Bar Two" ); + q.setParameterList( "nameList", nameList ); + q.setParameter( "stringVal", "a string" ); list = q.list(); if ( !(getDialect() instanceof SAPDBDialect) ) assertTrue( list.size()==2 ); @@ -1774,19 +1774,19 @@ public class FooBarTest extends LegacyTestCase { q = s.createQuery("select bar, b from Bar bar inner join bar.baz baz inner join baz.cascadingBars b where bar.name like 'Bar%'"); Object result = q.uniqueResult(); - assertTrue( result!=null ); + assertTrue( result != null ); q = s.createQuery("select bar, b from Bar bar left join bar.baz baz left join baz.cascadingBars b where bar.name like :name and b.name like :name"); - q.setString("name", "Bar%"); + q.setString( "name", "Bar%" ); list = q.list(); assertTrue( list.size()==1 ); // This test added for issue HB-297 - there is an named parameter in the Order By clause q = s.createQuery("select bar from Bar bar order by ((bar.x - :valueX)*(bar.x - :valueX))"); - q.setInteger("valueX", bar.getX()+1); + q.setInteger( "valueX", bar.getX() + 1 ); list = q.list(); - assertTrue( ((Bar)list.get(0)).getX() == bar.getX()); - q.setInteger("valueX", bar2.getX()+1); + assertTrue( ((Bar) list.get( 0 )).getX() == bar.getX() ); + q.setInteger( "valueX", bar2.getX() + 1 ); list = q.list(); assertTrue( ((Bar)list.get(0)).getX() == bar2.getX()); @@ -1928,7 +1928,7 @@ public class FooBarTest extends LegacyTestCase { Session s = openSession(); Transaction txn = s.beginTransaction(); Foo f = new Foo(); - s.save(f); + s.save( f ); s.flush(); List list = s.createCriteria(Foo.class) @@ -1940,7 +1940,7 @@ public class FooBarTest extends LegacyTestCase { .setFetchMode("baz", FetchMode.SELECT) .setFetchMode("abstracts", FetchMode.JOIN) .list(); - assertTrue( list.size()==1 && list.get(0)==f ); + assertTrue( list.size() == 1 && list.get( 0 ) == f ); list = s.createCriteria(Foo.class).add( Restrictions.disjunction() @@ -1950,7 +1950,7 @@ public class FooBarTest extends LegacyTestCase { ) .add( Restrictions.isNotNull("boolean") ) .list(); - assertTrue( list.size()==1 && list.get(0)==f ); + assertTrue( list.size() == 1 && list.get( 0 ) == f ); Foo example = new Foo(); example.setString("a STRing"); @@ -1963,7 +1963,10 @@ public class FooBarTest extends LegacyTestCase { .excludeProperty("yesno") ) .list(); - assertTrue( "Example API without like did not work correctly, size was " + list.size(), list.size()==1 && list.get(0)==f ); + assertTrue( + "Example API without like did not work correctly, size was " + list.size(), + list.size() == 1 && list.get( 0 ) == f + ); example.setString("rin"); list = s.createCriteria(Foo.class).add( @@ -2001,11 +2004,11 @@ public class FooBarTest extends LegacyTestCase { .addOrder( Order.asc("date") ) .addOrder( Order.desc("string") ) .list(); - assertTrue( list.size()==0 ); + assertTrue( list.size() == 0 ); list = s.createCriteria(Foo.class) .setFetchMode( "component.importantDates", FetchMode.JOIN ) .list(); - assertTrue( list.size()==3 ); + assertTrue( list.size() == 3 ); list = s.createCriteria(Foo.class) .setFetchMode( "component.importantDates", FetchMode.JOIN ) @@ -2038,9 +2041,9 @@ public class FooBarTest extends LegacyTestCase { s.save( new Bar() ); list = s.createCriteria(Bar.class) .list(); - assertTrue( list.size()==1 ); + assertTrue( list.size() == 1 ); assertTrue( s.createCriteria(Foo.class).list().size()==3 ); - s.delete( list.get(0) ); + s.delete( list.get( 0 ) ); s.delete( f.getFoo() ); s.delete(f); @@ -2073,28 +2076,28 @@ public class FooBarTest extends LegacyTestCase { Session s = openSession(); s.beginTransaction(); - s.save(foo1); + s.save( foo1 ); s.save(foo2); - baz.setFooArray(arr); - s.save(baz); + baz.setFooArray( arr ); + s.save( baz ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); baz = (Baz) s.load( Baz.class, baz.getCode() ); - assertTrue( baz.getFooArray().length==1 ); + assertTrue( baz.getFooArray().length == 1 ); assertTrue( s.createQuery( "from Baz baz join baz.fooArray foo" ).list().size()==1 ); assertTrue( s.createQuery( "from Foo foo" ).list().size()==2 ); - assertTrue( s.createFilter( baz.getFooArray(), "" ).list().size()==1 ); + assertTrue( s.createFilter( baz.getFooArray(), "" ).list().size() == 1 ); //assertTrue( s.delete("from java.lang.Object o")==9 ); doDelete( s, "from Foo foo" ); String bazid = baz.getCode(); - s.delete(baz); + s.delete( baz ); int rows=s.connection().createStatement().executeUpdate( "delete from FOO_ARRAY where id_='" + bazid + "' and i>=8" ); - assertTrue(rows==1); + assertTrue( rows == 1 ); s.getTransaction().commit(); s.close(); } @@ -2223,7 +2226,7 @@ public class FooBarTest extends LegacyTestCase { List list = new ArrayList(); list.add( new Fee() ); list.add( new Fee() ); - baz.setFees(list); + baz.setFees( list ); s.save(baz); t.commit(); s.close(); @@ -2231,7 +2234,7 @@ public class FooBarTest extends LegacyTestCase { s = openSession(); t = s.beginTransaction(); baz = (Baz) s.load( Baz.class, baz.getCode() ); - assertTrue( baz.getFees().size()==2 ); + assertTrue( baz.getFees().size() == 2 ); s.delete(baz); assertTrue( !s.createQuery( "from Fee fee" ).iterate().hasNext() ); t.commit(); @@ -2416,12 +2419,12 @@ public class FooBarTest extends LegacyTestCase { while ( iter.hasNext() ) { if ( iter.next().equals("a new value") ) found = true; } - assertTrue(found); - baz.setStringArray(null); + assertTrue( found ); + baz.setStringArray( null ); s.createQuery( "from Baz baz" ).iterate(); //no flush iter = s.createQuery( "select elements(baz.stringArray) from Baz baz" ).iterate(); assertTrue( !iter.hasNext() ); - baz.getStringList().add("1E1"); + baz.getStringList().add( "1E1" ); iter = s.createQuery( "from Foo foo" ).iterate();//no flush assertTrue( !iter.hasNext() ); iter = s.createQuery( "select elements(baz.stringList) from Baz baz" ).iterate(); @@ -2429,8 +2432,8 @@ public class FooBarTest extends LegacyTestCase { while ( iter.hasNext() ) { if ( iter.next().equals("1E1") ) found = true; } - assertTrue(found); - baz.getStringList().remove("1E1"); + assertTrue( found ); + baz.getStringList().remove( "1E1" ); iter = s.createQuery( "select elements(baz.stringArray) from Baz baz" ).iterate(); //no flush iter = s.createQuery( "select elements(baz.stringList) from Baz baz" ).iterate(); found = false; @@ -2441,9 +2444,9 @@ public class FooBarTest extends LegacyTestCase { List newList = new ArrayList(); newList.add("value"); - baz.setStringList(newList); + baz.setStringList( newList ); iter = s.createQuery( "from Foo foo" ).iterate();//no flush - baz.setStringList(null); + baz.setStringList( null ); iter = s.createQuery( "select elements(baz.stringList) from Baz baz" ).iterate(); assertTrue( !iter.hasNext() ); @@ -2452,7 +2455,7 @@ public class FooBarTest extends LegacyTestCase { iter = s.createQuery( "select elements(baz.stringList) from Baz baz" ).iterate(); assertTrue( iter.hasNext() ); - s.delete(baz); + s.delete( baz ); txn.commit(); s.close(); } @@ -2809,7 +2812,7 @@ public class FooBarTest extends LegacyTestCase { Foo foo2 = new Foo(); s.load( foo2, foo.getKey() ); // There is an interbase bug that causes null integers to return as 0, also numeric precision is <= 15 - assertTrue( "create", foo.equalsFoo(foo2) ); + assertTrue( "create", foo.equalsFoo( foo2 ) ); s.delete(foo2); s.getTransaction().commit(); s.close(); @@ -2821,27 +2824,27 @@ public class FooBarTest extends LegacyTestCase { s.beginTransaction(); Qux q = new Qux("0"); s.save(q); - q.setChild( new Qux("1") ); + q.setChild( new Qux( "1" ) ); s.save( q.getChild() ); Qux q2 = new Qux("2"); q2.setChild( q.getChild() ); Qux q3 = new Qux("3"); q.getChild().setChild(q3); - s.save(q3); + s.save( q3 ); Qux q4 = new Qux("4"); - q4.setChild(q3); + q4.setChild( q3 ); s.save(q4); - s.save(q2); + s.save( q2 ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); List l = s.createQuery( "from Qux" ).list(); - assertTrue( "", l.size()==5); - s.delete( l.get(0) ); - s.delete( l.get(1) ); - s.delete( l.get(2) ); + assertTrue( "", l.size() == 5 ); + s.delete( l.get( 0 ) ); + s.delete( l.get( 1 ) ); + s.delete( l.get( 2 ) ); s.delete( l.get(3) ); s.delete( l.get(4) ); s.getTransaction().commit(); @@ -2875,13 +2878,13 @@ public class FooBarTest extends LegacyTestCase { s.beginTransaction(); Baz baz = new Baz(); baz.setDefaults(); - s.save(baz); + s.save( baz ); s.flush(); assertTrue( s.contains(baz) ); - s.evict(baz); + s.evict( baz ); assertFalse( s.contains(baz) ); Baz baz2 = (Baz) s.load( Baz.class, baz.getCode() ); - assertFalse(baz==baz2); + assertFalse( baz == baz2 ); s.delete(baz2); s.getTransaction().commit(); s.close(); @@ -2894,20 +2897,20 @@ public class FooBarTest extends LegacyTestCase { Bar bar = new Bar(); s.save(bar); bar.setAbstracts( new HashSet() ); - bar.getAbstracts().add(bar); + bar.getAbstracts().add( bar ); Bar bar2 = new Bar(); - bar.getAbstracts().add(bar2); + bar.getAbstracts().add( bar2 ); bar.setFoo(bar); - s.save(bar2); + s.save( bar2 ); s.getTransaction().commit(); s.close(); - bar.setAbstracts(null); + bar.setAbstracts( null ); s = openSession(); s.beginTransaction(); s.load( bar, bar.getKey() ); - assertTrue( "collection contains self", bar.getAbstracts().size()==2 && bar.getAbstracts().contains(bar) ); + assertTrue( "collection contains self", bar.getAbstracts().size() == 2 && bar.getAbstracts().contains( bar ) ); assertTrue( "association to self", bar.getFoo()==bar ); Iterator iter = bar.getAbstracts().iterator(); while ( iter.hasNext() ) { @@ -2984,13 +2987,13 @@ public class FooBarTest extends LegacyTestCase { s.beginTransaction(); Foo x = new Foo(); Foo y = new Foo(); - x.setFoo(y); - y.setFoo(x); - s.save(x); - s.save(y); + x.setFoo( y ); + y.setFoo( x ); + s.save( x ); + s.save( y ); s.flush(); - s.delete(y); - s.delete(x); + s.delete( y ); + s.delete( x ); s.getTransaction().commit(); s.close(); } @@ -3786,7 +3789,7 @@ public class FooBarTest extends LegacyTestCase { s = openSession(); s.beginTransaction(); baz = (Baz) s.load( Baz.class, baz.getCode() ); - s.delete(baz); + s.delete( baz ); s.getTransaction().commit(); s.close(); } @@ -3798,11 +3801,11 @@ public class FooBarTest extends LegacyTestCase { Foo foo = new Foo(); foo.setComponent( new FooComponent("foo", 69, null, new FooComponent("bar", 96, null, null) ) ); s.save(foo); - foo.getComponent().setName("IFA"); + foo.getComponent().setName( "IFA" ); txn.commit(); s.close(); - foo.setComponent(null); + foo.setComponent( null ); s = openSession(); txn = s.beginTransaction(); @@ -3812,7 +3815,7 @@ public class FooBarTest extends LegacyTestCase { foo.getComponent().getName().equals("IFA") && foo.getComponent().getSubcomponent().getName().equals("bar") ); - assertTrue( "cascade save via component", foo.getComponent().getGlarch()!=null); + assertTrue( "cascade save via component", foo.getComponent().getGlarch() != null ); foo.getComponent().getSubcomponent().setName("baz"); txn.commit(); s.close(); @@ -3834,10 +3837,10 @@ public class FooBarTest extends LegacyTestCase { s = openSession(); txn = s.beginTransaction(); foo = new Foo(); - s.save(foo); + s.save( foo ); foo.setCustom( new String[] { "one", "two" } ); assertTrue( s.createQuery( "from Foo foo where foo.custom.s1 = 'one'" ).list().get(0)==foo ); - s.delete(foo); + s.delete( foo ); txn.commit(); s.close(); } @@ -4037,10 +4040,10 @@ public class FooBarTest extends LegacyTestCase { s.beginTransaction(); One one = new One(); s.save(one); - one.setValue("yada"); + one.setValue( "yada" ); Many many = new Many(); - many.setOne(one); - s.save(many); + many.setOne( one ); + s.save( many ); s.getTransaction().commit(); s.close(); @@ -4159,7 +4162,7 @@ public class FooBarTest extends LegacyTestCase { s.beginTransaction(); foo = (FooProxy) s.createQuery( "from Foo foo" ).list().get(0); FooProxy foo2 = (FooProxy) s.load( Foo.class, foo.getKey() ); - assertTrue("find returns same object as load", foo==foo2); + assertTrue( "find returns same object as load", foo == foo2 ); s.getTransaction().commit(); s.close(); @@ -4167,7 +4170,7 @@ public class FooBarTest extends LegacyTestCase { s.beginTransaction(); foo2 = (FooProxy) s.load( Foo.class, foo.getKey() ); foo = (FooProxy) s.createQuery( "from Foo foo" ).list().get(0); - assertTrue("find returns same object as load", foo==foo2); + assertTrue( "find returns same object as load", foo == foo2 ); doDelete( s, "from Foo foo" ); s.getTransaction().commit(); s.close(); @@ -4180,9 +4183,9 @@ public class FooBarTest extends LegacyTestCase { Foo foo = new Foo(); s.save(foo); s.flush(); - s.connection().createStatement().executeUpdate("update "+getDialect().openQuote()+"foos"+getDialect().closeQuote()+" set long_ = -3"); + s.connection().createStatement().executeUpdate( "update " + getDialect().openQuote() + "foos" + getDialect().closeQuote() + " set long_ = -3" ); s.refresh(foo); - assertTrue( foo.getLong().longValue()==-3l ); + assertTrue( foo.getLong().longValue() == -3l ); assertTrue( s.getCurrentLockMode(foo)==LockMode.READ ); s.refresh(foo, LockMode.UPGRADE); if ( getDialect().supportsOuterJoinForUpdate() ) { @@ -4235,10 +4238,10 @@ public class FooBarTest extends LegacyTestCase { s.close(); s = openSession(); s.beginTransaction(); - s.update(v, id); - s.update(v, id); - s.delete(v); - s.delete(v); + s.update( v, id ); + s.update( v, id ); + s.delete( v ); + s.delete( v ); s.getTransaction().commit(); s.close(); } @@ -4248,8 +4251,8 @@ public class FooBarTest extends LegacyTestCase { Session s = openSession(); s.beginTransaction(); Vetoer v = new Vetoer(); - v.setStrings( new String[] { "foo", "bar", "baz" } ); - s.save(v); Serializable id = s.save(v); + v.setStrings( new String[] {"foo", "bar", "baz"} ); + s.save( v ); Serializable id = s.save(v); v.getStrings()[1] = "osama"; s.getTransaction().commit(); s.close(); @@ -4257,8 +4260,8 @@ public class FooBarTest extends LegacyTestCase { s = openSession(); s.beginTransaction(); v = (Vetoer) s.load(Vetoer.class, id); - assertTrue( "serializable type", v.getStrings()[1].equals("osama") ); - s.delete(v); s.delete(v); + assertTrue( "serializable type", v.getStrings()[1].equals( "osama" ) ); + s.delete(v); s.delete( v ); s.flush(); s.getTransaction().commit(); s.close(); @@ -4339,12 +4342,12 @@ public class FooBarTest extends LegacyTestCase { s.createQuery( "from Fo" ).list(); tx.commit(); Connection c = s.disconnect(); - assertTrue( c!=null ); - s.reconnect(c); + assertTrue( c != null ); + s.reconnect( c ); tx = s.beginTransaction(); s.createQuery( "from Fo" ).list(); tx.commit(); - assertTrue( s.close()==c ); + assertTrue( s.close() == c ); c.close(); } @@ -4368,8 +4371,8 @@ public class FooBarTest extends LegacyTestCase { s = openSession(); s.beginTransaction(); baz = (Baz) s.load( Baz.class, baz.getCode() ); - assertTrue( ( (FooComponent) baz.getTopComponents().get(0) ).getCount()==99 ); - s.delete(baz); + assertTrue( ((FooComponent) baz.getTopComponents().get( 0 )).getCount() == 99 ); + s.delete( baz ); s.getTransaction().commit(); s.close(); } @@ -4380,17 +4383,17 @@ public class FooBarTest extends LegacyTestCase { Transaction txn = s.beginTransaction(); Foo foo = new Foo(); Serializable id = s.save(foo); - assertTrue(id!=null); + assertTrue( id != null ); Qux q = new Qux("q"); foo.getDependent().setQux(q); - s.save(q); - q.getFoo().setString("foo2"); + s.save( q ); + q.getFoo().setString( "foo2" ); //s.flush(); //s.connection().commit(); assertTrue( s.createQuery( "from Foo foo where foo.dependent.qux.foo.string = 'foo2'" ).iterate().hasNext() ); - s.delete(foo); + s.delete( foo ); txn.commit(); s.close(); } @@ -4452,8 +4455,8 @@ public class FooBarTest extends LegacyTestCase { s.beginTransaction(); GlarchProxy g = new Glarch(); Foo foo = new Foo(); - g.setAny(foo); - Serializable gid = s.save(g); + g.setAny( foo ); + Serializable gid = s.save( g ); s.save(foo); s.getTransaction().commit(); s.close(); @@ -4463,7 +4466,7 @@ public class FooBarTest extends LegacyTestCase { g = (GlarchProxy) s.load(Glarch.class, gid); assertTrue( g.getAny()!=null && g.getAny() instanceof FooProxy ); s.delete( g.getAny() ); - s.delete(g); + s.delete( g ); s.getTransaction().commit(); s.close(); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java index 50823bf17d..1c55ce5f56 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java @@ -22,7 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.test.legacy; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; diff --git a/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/NamingStrategyTest.java b/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/NamingStrategyTest.java index a5499ce6e2..94614c898a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/NamingStrategyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/NamingStrategyTest.java @@ -22,10 +22,10 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.test.namingstrategy; + import org.hibernate.cfg.Configuration; import org.hibernate.mapping.Column; import org.hibernate.mapping.PersistentClass; -import org.hibernate.testing.junit.functional.FunctionalTestCase; import org.junit.Test; diff --git a/hibernate-core/src/test/java/org/hibernate/test/service/ServiceBootstrappingTest.java b/hibernate-core/src/test/java/org/hibernate/test/service/ServiceBootstrappingTest.java index 4cc2b31656..7feacb640f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/service/ServiceBootstrappingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/service/ServiceBootstrappingTest.java @@ -37,8 +37,8 @@ import org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionPr import org.hibernate.service.jdbc.connections.internal.UserSuppliedConnectionProviderImpl; import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; +import org.hibernate.testing.env.ConnectionProviderBuilder; import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.test.common.ConnectionProviderBuilder; /** * @author Steve Ebersole diff --git a/hibernate-core/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java b/hibernate-core/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java index d1776f7b70..4dab7c189d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java @@ -36,7 +36,7 @@ import org.junit.Test; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; diff --git a/hibernate-core/src/test/java/org/hibernate/test/transaction/jdbc/TestExpectedUsage.java b/hibernate-core/src/test/java/org/hibernate/test/transaction/jdbc/TestExpectedUsage.java index ac5d81fd1a..3943269b41 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/transaction/jdbc/TestExpectedUsage.java +++ b/hibernate-core/src/test/java/org/hibernate/test/transaction/jdbc/TestExpectedUsage.java @@ -45,7 +45,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.test.common.ConnectionProviderBuilder; +import org.hibernate.testing.env.ConnectionProviderBuilder; import org.hibernate.test.common.JournalingTransactionObserver; import org.hibernate.test.common.TransactionContextImpl; import org.hibernate.test.common.TransactionEnvironmentImpl; diff --git a/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/BasicDrivingTest.java b/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/BasicDrivingTest.java index a06fae5fe6..02a108ec77 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/BasicDrivingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/BasicDrivingTest.java @@ -49,8 +49,8 @@ import org.hibernate.service.internal.ServiceRegistryImpl; import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator; import org.hibernate.service.jta.platform.spi.JtaPlatform; +import org.hibernate.testing.env.ConnectionProviderBuilder; import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.test.common.ConnectionProviderBuilder; import org.hibernate.test.common.JournalingTransactionObserver; import org.hibernate.test.common.TransactionContextImpl; import org.hibernate.test.common.TransactionEnvironmentImpl; diff --git a/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/ManagedDrivingTest.java b/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/ManagedDrivingTest.java index 93ca458dcf..7cb8baad8a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/ManagedDrivingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/ManagedDrivingTest.java @@ -49,7 +49,7 @@ import org.junit.Before; import org.junit.Test; import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.test.common.ConnectionProviderBuilder; +import org.hibernate.testing.env.ConnectionProviderBuilder; import org.hibernate.test.common.JournalingTransactionObserver; import org.hibernate.test.common.TransactionContextImpl; import org.hibernate.test.common.TransactionEnvironmentImpl; diff --git a/hibernate-core/src/test/java/org/hibernate/test/typeparameters/DefaultValueIntegerType.java b/hibernate-core/src/test/java/org/hibernate/test/typeparameters/DefaultValueIntegerType.java index 0ce4d22ac7..dc8a744555 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/typeparameters/DefaultValueIntegerType.java +++ b/hibernate-core/src/test/java/org/hibernate/test/typeparameters/DefaultValueIntegerType.java @@ -1,5 +1,5 @@ package org.hibernate.test.typeparameters; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/hibernate-core/src/test/java/org/hibernate/test/util/StringHelperTest.java b/hibernate-core/src/test/java/org/hibernate/test/util/StringHelperTest.java index 1efabee28a..507e10c584 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/util/StringHelperTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/util/StringHelperTest.java @@ -1,50 +1,49 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2011, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.test.util; - -import org.hibernate.internal.util.StringHelper; -import org.hibernate.testing.junit.UnitTestCase; - -import org.junit.Test; - -import org.hibernate.testing.junit4.BaseUnitTestCase; - -import static org.junit.Assert.assertEquals; - -/** - * @author Steve Ebersole - */ -public class StringHelperTest extends BaseUnitTestCase { - @Test - public void testAliasGeneration() { - assertSimpleAlias( "xyz", "xyz_" ); - assertSimpleAlias( "_xyz", "xyz_" ); - assertSimpleAlias( "!xyz", "xyz_" ); - assertSimpleAlias( "abcdefghijklmnopqrstuvwxyz", "abcdefghij_" ); - } - - private void assertSimpleAlias(String source, String expected) { - assertEquals( expected, StringHelper.generateAlias( source ) ); - } -} +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.util; + +import org.hibernate.internal.util.StringHelper; + +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; + +/** + * @author Steve Ebersole + */ +public class StringHelperTest extends BaseUnitTestCase { + @Test + public void testAliasGeneration() { + assertSimpleAlias( "xyz", "xyz_" ); + assertSimpleAlias( "_xyz", "xyz_" ); + assertSimpleAlias( "!xyz", "xyz_" ); + assertSimpleAlias( "abcdefghijklmnopqrstuvwxyz", "abcdefghij_" ); + } + + private void assertSimpleAlias(String source, String expected) { + assertEquals( expected, StringHelper.generateAlias( source ) ); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/testing/junit/functional/annotations/HibernateTestCase.java b/hibernate-core/src/test/java/org/hibernate/testing/junit/functional/annotations/HibernateTestCase.java index 8dd71e6d88..fc994b27f5 100644 --- a/hibernate-core/src/test/java/org/hibernate/testing/junit/functional/annotations/HibernateTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/testing/junit/functional/annotations/HibernateTestCase.java @@ -23,7 +23,6 @@ */ package org.hibernate.testing.junit.functional.annotations; -import static org.hibernate.TestLogger.LOG; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; diff --git a/hibernate-core/src/test/java/org/hibernate/testing/tm/ConnectionProviderImpl.java b/hibernate-core/src/test/java/org/hibernate/testing/tm/ConnectionProviderImpl.java index 83572c4995..f78248af97 100644 --- a/hibernate-core/src/test/java/org/hibernate/testing/tm/ConnectionProviderImpl.java +++ b/hibernate-core/src/test/java/org/hibernate/testing/tm/ConnectionProviderImpl.java @@ -29,7 +29,8 @@ import org.hibernate.HibernateException; import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; import org.hibernate.service.spi.Stoppable; import org.hibernate.service.spi.UnknownUnwrapTypeException; -import org.hibernate.test.common.ConnectionProviderBuilder; + +import org.hibernate.testing.env.ConnectionProviderBuilder; /** * A {@link ConnectionProvider} implementation adding JTA-style transactionality diff --git a/hibernate-core/src/test/java/org/hibernate/testing/tm/SimpleJtaTransactionImpl.java b/hibernate-core/src/test/java/org/hibernate/testing/tm/SimpleJtaTransactionImpl.java index 814914210a..945930421f 100644 --- a/hibernate-core/src/test/java/org/hibernate/testing/tm/SimpleJtaTransactionImpl.java +++ b/hibernate-core/src/test/java/org/hibernate/testing/tm/SimpleJtaTransactionImpl.java @@ -22,7 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.testing.tm; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.sql.Connection; import java.sql.SQLException; import java.util.LinkedList; diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/Cat.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/Cat.java index ab2fe07778..77becf5e00 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/Cat.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/Cat.java @@ -1,6 +1,6 @@ //$Id$ package org.hibernate.ejb.test; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.io.Serializable; import java.util.ArrayList; import java.util.Calendar; diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/TestCase.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/TestCase.java index 349a9bfdfb..a12f115685 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/TestCase.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/TestCase.java @@ -23,7 +23,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.test; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/RemoveTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/RemoveTest.java index a6a1e97d8c..a0f08ac569 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/RemoveTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/RemoveTest.java @@ -1,104 +1,104 @@ -//$Id$ +//$Id$ package org.hibernate.ejb.test.emops; -import static org.hibernate.TestLogger.LOG; -import java.util.Map; -import javax.persistence.EntityManager; -import javax.persistence.OptimisticLockException; -import org.hibernate.ejb.test.TestCase; - -/** - * @author Emmanuel Bernard - */ -public class RemoveTest extends TestCase { - - public void testRemove() { - Race race = new Race(); - race.competitors.add( new Competitor() ); - race.competitors.add( new Competitor() ); - race.competitors.add( new Competitor() ); - EntityManager em = getOrCreateEntityManager(); - em.getTransaction().begin(); - em.persist( race ); - em.flush(); - em.remove( race ); - em.flush(); - em.getTransaction().rollback(); - em.close(); - } - - public void testRemoveAndFind() { - Race race = new Race(); - EntityManager em = getOrCreateEntityManager(); - em.getTransaction().begin(); - em.persist( race ); - em.remove( race ); - assertNull( em.find( Race.class, race.id ) ); - em.getTransaction().rollback(); - em.close(); - } - - public void testUpdatedAndRemove() throws Exception { - Music music = new Music(); - music.setName( "Classical" ); - EntityManager em = getOrCreateEntityManager(); - em.getTransaction().begin(); - em.persist( music ); - em.getTransaction().commit(); - em.clear(); - - - EntityManager em2 = factory.createEntityManager(); - try { - em2.getTransaction().begin(); - //read music from 2nd EM - music = em2.find( Music.class, music.getId() ); - } catch (Exception e) { - em2.getTransaction().rollback(); - em2.close(); - throw e; - } - - //change music - em = getOrCreateEntityManager(); - em.getTransaction().begin(); - em.find( Music.class, music.getId() ).setName( "Rap" ); - em.getTransaction().commit(); - - try { - em2.remove( music ); //remove changed music - em2.flush(); - fail("should have an optimistic lock exception"); - } - - catch( OptimisticLockException e ) { - LOG.debug("success"); - } - finally { - em2.getTransaction().rollback(); - em2.close(); - } - - //clean - em.getTransaction().begin(); - em.remove( em.find( Music.class, music.getId() ) ); - em.getTransaction().commit(); - em.close(); - } - - @Override - public Class[] getAnnotatedClasses() { - return new Class[] { - Race.class, - Competitor.class, - Music.class - }; - } - - - @Override - public Map getConfig() { - Map cfg = super.getConfig(); - cfg.put( "hibernate.jdbc.batch_size", "0"); - return cfg; - } -} +import static org.hibernate.testing.TestLogger.LOG; +import java.util.Map; +import javax.persistence.EntityManager; +import javax.persistence.OptimisticLockException; +import org.hibernate.ejb.test.TestCase; + +/** + * @author Emmanuel Bernard + */ +public class RemoveTest extends TestCase { + + public void testRemove() { + Race race = new Race(); + race.competitors.add( new Competitor() ); + race.competitors.add( new Competitor() ); + race.competitors.add( new Competitor() ); + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); + em.persist( race ); + em.flush(); + em.remove( race ); + em.flush(); + em.getTransaction().rollback(); + em.close(); + } + + public void testRemoveAndFind() { + Race race = new Race(); + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); + em.persist( race ); + em.remove( race ); + assertNull( em.find( Race.class, race.id ) ); + em.getTransaction().rollback(); + em.close(); + } + + public void testUpdatedAndRemove() throws Exception { + Music music = new Music(); + music.setName( "Classical" ); + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); + em.persist( music ); + em.getTransaction().commit(); + em.clear(); + + + EntityManager em2 = factory.createEntityManager(); + try { + em2.getTransaction().begin(); + //read music from 2nd EM + music = em2.find( Music.class, music.getId() ); + } catch (Exception e) { + em2.getTransaction().rollback(); + em2.close(); + throw e; + } + + //change music + em = getOrCreateEntityManager(); + em.getTransaction().begin(); + em.find( Music.class, music.getId() ).setName( "Rap" ); + em.getTransaction().commit(); + + try { + em2.remove( music ); //remove changed music + em2.flush(); + fail("should have an optimistic lock exception"); + } + + catch( OptimisticLockException e ) { + LOG.debug("success"); + } + finally { + em2.getTransaction().rollback(); + em2.close(); + } + + //clean + em.getTransaction().begin(); + em.remove( em.find( Music.class, music.getId() ) ); + em.getTransaction().commit(); + em.close(); + } + + @Override + public Class[] getAnnotatedClasses() { + return new Class[] { + Race.class, + Competitor.class, + Music.class + }; + } + + + @Override + public Map getConfig() { + Map cfg = super.getConfig(); + cfg.put( "hibernate.jdbc.batch_size", "0"); + return cfg; + } +} diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/exception/ExceptionTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/exception/ExceptionTest.java index a43ff79808..e041af8431 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/exception/ExceptionTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/exception/ExceptionTest.java @@ -1,134 +1,134 @@ -// $Id$ +// $Id$ package org.hibernate.ejb.test.exception; -import static org.hibernate.TestLogger.LOG; -import java.util.Map; -import javax.persistence.EntityManager; -import javax.persistence.EntityNotFoundException; -import javax.persistence.OptimisticLockException; -import javax.persistence.PersistenceException; -import org.hibernate.cfg.Environment; -import org.hibernate.ejb.test.TestCase; -import org.hibernate.exception.ConstraintViolationException; - -/** - * @author Emmanuel Bernard - */ -@SuppressWarnings("unchecked") -public class ExceptionTest extends TestCase { - - public void testOptimisticLockingException() throws Exception { - EntityManager em = getOrCreateEntityManager(); - EntityManager em2 = factory.createEntityManager(); - em.getTransaction().begin(); - Music music = new Music(); - music.setName( "Old Country" ); - em.persist( music ); - em.getTransaction().commit(); - - try { - em2.getTransaction().begin(); - Music music2 = em2.find( Music.class, music.getId() ); - music2.setName( "HouseMusic" ); - em2.getTransaction().commit(); - } - catch ( Exception e ) { - em2.getTransaction().rollback(); - throw e; - } - finally { - em2.close(); - } - - em.getTransaction().begin(); - music.setName( "Rock" ); - try { - - em.flush(); - fail( "Should raise an optimistic lock exception" ); - } - catch ( OptimisticLockException e ) { - //success - assertEquals( music, e.getEntity() ); - } - catch ( Exception e ) { - fail( "Should raise an optimistic lock exception" ); - } - finally { - em.getTransaction().rollback(); - em.close(); - } - } - - public void testEntityNotFoundException() throws Exception { - EntityManager em = getOrCreateEntityManager(); - Music music = em.getReference( Music.class, -1 ); - try { - music.getName(); - fail( "Non existent entity should raise an exception when state is accessed" ); - } - catch ( EntityNotFoundException e ) { - LOG.debug("success"); - } - finally { - em.close(); - } - } - - public void testConstraintViolationException() throws Exception { - EntityManager em = getOrCreateEntityManager(); - em.getTransaction().begin(); - Music music = new Music(); - music.setName( "Jazz" ); - em.persist( music ); - Musician lui = new Musician(); - lui.setName( "Lui Armstrong" ); - lui.setFavouriteMusic( music ); - em.persist( lui ); - em.getTransaction().commit(); - try { - em.getTransaction().begin(); - String hqlDelete = "delete Music where name = :name"; - em.createQuery( hqlDelete ).setParameter( "name", "Jazz" ).executeUpdate(); - em.getTransaction().commit(); - fail(); - } - catch ( PersistenceException e ) { - Throwable t = e.getCause(); - assertTrue( "Should be a constraint violation", t instanceof ConstraintViolationException ); - em.getTransaction().rollback(); - } - finally { - em.close(); - } - } - - // HHH-4676 - public void testInterceptor() throws Exception { - EntityManager em = getOrCreateEntityManager(); - em.getTransaction().begin(); - Instrument instrument = new Instrument(); - instrument.setName( "Guitar" ); - try { - em.persist( instrument ); - fail( "Commit should have failed." ); - } - catch ( RuntimeException e ) { - assertTrue( em.getTransaction().getRollbackOnly() ); - } - em.close(); - } - - @Override - public Map getConfig() { - Map config = super.getConfig(); - config.put( Environment.BATCH_VERSIONED_DATA, "false" ); - return config; - } - - @Override - public Class[] getAnnotatedClasses() { - return new Class[] { - Music.class, Musician.class, Instrument.class - }; - } -} +import static org.hibernate.testing.TestLogger.LOG; +import java.util.Map; +import javax.persistence.EntityManager; +import javax.persistence.EntityNotFoundException; +import javax.persistence.OptimisticLockException; +import javax.persistence.PersistenceException; +import org.hibernate.cfg.Environment; +import org.hibernate.ejb.test.TestCase; +import org.hibernate.exception.ConstraintViolationException; + +/** + * @author Emmanuel Bernard + */ +@SuppressWarnings("unchecked") +public class ExceptionTest extends TestCase { + + public void testOptimisticLockingException() throws Exception { + EntityManager em = getOrCreateEntityManager(); + EntityManager em2 = factory.createEntityManager(); + em.getTransaction().begin(); + Music music = new Music(); + music.setName( "Old Country" ); + em.persist( music ); + em.getTransaction().commit(); + + try { + em2.getTransaction().begin(); + Music music2 = em2.find( Music.class, music.getId() ); + music2.setName( "HouseMusic" ); + em2.getTransaction().commit(); + } + catch ( Exception e ) { + em2.getTransaction().rollback(); + throw e; + } + finally { + em2.close(); + } + + em.getTransaction().begin(); + music.setName( "Rock" ); + try { + + em.flush(); + fail( "Should raise an optimistic lock exception" ); + } + catch ( OptimisticLockException e ) { + //success + assertEquals( music, e.getEntity() ); + } + catch ( Exception e ) { + fail( "Should raise an optimistic lock exception" ); + } + finally { + em.getTransaction().rollback(); + em.close(); + } + } + + public void testEntityNotFoundException() throws Exception { + EntityManager em = getOrCreateEntityManager(); + Music music = em.getReference( Music.class, -1 ); + try { + music.getName(); + fail( "Non existent entity should raise an exception when state is accessed" ); + } + catch ( EntityNotFoundException e ) { + LOG.debug("success"); + } + finally { + em.close(); + } + } + + public void testConstraintViolationException() throws Exception { + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); + Music music = new Music(); + music.setName( "Jazz" ); + em.persist( music ); + Musician lui = new Musician(); + lui.setName( "Lui Armstrong" ); + lui.setFavouriteMusic( music ); + em.persist( lui ); + em.getTransaction().commit(); + try { + em.getTransaction().begin(); + String hqlDelete = "delete Music where name = :name"; + em.createQuery( hqlDelete ).setParameter( "name", "Jazz" ).executeUpdate(); + em.getTransaction().commit(); + fail(); + } + catch ( PersistenceException e ) { + Throwable t = e.getCause(); + assertTrue( "Should be a constraint violation", t instanceof ConstraintViolationException ); + em.getTransaction().rollback(); + } + finally { + em.close(); + } + } + + // HHH-4676 + public void testInterceptor() throws Exception { + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); + Instrument instrument = new Instrument(); + instrument.setName( "Guitar" ); + try { + em.persist( instrument ); + fail( "Commit should have failed." ); + } + catch ( RuntimeException e ) { + assertTrue( em.getTransaction().getRollbackOnly() ); + } + em.close(); + } + + @Override + public Map getConfig() { + Map config = super.getConfig(); + config.put( Environment.BATCH_VERSIONED_DATA, "false" ); + return config; + } + + @Override + public Class[] getAnnotatedClasses() { + return new Class[] { + Music.class, Musician.class, Instrument.class + }; + } +} diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/lock/LockTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/lock/LockTest.java index e461a72cda..c79dbe03fb 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/lock/LockTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/lock/LockTest.java @@ -1,6 +1,6 @@ //$Id$ package org.hibernate.ejb.test.lock; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java index 36c385707a..d85334cac7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java @@ -22,7 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.components; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.math.BigInteger; import java.util.Arrays; import javax.persistence.EntityManager; diff --git a/hibernate-infinispan/hibernate-infinispan.gradle b/hibernate-infinispan/hibernate-infinispan.gradle index 71a0396a53..b7d14c98b8 100644 --- a/hibernate-infinispan/hibernate-infinispan.gradle +++ b/hibernate-infinispan/hibernate-infinispan.gradle @@ -27,7 +27,7 @@ dependencies { type = 'jar' } } - testCompile(project(':hibernate-core').sourceSets.test.classes) + testCompile( project(':hibernate-testing') ) testCompile([group: 'org.jboss', name: 'jboss-common-core', version: '2.2.14.GA']) testCompile([group: 'org.jboss.naming', name: 'jnp-client', version: jnpVersion]) testCompile([group: 'org.jboss.naming', name: 'jnpserver', version: jnpVersion]) diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractEntityCollectionRegionTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractEntityCollectionRegionTestCase.java index e651c99d14..d3e0f8ee04 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractEntityCollectionRegionTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractEntityCollectionRegionTestCase.java @@ -22,7 +22,9 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.test.cache.infinispan; + import java.util.Properties; + import org.hibernate.cache.CacheDataDescription; import org.hibernate.cache.RegionFactory; import org.hibernate.cache.TransactionalDataRegion; @@ -31,6 +33,8 @@ import org.hibernate.cache.infinispan.InfinispanRegionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator; +import org.junit.Test; + import org.hibernate.testing.ServiceRegistryBuilder; import org.hibernate.test.cache.infinispan.util.CacheTestUtil; @@ -41,80 +45,79 @@ import static org.junit.Assert.assertTrue; /** * Base class for tests of EntityRegion and CollectionRegion implementations. - * + * * @author Galder ZamarreƱo * @since 3.5 */ public abstract class AbstractEntityCollectionRegionTestCase extends AbstractRegionImplTestCase { - /** - * Creates a Region backed by an PESSIMISTIC locking JBoss Cache, and then ensures that it - * handles calls to buildAccessStrategy as expected when all the various {@link AccessType}s are - * passed as arguments. - */ - public void testSupportedAccessTypes() throws Exception { - supportedAccessTypeTest(); - } + @Test + public void testSupportedAccessTypes() throws Exception { + supportedAccessTypeTest(); + } - private void supportedAccessTypeTest() throws Exception { - Configuration cfg = CacheTestUtil.buildConfiguration("test", InfinispanRegionFactory.class, true, false); - String entityCfg = "entity"; - cfg.setProperty(InfinispanRegionFactory.ENTITY_CACHE_RESOURCE_PROP, entityCfg); - InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory( - ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() ), - cfg, - getCacheTestSupport() - ); - supportedAccessTypeTest(regionFactory, cfg.getProperties()); - } + private void supportedAccessTypeTest() throws Exception { + Configuration cfg = CacheTestUtil.buildConfiguration( "test", InfinispanRegionFactory.class, true, false ); + String entityCfg = "entity"; + cfg.setProperty( InfinispanRegionFactory.ENTITY_CACHE_RESOURCE_PROP, entityCfg ); + InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory( + ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() ), + cfg, + getCacheTestSupport() + ); + supportedAccessTypeTest( regionFactory, cfg.getProperties() ); + } - /** - * Creates a Region using the given factory, and then ensure that it handles calls to - * buildAccessStrategy as expected when all the various {@link AccessType}s are passed as - * arguments. - */ - protected abstract void supportedAccessTypeTest(RegionFactory regionFactory, Properties properties); + /** + * Creates a Region using the given factory, and then ensure that it handles calls to + * buildAccessStrategy as expected when all the various {@link AccessType}s are passed as + * arguments. + */ + protected abstract void supportedAccessTypeTest(RegionFactory regionFactory, Properties properties); - /** - * Test that the Region properly implements {@link TransactionalDataRegion#isTransactionAware()}. - * - * @throws Exception - */ - public void testIsTransactionAware() throws Exception { - Configuration cfg = CacheTestUtil.buildConfiguration("test", InfinispanRegionFactory.class, true, false); - InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory( - ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() ), - cfg, - getCacheTestSupport() - ); - TransactionalDataRegion region = (TransactionalDataRegion) createRegion(regionFactory, "test/test", cfg.getProperties(), getCacheDataDescription()); - assertTrue("Region is transaction-aware", region.isTransactionAware()); - CacheTestUtil.stopRegionFactory(regionFactory, getCacheTestSupport()); - cfg = CacheTestUtil.buildConfiguration("test", InfinispanRegionFactory.class, true, false); - // Make it non-transactional - cfg.getProperties().remove( JtaPlatformInitiator.JTA_PLATFORM ); - regionFactory = CacheTestUtil.startRegionFactory( - ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() ), - cfg, - getCacheTestSupport() - ); - region = (TransactionalDataRegion) createRegion(regionFactory, "test/test", cfg.getProperties(), getCacheDataDescription()); - assertFalse("Region is not transaction-aware", region.isTransactionAware()); - CacheTestUtil.stopRegionFactory(regionFactory, getCacheTestSupport()); - } + @Test + public void testIsTransactionAware() throws Exception { + Configuration cfg = CacheTestUtil.buildConfiguration( "test", InfinispanRegionFactory.class, true, false ); + InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory( + ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() ), + cfg, + getCacheTestSupport() + ); + TransactionalDataRegion region = (TransactionalDataRegion) createRegion( + regionFactory, "test/test", cfg.getProperties(), getCacheDataDescription() + ); + assertTrue( "Region is transaction-aware", region.isTransactionAware() ); + CacheTestUtil.stopRegionFactory( regionFactory, getCacheTestSupport() ); + cfg = CacheTestUtil.buildConfiguration( "test", InfinispanRegionFactory.class, true, false ); + // Make it non-transactional + cfg.getProperties().remove( JtaPlatformInitiator.JTA_PLATFORM ); + regionFactory = CacheTestUtil.startRegionFactory( + ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() ), + cfg, + getCacheTestSupport() + ); + region = (TransactionalDataRegion) createRegion( + regionFactory, "test/test", cfg.getProperties(), getCacheDataDescription() + ); + assertFalse( "Region is not transaction-aware", region.isTransactionAware() ); + CacheTestUtil.stopRegionFactory( regionFactory, getCacheTestSupport() ); + } - public void testGetCacheDataDescription() throws Exception { - Configuration cfg = CacheTestUtil.buildConfiguration("test", InfinispanRegionFactory.class, true, false); - InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory( - ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() ), - cfg, - getCacheTestSupport() - ); - TransactionalDataRegion region = (TransactionalDataRegion) createRegion(regionFactory, "test/test", cfg.getProperties(), getCacheDataDescription()); - CacheDataDescription cdd = region.getCacheDataDescription(); - assertNotNull(cdd); - CacheDataDescription expected = getCacheDataDescription(); - assertEquals(expected.isMutable(), cdd.isMutable()); - assertEquals(expected.isVersioned(), cdd.isVersioned()); - assertEquals(expected.getVersionComparator(), cdd.getVersionComparator()); - } + @Test + public void testGetCacheDataDescription() throws Exception { + Configuration cfg = CacheTestUtil.buildConfiguration( "test", InfinispanRegionFactory.class, true, false ); + InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory( + ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() ), + cfg, + getCacheTestSupport() + ); + TransactionalDataRegion region = (TransactionalDataRegion) createRegion( + regionFactory, "test/test", cfg.getProperties(), getCacheDataDescription() + ); + CacheDataDescription cdd = region.getCacheDataDescription(); + assertNotNull( cdd ); + CacheDataDescription expected = getCacheDataDescription(); + assertEquals( expected.isMutable(), cdd.isMutable() ); + assertEquals( expected.isVersioned(), cdd.isVersioned() ); + assertEquals( expected.getVersionComparator(), cdd.getVersionComparator() ); + } } diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTestCase.java index 3d645705fb..94f6c83ea8 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTestCase.java @@ -39,7 +39,7 @@ import org.junit.Test; import org.hibernate.test.cache.infinispan.util.CacheTestUtil; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractNonFunctionalTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractNonFunctionalTestCase.java index 307feb8e5b..f9bda567b1 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractNonFunctionalTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractNonFunctionalTestCase.java @@ -35,7 +35,7 @@ import org.junit.Before; import org.hibernate.test.cache.infinispan.util.CacheTestSupport; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; /** * Base class for all non-functional tests of Infinispan integration. diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractCollectionRegionAccessStrategyTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractCollectionRegionAccessStrategyTestCase.java index cbc6d4ddef..a0afa4e92b 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractCollectionRegionAccessStrategyTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractCollectionRegionAccessStrategyTestCase.java @@ -54,7 +54,7 @@ import org.hibernate.test.cache.infinispan.NodeEnvironment; import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeJtaTransactionManagerImpl; import org.hibernate.test.cache.infinispan.util.CacheTestUtil; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractReadOnlyAccessTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractReadOnlyAccessTestCase.java index f0f435bab8..847ae276dd 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractReadOnlyAccessTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractReadOnlyAccessTestCase.java @@ -22,9 +22,8 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.test.cache.infinispan.collection; -import org.hibernate.cache.access.AccessType; -import org.junit.Test; +import org.hibernate.cache.access.AccessType; /** * Base class for tests of TRANSACTIONAL access. @@ -32,7 +31,6 @@ import org.junit.Test; * @author Brian Stansberry */ public abstract class AbstractReadOnlyAccessTestCase extends AbstractCollectionRegionAccessStrategyTestCase { - @Test @Override protected AccessType getAccessType() { return AccessType.READ_ONLY; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java index 19b4926953..9aadb36a74 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java @@ -56,6 +56,7 @@ public class TransactionalExtraAPITestCase extends AbstractNonFunctionalTestCase @Before public final void prepareLocalAccessStrategy() throws Exception { environment = new NodeEnvironment( createConfiguration() ); + environment.prepare(); // Sleep a bit to avoid concurrent FLUSH problem avoidConcurrentFlush(); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractEntityRegionAccessStrategyTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractEntityRegionAccessStrategyTestCase.java index c113875791..0e2f7bb4d1 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractEntityRegionAccessStrategyTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractEntityRegionAccessStrategyTestCase.java @@ -46,7 +46,7 @@ import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase; import org.hibernate.test.cache.infinispan.NodeEnvironment; import org.hibernate.test.cache.infinispan.util.CacheTestUtil; -import static org.hibernate.testing.TestingLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractTransactionalAccessTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractTransactionalAccessTestCase.java index 7133ad0946..6d7c02aba6 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractTransactionalAccessTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractTransactionalAccessTestCase.java @@ -32,7 +32,7 @@ import org.hibernate.cache.access.AccessType; import junit.framework.AssertionFailedError; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java index 3c85053042..f6f5ee7d9e 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java @@ -20,13 +20,12 @@ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.hibernate.test.cache.infinispan.entity; -import org.hibernate.cache.EntityRegion; + import org.hibernate.cache.access.AccessType; import org.hibernate.cache.access.EntityRegionAccessStrategy; import org.hibernate.cache.access.SoftLock; import org.hibernate.cache.infinispan.InfinispanRegionFactory; import org.hibernate.cfg.Configuration; -import org.hibernate.service.internal.ServiceRegistryImpl; import org.junit.After; import org.junit.Before; @@ -61,6 +60,7 @@ public class TransactionalExtraAPITestCase extends AbstractNonFunctionalTestCase @Before public final void prepareLocalAccessStrategy() throws Exception { environment = new NodeEnvironment( createConfiguration() ); + environment.prepare(); // Sleep a bit to avoid concurrent FLUSH problem avoidConcurrentFlush(); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicTransactionalTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicTransactionalTestCase.java index 58cbf24fef..4cbcaa8204 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicTransactionalTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicTransactionalTestCase.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.test.cache.infinispan.functional; + import java.io.Serializable; import java.util.Map; @@ -56,6 +57,9 @@ public class BasicTransactionalTestCase extends SingleNodeTestCase { @Test public void testEntityCache() throws Exception { + Statistics stats = sessionFactory().getStatistics(); + stats.clear(); + Item item = new Item( "chris", "Chris's Item" ); beginTx(); try { @@ -78,7 +82,6 @@ public class BasicTransactionalTestCase extends SingleNodeTestCase { try { Session s = openSession(); Item found = (Item) s.load( Item.class, item.getId() ); - Statistics stats = s.getSessionFactory().getStatistics(); log.info( stats.toString() ); assertEquals( item.getDescription(), found.getDescription() ); assertEquals( 0, stats.getSecondLevelCacheMissCount() ); @@ -96,6 +99,9 @@ public class BasicTransactionalTestCase extends SingleNodeTestCase { @Test public void testCollectionCache() throws Exception { + Statistics stats = sessionFactory().getStatistics(); + stats.clear(); + Item item = new Item( "chris", "Chris's Item" ); Item another = new Item( "another", "Owned Item" ); item.addItem( another ); @@ -133,7 +139,6 @@ public class BasicTransactionalTestCase extends SingleNodeTestCase { beginTx(); try { Session s = openSession(); - Statistics stats = s.getSessionFactory().getStatistics(); SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics( Item.class.getName() + ".items" ); Item loadedWithCachedCollection = (Item) s.load( Item.class, item.getId() ); stats.logSummary(); @@ -154,6 +159,9 @@ public class BasicTransactionalTestCase extends SingleNodeTestCase { @Test public void testStaleWritesLeaveCacheConsistent() throws Exception { + Statistics stats = sessionFactory().getStatistics(); + stats.clear(); + VersionedItem item = null; Transaction txn = null; Session s = null; @@ -203,8 +211,7 @@ public class BasicTransactionalTestCase extends SingleNodeTestCase { } // check the version value in the cache... - SecondLevelCacheStatistics slcs = sessionFactory().getStatistics() - .getSecondLevelCacheStatistics( VersionedItem.class.getName() ); + SecondLevelCacheStatistics slcs = stats.getSecondLevelCacheStatistics( VersionedItem.class.getName() ); Object entry = slcs.getEntries().get( item.getId() ); Long cachedVersionValue; @@ -231,6 +238,16 @@ public class BasicTransactionalTestCase extends SingleNodeTestCase { @Test public void testQueryCacheInvalidation() throws Exception { + Statistics stats = sessionFactory().getStatistics(); + stats.clear(); + + SecondLevelCacheStatistics slcs = stats.getSecondLevelCacheStatistics( Item.class.getName() ); + sessionFactory().getCache().evictEntityRegion( Item.class.getName() ); + + assertEquals( 0, slcs.getPutCount() ); + assertEquals( 0, slcs.getElementCountInMemory() ); + assertEquals( 0, slcs.getEntries().size() ); + Session s = null; Transaction t = null; Item i = null; @@ -253,13 +270,10 @@ public class BasicTransactionalTestCase extends SingleNodeTestCase { commitOrRollbackTx(); } - SecondLevelCacheStatistics slcs = s.getSessionFactory() - .getStatistics() - .getSecondLevelCacheStatistics( Item.class.getName() ); - assertEquals( slcs.getPutCount(), 1 ); - assertEquals( slcs.getElementCountInMemory(), 1 ); - assertEquals( slcs.getEntries().size(), 1 ); + assertEquals( 1, slcs.getPutCount() ); + assertEquals( 1, slcs.getElementCountInMemory() ); + assertEquals( 1, slcs.getEntries().size() ); beginTx(); try { @@ -305,6 +319,9 @@ public class BasicTransactionalTestCase extends SingleNodeTestCase { @Test public void testQueryCache() throws Exception { + Statistics stats = sessionFactory().getStatistics(); + stats.clear(); + Session s; Item item = new Item( "chris", "Chris's Item" ); @@ -344,7 +361,6 @@ public class BasicTransactionalTestCase extends SingleNodeTestCase { beginTx(); try { s = openSession(); - Statistics stats = s.getSessionFactory().getStatistics(); s.createQuery( "from Item" ).setCacheable( true ).list(); assertEquals( 1, stats.getQueryCacheHitCount() ); s.createQuery( "delete from Item" ).executeUpdate(); @@ -360,6 +376,9 @@ public class BasicTransactionalTestCase extends SingleNodeTestCase { @Test public void testQueryCacheHitInSameTransaction() throws Exception { + Statistics stats = sessionFactory().getStatistics(); + stats.clear(); + Session s = null; Item item = new Item( "galder", "Galder's Item" ); @@ -386,7 +405,6 @@ public class BasicTransactionalTestCase extends SingleNodeTestCase { beginTx(); try { s = openSession(); - Statistics stats = s.getSessionFactory().getStatistics(); s.createQuery( "from Item" ).setCacheable( true ).list(); s.createQuery( "from Item" ).setCacheable( true ).list(); assertEquals( 1, stats.getQueryCacheHitCount() ); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/JndiRegionFactoryTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/JndiRegionFactoryTestCase.java index f75334dccf..81b2f01c41 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/JndiRegionFactoryTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/JndiRegionFactoryTestCase.java @@ -52,6 +52,8 @@ import org.hibernate.dialect.Dialect; import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.stat.Statistics; +import org.junit.Test; + import static org.junit.Assert.assertEquals; /** @@ -115,6 +117,7 @@ public class JndiRegionFactoryTestCase extends SingleNodeTestCase { cfg.setProperty( "java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" ); } + @Test public void testRedeployment() throws Exception { addEntityCheckCache( sessionFactory() ); sessionFactory().close(); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/CacheAccessListener.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/CacheAccessListener.java index 3cea204017..3d0902215a 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/CacheAccessListener.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/CacheAccessListener.java @@ -22,7 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.test.cache.infinispan.functional.classloader; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.util.HashSet; import java.util.Set; import org.hibernate.cache.infinispan.util.CacheHelper; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/IsolatedClassLoaderTest.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/IsolatedClassLoaderTest.java index 68a9f02640..3175efc521 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/IsolatedClassLoaderTest.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/IsolatedClassLoaderTest.java @@ -34,11 +34,13 @@ import org.hibernate.cache.StandardQueryCache; import org.hibernate.cache.infinispan.InfinispanRegionFactory; import org.hibernate.cfg.Configuration; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import org.junit.After; import org.junit.AfterClass; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -70,29 +72,28 @@ public class IsolatedClassLoaderTest extends DualNodeTestCase { private Cache remoteQueryCache; private CacheAccessListener remoteQueryListener; - private static ClassLoader originalClassLoader; + private static ClassLoader originalTCCL; @BeforeClass public static void prepareClassLoader() { - originalClassLoader = Thread.currentThread().getContextClassLoader(); - ClassLoader parent = originalClassLoader == null - ? IsolatedClassLoaderTest.class.getClassLoader() - : originalClassLoader; - ClassLoader selectedTCCL = new SelectedClassnameClassLoader( - new String[] { - org.hibernate.test.cache.infinispan.functional.classloader.Account.class.getName(), - org.hibernate.test.cache.infinispan.functional.classloader.AccountHolder.class.getName() - }, + originalTCCL = Thread.currentThread().getContextClassLoader(); + final String packageName = IsolatedClassLoaderTest.class.getPackage().getName(); + final String[] isolatedClassNames = new String[] { packageName + "Account", packageName + "AccountHolder" }; + final SelectedClassnameClassLoader visible = new SelectedClassnameClassLoader( + isolatedClassNames, null, null, - parent + originalTCCL ); - Thread.currentThread().setContextClassLoader( selectedTCCL ); + Thread.currentThread().setContextClassLoader( visible ); } @AfterClass public static void resetClassLoader() { - Thread.currentThread().setContextClassLoader( originalClassLoader ); + ClusterAwareRegionFactory.clearCacheManagers(); + DualNodeJtaTransactionManagerImpl.cleanupTransactions(); + DualNodeJtaTransactionManagerImpl.cleanupTransactionManagers(); + Thread.currentThread().setContextClassLoader( originalTCCL ); } @Override diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/SelectedClassnameClassLoader.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/SelectedClassnameClassLoader.java index 425e2189a7..e27141a58c 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/SelectedClassnameClassLoader.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/SelectedClassnameClassLoader.java @@ -22,7 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.test.cache.infinispan.functional.classloader; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import java.io.ByteArrayOutputStream; import java.io.FileNotFoundException; import java.io.IOException; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/DualNodeConnectionProviderImpl.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/DualNodeConnectionProviderImpl.java index dd9fef6bd8..60a6564eaf 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/DualNodeConnectionProviderImpl.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/DualNodeConnectionProviderImpl.java @@ -24,11 +24,15 @@ package org.hibernate.test.cache.infinispan.functional.cluster; import java.sql.Connection; import java.sql.SQLException; +import java.util.Map; + import org.hibernate.HibernateException; import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; +import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.Stoppable; import org.hibernate.service.spi.UnknownUnwrapTypeException; -import org.hibernate.test.common.ConnectionProviderBuilder; + +import org.hibernate.testing.env.ConnectionProviderBuilder; /** * A {@link ConnectionProvider} implementation adding JTA-style transactionality around the returned @@ -36,7 +40,7 @@ import org.hibernate.test.common.ConnectionProviderBuilder; * * @author Brian Stansberry */ -public class DualNodeConnectionProviderImpl implements ConnectionProvider { +public class DualNodeConnectionProviderImpl implements ConnectionProvider, Configurable { private static ConnectionProvider actualConnectionProvider = ConnectionProviderBuilder.buildConnectionProvider(); private String nodeId; private boolean isTransactional; @@ -104,4 +108,9 @@ public class DualNodeConnectionProviderImpl implements ConnectionProvider { public boolean supportsAggressiveRelease() { return true; } + + @Override + public void configure(Map configurationValues) { + nodeId = (String) configurationValues.get( "nodeId" ); + } } diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/SessionRefreshTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/SessionRefreshTestCase.java index 5d4bbd1a11..f424d84352 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/SessionRefreshTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/SessionRefreshTestCase.java @@ -39,7 +39,7 @@ import org.junit.Test; import org.hibernate.test.cache.infinispan.functional.classloader.Account; import org.hibernate.test.cache.infinispan.functional.classloader.ClassLoaderTestDAO; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/query/QueryRegionImplTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/query/QueryRegionImplTestCase.java index 33118b2248..d6dcadb6e7 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/query/QueryRegionImplTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/query/QueryRegionImplTestCase.java @@ -48,7 +48,7 @@ import junit.framework.AssertionFailedError; import org.hibernate.test.cache.infinispan.AbstractGeneralDataRegionTestCase; import org.hibernate.test.cache.infinispan.util.CacheTestUtil; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/tm/XaConnectionProvider.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/tm/XaConnectionProvider.java index f3f62db7c5..bc5b867503 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/tm/XaConnectionProvider.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/tm/XaConnectionProvider.java @@ -27,7 +27,8 @@ import org.hibernate.HibernateException; import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; import org.hibernate.service.spi.Stoppable; import org.hibernate.service.spi.UnknownUnwrapTypeException; -import org.hibernate.test.common.ConnectionProviderBuilder; + +import org.hibernate.testing.env.ConnectionProviderBuilder; /** * XaConnectionProvider. diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/CacheTestSupport.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/CacheTestSupport.java index 515fd81e7f..02a12ebd94 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/CacheTestSupport.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/CacheTestSupport.java @@ -31,7 +31,7 @@ import org.infinispan.Cache; import org.hibernate.cache.RegionFactory; -import static org.hibernate.TestLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; /** * Support class for tracking and cleaning up objects used in tests. diff --git a/hibernate-testing/hibernate-testing.gradle b/hibernate-testing/hibernate-testing.gradle index 40cc895d66..66bc3a9761 100644 --- a/hibernate-testing/hibernate-testing.gradle +++ b/hibernate-testing/hibernate-testing.gradle @@ -1,3 +1,26 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ apply plugin: 'java' dependencies { diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/SkipLog.java b/hibernate-testing/src/main/java/org/hibernate/testing/SkipLog.java index a9fe860b55..e90005f6d6 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/SkipLog.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/SkipLog.java @@ -25,7 +25,7 @@ package org.hibernate.testing; import org.hibernate.testing.junit4.SkipMarker; -import static org.hibernate.testing.TestingLogger.LOG; +import static org.hibernate.testing.TestLogger.LOG; /** * Well-known-location lookup for the test-skip log... @@ -34,11 +34,11 @@ import static org.hibernate.testing.TestingLogger.LOG; */ public class SkipLog { public static void reportSkip(SkipMarker skipMarker) { - LOG.info( "*** skipping test [" + skipMarker.getTestName() + "] - " + skipMarker.getReason(), new Exception() ); + LOG.info( "*** skipping test [" + skipMarker.getTestName() + "] - " + skipMarker.getReason(), new Exception() ); } public static void reportSkip(String message) { - LOG.info( "*** skipping test - " + message, new Exception() ); + LOG.info( "*** skipping test - " + message, new Exception() ); } public static void reportSkip(String reason, String testDescription) { diff --git a/hibernate-core/src/test/java/org/hibernate/TestLogger.java b/hibernate-testing/src/main/java/org/hibernate/testing/TestLogger.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/TestLogger.java rename to hibernate-testing/src/main/java/org/hibernate/testing/TestLogger.java index 91f672fe5b..2bc5b3c72e 100644 --- a/hibernate-core/src/test/java/org/hibernate/TestLogger.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/TestLogger.java @@ -21,16 +21,15 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate; +package org.hibernate.testing; import org.jboss.logging.BasicLogger; import org.jboss.logging.Logger; import org.jboss.logging.MessageLogger; /** - * Defines internationalized messages for all modules part of hibernate-core. + * Logging support for the hibernate-testing module */ @MessageLogger( projectCode = "HHH" ) public interface TestLogger extends BasicLogger { - public static final TestLogger LOG = Logger.getMessageLogger(TestLogger.class, TestLogger.class.getName()); } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/TestingLogger.java b/hibernate-testing/src/main/java/org/hibernate/testing/TestingLogger.java deleted file mode 100644 index 96a2cf0466..0000000000 --- a/hibernate-testing/src/main/java/org/hibernate/testing/TestingLogger.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2011, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.testing; -import org.jboss.logging.BasicLogger; -import org.jboss.logging.Logger; -import org.jboss.logging.MessageLogger; - -/** - * Logging support for the hibernate-testing module - */ -@MessageLogger( projectCode = "HHH" ) -public interface TestingLogger extends BasicLogger { - public static final TestingLogger LOG = Logger.getMessageLogger(TestingLogger.class, TestingLogger.class.getName()); -} diff --git a/hibernate-core/src/test/java/org/hibernate/test/common/ConnectionProviderBuilder.java b/hibernate-testing/src/main/java/org/hibernate/testing/env/ConnectionProviderBuilder.java similarity index 91% rename from hibernate-core/src/test/java/org/hibernate/test/common/ConnectionProviderBuilder.java rename to hibernate-testing/src/main/java/org/hibernate/testing/env/ConnectionProviderBuilder.java index 34da33a7aa..410653273c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/common/ConnectionProviderBuilder.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/env/ConnectionProviderBuilder.java @@ -1,7 +1,7 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * Copyright (c) 2010-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are * distributed under license by Red Hat Inc. @@ -21,8 +21,10 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.test.common; +package org.hibernate.testing.env; + import java.util.Properties; + import org.hibernate.cfg.Environment; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.H2Dialect; @@ -30,7 +32,7 @@ import org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionPr import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; /** - * TODO : javadoc + * Defines the JDBC connection information (currently H2) used by Hibernate for unit (not functional!) tests * * @author Steve Ebersole */