HHH-6742 move unit tests back to src/test

This commit is contained in:
Strong Liu 2011-10-18 21:47:19 +08:00
parent c84fb01c22
commit 98e68aab4b
530 changed files with 671 additions and 555 deletions

View File

@ -30,6 +30,7 @@ import java.util.ArrayList;
import java.util.Map;
import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.cfg.Environment;
import org.hibernate.internal.util.ReflectHelper;
@ -87,8 +88,8 @@ public class DriverManagerConnectionProviderImpl implements ConnectionProvider,
public void configure(Map configurationValues) {
LOG.usingHibernateBuiltInConnectionPool();
String driverClassName = (String) configurationValues.get( Environment.DRIVER );
if (driverClassName == null) LOG.jdbcDriverNotSpecified(Environment.DRIVER);
String driverClassName = (String) configurationValues.get( AvailableSettings.DRIVER );
if (driverClassName == null) LOG.jdbcDriverNotSpecified(AvailableSettings.DRIVER);
else {
try {
// trying via forName() first to be as close to DriverManager's semantics
@ -104,18 +105,18 @@ public class DriverManagerConnectionProviderImpl implements ConnectionProvider,
}
}
poolSize = ConfigurationHelper.getInt( Environment.POOL_SIZE, configurationValues, 20 ); // default pool size 20
poolSize = ConfigurationHelper.getInt( AvailableSettings.POOL_SIZE, configurationValues, 20 ); // default pool size 20
LOG.hibernateConnectionPoolSize(poolSize);
autocommit = ConfigurationHelper.getBoolean( Environment.AUTOCOMMIT, configurationValues );
autocommit = ConfigurationHelper.getBoolean( AvailableSettings.AUTOCOMMIT, configurationValues );
LOG.autoCommitMode( autocommit );
isolation = ConfigurationHelper.getInteger( Environment.ISOLATION, configurationValues );
isolation = ConfigurationHelper.getInteger( AvailableSettings.ISOLATION, configurationValues );
if (isolation != null) LOG.jdbcIsolationLevel(Environment.isolationLevelToString(isolation.intValue()));
url = (String) configurationValues.get( Environment.URL );
url = (String) configurationValues.get( AvailableSettings.URL );
if ( url == null ) {
String msg = LOG.jdbcUrlNotSpecified(Environment.URL);
String msg = LOG.jdbcUrlNotSpecified(AvailableSettings.URL);
LOG.error(msg);
throw new HibernateException( msg );
}

View File

@ -113,7 +113,7 @@ public class SchemaExport {
this.sqlExceptionHelper = serviceRegistry.getService( JdbcServices.class ).getSqlExceptionHelper();
this.importFiles = ConfigurationHelper.getString(
Environment.HBM2DDL_IMPORT_FILES,
AvailableSettings.HBM2DDL_IMPORT_FILES,
configuration.getProperties(),
DEFAULT_IMPORT_FILE
);
@ -178,7 +178,7 @@ public class SchemaExport {
this.sqlExceptionHelper = new SqlExceptionHelper();
this.importFiles = ConfigurationHelper.getString(
Environment.HBM2DDL_IMPORT_FILES,
AvailableSettings.HBM2DDL_IMPORT_FILES,
properties,
DEFAULT_IMPORT_FILE
);
@ -202,7 +202,7 @@ public class SchemaExport {
this.sqlExceptionHelper = new SqlExceptionHelper();
this.importFiles = ConfigurationHelper.getString(
Environment.HBM2DDL_IMPORT_FILES,
AvailableSettings.HBM2DDL_IMPORT_FILES,
configuration.getProperties(),
DEFAULT_IMPORT_FILE
);
@ -573,7 +573,7 @@ public class SchemaExport {
}
if (importFile != null) {
cfg.setProperty( Environment.HBM2DDL_IMPORT_FILES, importFile );
cfg.setProperty( AvailableSettings.HBM2DDL_IMPORT_FILES, importFile );
}
StandardServiceRegistryImpl serviceRegistry = createServiceRegistry( cfg.getProperties() );

View File

@ -75,7 +75,7 @@ public class AccessTest extends BaseCoreFunctionalTestCase {
tx.commit();
s.close();
}
@Test
public void testPropertyOverriding() throws Exception {
Furniture fur = new Furniture();
fur.weight = 3;
@ -91,7 +91,7 @@ public class AccessTest extends BaseCoreFunctionalTestCase {
tx.commit();
s.close();
}
@Test
public void testNonOverridenSubclass() throws Exception {
Chair chair = new Chair();
chair.setPillow( "Blue" );
@ -107,7 +107,7 @@ public class AccessTest extends BaseCoreFunctionalTestCase {
tx.commit();
s.close();
}
@Test
public void testOverridenSubclass() throws Exception {
BigBed bed = new BigBed();
bed.size = 5;
@ -125,7 +125,7 @@ public class AccessTest extends BaseCoreFunctionalTestCase {
tx.commit();
s.close();
}
@Test
public void testFieldsOverriding() throws Exception {
Gardenshed gs = new Gardenshed();
gs.floors = 4;
@ -142,7 +142,7 @@ public class AccessTest extends BaseCoreFunctionalTestCase {
tx.commit();
s.close();
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {
Bed.class,

View File

@ -1,219 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008-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.annotations.access.jpa;
import org.hibernate.MappingException;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.property.BasicPropertyAccessor;
import org.hibernate.property.DirectPropertyAccessor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tuple.entity.EntityTuplizer;
import junit.framework.TestCase;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.testing.TestForIssue;
/**
* Tests verifying the correct behaviour for the usage of {@code @javax.persistence.Access}.
*
* @author Hardy Ferentschik
*/
@SuppressWarnings( {"deprecation"})
public class AccessMappingTest 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 testInconsistentAnnotationPlacement() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass( Course1.class );
cfg.addAnnotatedClass( Student.class );
try {
cfg.buildSessionFactory( serviceRegistry );
fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." );
}
catch ( MappingException e ) {
// success
}
}
public void testFieldAnnotationPlacement() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Class<?> classUnderTest = Course6.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel()
.getTuplizer();
assertTrue(
"Field access should be used.",
tuplizer.getIdentifierGetter() instanceof DirectPropertyAccessor.DirectGetter
);
}
public void testPropertyAnnotationPlacement() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Class<?> classUnderTest = Course7.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel()
.getTuplizer();
assertTrue(
"Property access should be used.",
tuplizer.getIdentifierGetter() instanceof BasicPropertyAccessor.BasicGetter
);
}
public void testExplicitPropertyAccessAnnotationsOnProperty() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Class<?> classUnderTest = Course2.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel()
.getTuplizer();
assertTrue(
"Property access should be used.",
tuplizer.getIdentifierGetter() instanceof BasicPropertyAccessor.BasicGetter
);
}
public void testExplicitPropertyAccessAnnotationsOnField() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass( Course4.class );
cfg.addAnnotatedClass( Student.class );
try {
cfg.buildSessionFactory( serviceRegistry );
fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." );
}
catch ( MappingException e ) {
// success
}
}
public void testExplicitPropertyAccessAnnotationsWithHibernateStyleOverride() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Class<?> classUnderTest = Course3.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel()
.getTuplizer();
assertTrue(
"Field access should be used.",
tuplizer.getIdentifierGetter() instanceof DirectPropertyAccessor.DirectGetter
);
assertTrue(
"Property access should be used.",
tuplizer.getGetter( 0 ) instanceof BasicPropertyAccessor.BasicGetter
);
}
public void testExplicitPropertyAccessAnnotationsWithJpaStyleOverride() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Class<?> classUnderTest = Course5.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel()
.getTuplizer();
assertTrue(
"Field access should be used.",
tuplizer.getIdentifierGetter() instanceof DirectPropertyAccessor.DirectGetter
);
assertTrue(
"Property access should be used.",
tuplizer.getGetter( 0 ) instanceof BasicPropertyAccessor.BasicGetter
);
}
public void testDefaultFieldAccessIsInherited() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Class<?> classUnderTest = User.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Person.class );
cfg.addAnnotatedClass( Being.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel()
.getTuplizer();
assertTrue(
"Field access should be used since the default access mode gets inherited",
tuplizer.getIdentifierGetter() instanceof DirectPropertyAccessor.DirectGetter
);
}
public void testDefaultPropertyAccessIsInherited() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass( Horse.class );
cfg.addAnnotatedClass( Animal.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityTuplizer tuplizer = factory.getEntityPersister( Animal.class.getName() )
.getEntityMetamodel()
.getTuplizer();
assertTrue(
"Property access should be used since explicity configured via @Access",
tuplizer.getIdentifierGetter() instanceof BasicPropertyAccessor.BasicGetter
);
tuplizer = factory.getEntityPersister( Horse.class.getName() )
.getEntityMetamodel()
.getTuplizer();
assertTrue(
"Field access should be used since the default access mode gets inherited",
tuplizer.getGetter( 0 ) instanceof DirectPropertyAccessor.DirectGetter
);
}
@TestForIssue( jiraKey = "HHH-5004")
public void testAccessOnClassAndId() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass( Course8.class );
cfg.addAnnotatedClass( Student.class );
cfg.buildSessionFactory( serviceRegistry );
}
}

View File

@ -54,11 +54,6 @@ public class ProxyBreakingTest extends BaseCoreFunctionalTestCase {
s.close();
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[0];
}
@Override
protected String[] getXmlFiles() {
return new String[] {

View File

@ -4,9 +4,6 @@ import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Stack;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.hibernate.hql.internal.antlr.HqlTokenTypes;
import org.hibernate.hql.internal.ast.HqlParser;
@ -16,30 +13,26 @@ import org.hibernate.hql.internal.ast.util.ASTPrinter;
import antlr.RecognitionException;
import antlr.TokenStreamException;
import antlr.collections.AST;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Tests the HQL parser on various inputs, just makes sure that the first phase of the parser
* works properly (i.e. no unexpected syntax errors).
* todo this should be a unit test.
*/
public class HqlParserTest extends TestCase {
public class HqlParserTest{
/**
* Standard JUnit test case constructor.
*
* @param name The name of the test case.
*/
public HqlParserTest(String name) {
super( name );
}
public void testUnion() throws Exception {
@Test
public void testUnion() throws Exception {
parse("from Animal a where a in (from Cat union from Dog) ");
}
/**
* Section 9.2 - from *
*/
public void testDocoExamples92() throws Exception {
@Test public void testDocoExamples92() throws Exception {
parse( "from eg.Cat" );
parse( "from eg.Cat as cat" );
parse( "from eg.Cat cat" );
@ -50,7 +43,7 @@ public class HqlParserTest extends TestCase {
/**
* Section 9.3 - Associations and joins *
*/
public void testDocoExamples93() throws Exception {
@Test public void testDocoExamples93() throws Exception {
parse( "from eg.Cat as cat inner join cat.mate as mate left outer join cat.kittens as kitten" );
parse( "from eg.Cat as cat left join cat.mate.kittens as kittens" );
parse( "from Formula form full join form.parameter param" );
@ -61,7 +54,7 @@ public class HqlParserTest extends TestCase {
/**
* Section 9.4 - Select *
*/
public void testDocoExamples94() throws Exception {
@Test public void testDocoExamples94() throws Exception {
parse( "select mate from eg.Cat as cat inner join cat.mate as mate" );
parse( "select cat.mate from eg.Cat cat" );
parse( "select elements(cat.kittens) from eg.Cat cat" );
@ -79,7 +72,7 @@ public class HqlParserTest extends TestCase {
/**
* Section 9.5 - Aggregate functions *
*/
public void testDocoExamples95() throws Exception {
@Test public void testDocoExamples95() throws Exception {
parse( "select avg(cat.weight), sum(cat.weight), max(cat.weight), count(cat)\n"
+ "from eg.Cat cat" );
parse( "select cat, count( elements(cat.kittens) )\n"
@ -91,7 +84,7 @@ public class HqlParserTest extends TestCase {
/**
* Section 9.6 - Polymorphism *
*/
public void testDocoExamples96() throws Exception {
@Test public void testDocoExamples96() throws Exception {
parse( "from eg.Cat as cat" );
parse( "from java.lang.Object o" );
parse( "from eg.Named n, eg.Named m where n.name = m.name" );
@ -100,7 +93,7 @@ public class HqlParserTest extends TestCase {
/**
* Section 9.7 - Where *
*/
public void testDocoExamples97() throws Exception {
@Test public void testDocoExamples97() throws Exception {
parse( "from eg.Cat as cat where cat.name='Fritz'" );
parse( "select foo\n"
+ "from eg.Foo foo, eg.Bar bar\n"
@ -126,7 +119,7 @@ public class HqlParserTest extends TestCase {
/**
* Section 9.8 - Expressions *
*/
public void testDocoExamples98() throws Exception {
@Test public void testDocoExamples98() throws Exception {
parse( "from eg.DomesticCat cat where cat.name between 'A' and 'B'" );
parse( "from eg.DomesticCat cat where cat.name in ( 'Foo', 'Bar', 'Baz' )" );
parse( "from eg.DomesticCat cat where cat.name not between 'A' and 'B'" );
@ -182,12 +175,12 @@ public class HqlParserTest extends TestCase {
}
public void testDocoExamples99() throws Exception {
@Test public void testDocoExamples99() throws Exception {
parse( "from eg.DomesticCat cat\n"
+ "order by cat.name asc, cat.weight desc, cat.birthdate" );
}
public void testDocoExamples910() throws Exception {
@Test public void testDocoExamples910() throws Exception {
parse( "select cat.color, sum(cat.weight), count(cat)\n"
+ "from eg.Cat cat group by cat.color" );
parse( "select foo.id, avg( elements(foo.names) ), max( indices(foo.names) )\n"
@ -200,7 +193,7 @@ public class HqlParserTest extends TestCase {
+ "order by count(kitten) asc, sum(kitten.weight) desc" );
}
public void testDocoExamples911() throws Exception {
@Test public void testDocoExamples911() throws Exception {
parse( "from eg.Cat as fatcat where fatcat.weight > (\n"
+ "select avg(cat.weight) from eg.DomesticCat cat)" );
parse( "from eg.DomesticCat as cat where cat.name = some (\n"
@ -211,7 +204,7 @@ public class HqlParserTest extends TestCase {
+ "select name.nickName from eg.Name as name)" );
}
public void testDocoExamples912() throws Exception {
@Test public void testDocoExamples912() throws Exception {
parse( "select ord.id, sum(price.amount), count(item)\n"
+ "from Order as ord join ord.lineItems as item\n"
+ "join item.product as product, Catalog as catalog\n"
@ -271,7 +264,7 @@ public class HqlParserTest extends TestCase {
+ "order by account.type.sortOrder, account.accountNumber, payment.dueDate" );
}
public void testExamples1() throws Exception {
@Test public void testExamples1() throws Exception {
parse( "select new org.hibernate.test.S(s.count, s.address)\n"
+ "from s in class Simple" );
parse( "select s.name, sysdate, trunc(s.pay), round(s.pay) from s in class Simple" );
@ -280,32 +273,32 @@ public class HqlParserTest extends TestCase {
parse( "select trunc(round(sysdate)) from s in class Simple" );
}
public void testArrayExpr() throws Exception {
@Test public void testArrayExpr() throws Exception {
parse( "from Order ord where ord.items[0].id = 1234" );
}
public void testMultipleActualParameters() throws Exception {
@Test public void testMultipleActualParameters() throws Exception {
parse( "select round(s.pay, 2) from s" );
}
public void testMultipleFromClasses() throws Exception {
@Test public void testMultipleFromClasses() throws Exception {
parse( "FROM eg.mypackage.Cat qat, com.toadstool.Foo f" );
parse( "FROM eg.mypackage.Cat qat, org.jabberwocky.Dipstick" );
}
public void testFromWithJoin() throws Exception {
@Test public void testFromWithJoin() throws Exception {
parse( "FROM eg.mypackage.Cat qat, com.toadstool.Foo f join net.sf.blurb.Blurb" );
parse( "FROM eg.mypackage.Cat qat left join com.multijoin.JoinORama , com.toadstool.Foo f join net.sf.blurb.Blurb" );
}
public void testSelect() throws Exception {
@Test public void testSelect() throws Exception {
parse( "SELECT f FROM eg.mypackage.Cat qat, com.toadstool.Foo f join net.sf.blurb.Blurb" );
parse( "SELECT DISTINCT bar FROM eg.mypackage.Cat qat left join com.multijoin.JoinORama as bar, com.toadstool.Foo f join net.sf.blurb.Blurb" );
parse( "SELECT count(*) FROM eg.mypackage.Cat qat" );
parse( "SELECT avg(qat.weight) FROM eg.mypackage.Cat qat" );
}
public void testWhere() throws Exception {
@Test public void testWhere() throws Exception {
parse( "FROM eg.mypackage.Cat qat where qat.name like '%fluffy%' or qat.toes > 5" );
parse( "FROM eg.mypackage.Cat qat where not qat.name like '%fluffy%' or qat.toes > 5" );
parse( "FROM eg.mypackage.Cat qat where not qat.name not like '%fluffy%'" );
@ -315,33 +308,33 @@ public class HqlParserTest extends TestCase {
parse( "from Animal an where (an.bodyWeight > 10 and an.bodyWeight < 100) or an.bodyWeight is null" );
}
public void testGroupBy() throws Exception {
@Test public void testGroupBy() throws Exception {
parse( "FROM eg.mypackage.Cat qat group by qat.breed" );
parse( "FROM eg.mypackage.Cat qat group by qat.breed, qat.eyecolor" );
}
public void testOrderBy() throws Exception {
@Test public void testOrderBy() throws Exception {
parse( "FROM eg.mypackage.Cat qat order by avg(qat.toes)" );
parse( "from Animal an order by sqrt(an.bodyWeight)/2" );
}
public void testDoubleLiteral() throws Exception {
@Test public void testDoubleLiteral() throws Exception {
parse( "from eg.Cat as tinycat where fatcat.weight < 3.1415" );
parse( "from eg.Cat as enormouscat where fatcat.weight > 3.1415e3" );
}
public void testComplexConstructor() throws Exception {
@Test public void testComplexConstructor() throws Exception {
parse( "select new Foo(count(bar)) from bar" );
parse( "select new Foo(count(bar),(select count(*) from doofus d where d.gob = 'fat' )) from bar" );
}
public void testInNotIn() throws Exception {
@Test public void testInNotIn() throws Exception {
parse( "from foo where foo.bar in ('a' , 'b', 'c')" );
parse( "from foo where foo.bar not in ('a' , 'b', 'c')" );
}
public void testOperatorPrecedence() throws Exception {
@Test public void testOperatorPrecedence() throws Exception {
parse( "from foo where foo.bar = 123 + foo.baz * foo.not" );
parse( "from foo where foo.bar like 'testzzz' || foo.baz or foo.bar in ('duh', 'gob')" );
}
@ -351,7 +344,7 @@ public class HqlParserTest extends TestCase {
*
* @throws Exception if the HQL could not be parsed.
*/
public void testUnitTestHql() throws Exception {
@Test public void testUnitTestHql() throws Exception {
parse( "select foo from foo in class org.hibernate.test.Foo, fee in class org.hibernate.test.Fee where foo.dependent = fee order by foo.string desc, foo.component.count asc, fee.id" );
parse( "select foo.foo, foo.dependent from foo in class org.hibernate.test.Foo order by foo.foo.string desc, foo.component.count asc, foo.dependent.id" );
parse( "select foo from foo in class org.hibernate.test.Foo order by foo.dependent.id, foo.dependent.fi" );
@ -880,26 +873,26 @@ public class HqlParserTest extends TestCase {
parse( "from org.hibernate.test.Componentizable" );
}
public void testUnnamedParameter() throws Exception {
@Test public void testUnnamedParameter() throws Exception {
parse( "select foo, bar from org.hibernate.test.Foo foo left outer join foo.foo bar where foo = ?" ); // Added '?' as a valid expression.
}
public void testInElements() throws Exception {
@Test public void testInElements() throws Exception {
parse( "from bar in class org.hibernate.test.Bar, foo in elements(bar.baz.fooArray)" ); // Added collectionExpr as a valid 'in' clause.
}
public void testDotElements() throws Exception {
@Test public void testDotElements() throws Exception {
parse( "select distinct foo from baz in class org.hibernate.test.Baz, foo in elements(baz.fooArray)" );
parse( "select foo from baz in class org.hibernate.test.Baz, foo in elements(baz.fooSet)" );
parse( "select foo from baz in class org.hibernate.test.Baz, foo in elements(baz.fooArray)" );
parse( "from org.hibernate.test.Baz baz where 'b' in elements(baz.collectionComponent.nested.foos) and 1.0 in elements(baz.collectionComponent.nested.floats)" );
}
public void testSelectAll() throws Exception {
@Test public void testSelectAll() throws Exception {
parse( "select all s, s.other from s in class org.hibernate.test.Simple where s = :s" );
}
public void testNot() throws Exception {
@Test public void testNot() throws Exception {
// Cover NOT optimization in HqlParser
parse( "from eg.Cat cat where not ( cat.kittens.size < 1 )" );
parse( "from eg.Cat cat where not ( cat.kittens.size > 1 )" );
@ -911,7 +904,7 @@ public class HqlParserTest extends TestCase {
parse( "from eg.Cat cat where not not ( not cat.kittens.size <= 1 )" );
}
public void testOtherSyntax() throws Exception {
@Test public void testOtherSyntax() throws Exception {
parse( "select bar from org.hibernate.test.Bar bar order by ((bar.x - :valueX)*(bar.x - :valueX))" );
parse( "from bar in class org.hibernate.test.Bar, foo in elements(bar.baz.fooSet)" );
parse( "from one in class org.hibernate.test.One, many in elements(one.manies) where one.id = 1 and many.id = 1" );
@ -928,25 +921,25 @@ public class HqlParserTest extends TestCase {
// parse("from sm in class org.hibernate.test.SubMulti where exists sm.children.elements");
}
public void testEjbqlExtensions() throws Exception {
@Test public void testEjbqlExtensions() throws Exception {
parse( "select object(a) from Animal a where a.mother member of a.offspring" );
parse( "select object(a) from Animal a where a.mother member a.offspring" ); //no member of
parse( "select object(a) from Animal a where a.offspring is empty" );
}
public void testEmptyFilter() throws Exception {
@Test public void testEmptyFilter() throws Exception {
parseFilter( "" ); // Blank is a legitimate filter.
}
public void testOrderByFilter() throws Exception {
@Test public void testOrderByFilter() throws Exception {
parseFilter( "order by this.id" );
}
public void testRestrictionFilter() throws Exception {
@Test public void testRestrictionFilter() throws Exception {
parseFilter( "where this.name = ?" );
}
public void testNoFrom() throws Exception {
@Test public void testNoFrom() throws Exception {
System.out.println( "***** This test ensures that an error is detected ERROR MESSAGES ARE OKAY! *****" );
HqlParser parser = HqlParser.getInstance( "" );
parser.setFilter( false );
@ -955,11 +948,11 @@ public class HqlParserTest extends TestCase {
System.out.println( "***** END OF ERROR TEST *****" );
}
public void testHB1042() throws Exception {
@Test public void testHB1042() throws Exception {
parse( "select x from fmc_web.pool.Pool x left join x.containers c0 where (upper(x.name) = upper(':') and c0.id = 1)" );
}
public void testKeywordInPath() throws Exception {
@Test public void testKeywordInPath() throws Exception {
// The keyword 'order' used as a property name.
parse( "from Customer c where c.order.status = 'argh'" );
// The keyword 'order' and 'count' used as a property name.
@ -970,7 +963,7 @@ public class HqlParserTest extends TestCase {
parse( "from Letter l where l.case = :case" );
}
public void testPathologicalKeywordAsIdentifier() throws Exception {
@Test public void testPathologicalKeywordAsIdentifier() throws Exception {
// Super evil badness... a legitimate keyword!
parse( "from Order order" );
//parse( "from Order order join order.group" );
@ -984,45 +977,45 @@ public class HqlParserTest extends TestCase {
parse( "from Group as group group by group.by.from" );
}
public void testHHH354() throws Exception {
@Test public void testHHH354() throws Exception {
parse( "from Foo f where f.full = 'yep'");
}
public void testWhereAsIdentifier() throws Exception {
@Test public void testWhereAsIdentifier() throws Exception {
// 'where' as a package name
parse( "from where.Order" );
}
public void testEjbqlKeywordsAsIdentifier() throws Exception {
@Test public void testEjbqlKeywordsAsIdentifier() throws Exception {
parse( "from org.hibernate.test.Bar bar where bar.object.id = ? and bar.object.class = ?" );
}
public void testConstructorIn() throws Exception {
@Test public void testConstructorIn() throws Exception {
parse( "from org.hibernate.test.Bar bar where (b.x, b.y, b.z) in (select foo, bar, baz from org.hibernate.test.Foo)" );
}
public void testMultiByteCharacters() throws Exception {
@Test public void testMultiByteCharacters() throws Exception {
parse ("from User user where user.name like '%nn\u4e2dnn%'");
// Test for HHH-558
parse ("from User user where user.\u432d like '%\u4e2d%'");
parse ("from \u432d \u432d where \u432d.name like '%fred%'");
}
public void testHHH719() throws Exception {
@Test public void testHHH719() throws Exception {
// Some SQLs have function names with package qualifiers.
parse("from Foo f order by com.fooco.SpecialFunction(f.id)");
}
public void testHHH1107() throws Exception {
@Test public void testHHH1107() throws Exception {
parse("from Animal where zoo.address.street = '123 Bogus St.'");
}
public void testHHH1247() throws Exception {
@Test public void testHHH1247() throws Exception {
parse("select distinct user.party from com.itf.iceclaims.domain.party.user.UserImpl user inner join user.party.$RelatedWorkgroups relatedWorkgroups where relatedWorkgroups.workgroup.id = :workgroup and relatedWorkgroups.effectiveTime.start <= :datesnow and relatedWorkgroups.effectiveTime.end > :dateenow ");
}
public void testHHH1780() throws Exception {
@Test public void testHHH1780() throws Exception {
// verifies the tree contains a NOT->EXISTS subtree
class Verifier {
public boolean verify(AST root) {
@ -1062,7 +1055,7 @@ public class HqlParserTest extends TestCase {
}
public void testLineAndColumnNumber() throws Exception {
@Test public void testLineAndColumnNumber() throws Exception {
AST ast = doParse("from Foo f\nwhere f.name = 'fred'",false);
// Find some of the nodes and check line and column values.
ASTIterator iter = new ASTIterator(ast);
@ -1116,7 +1109,5 @@ public class HqlParserTest extends TestCase {
return ast;
}
public static Test suite() {
return new TestSuite( HqlParserTest.class );
}
}

View File

@ -13,7 +13,7 @@ public abstract class AbstractExecutable implements Executable {
private ServiceRegistry serviceRegistry;
private SessionFactory factory;
@Override
public final void prepare() {
Configuration cfg = new Configuration().setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
String[] resources = getResources();
@ -23,7 +23,7 @@ public abstract class AbstractExecutable implements Executable {
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
factory = cfg.buildSessionFactory( serviceRegistry );
}
@Override
public final void complete() {
try {
cleanup();

View File

@ -48,7 +48,7 @@ public abstract class LegacyTestCase extends BaseCoreFunctionalTestCase {
@Before
@SuppressWarnings( {"UnnecessaryUnboxing"})
public void checkAntlrParserSetting() {
useAntlrParser = Boolean.valueOf( extractFromSystem( USE_ANTLR_PARSER_PROP ) ).booleanValue();
useAntlrParser = Boolean.valueOf( extractFromSystem( USE_ANTLR_PARSER_PROP ) );
}
protected static String extractFromSystem(String systemPropertyName) {

View File

@ -38,6 +38,7 @@ import org.hibernate.cfg.ObjectNameNormalizer;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.SessionImpl;
import org.hibernate.jdbc.Work;
import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject;
@ -67,6 +68,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase {
private ServiceRegistry serviceRegistry;
private SessionFactoryImplementor sessionFactory;
private SequenceHiLoGenerator generator;
private SessionImplementor session;
@Before
public void setUp() throws Exception {
@ -108,6 +110,9 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase {
@After
public void tearDown() throws Exception {
if(session != null && !session.isClosed()) {
((Session)session).close();
}
if ( sessionFactory != null ) {
sessionFactory.close();
}
@ -118,12 +123,12 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase {
@Test
public void testHiLoAlgorithm() {
SessionImpl session = (SessionImpl) sessionFactory.openSession();
session.beginTransaction();
session = (SessionImpl) sessionFactory.openSession();
((Session)session).beginTransaction();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// initially sequence should be uninitialized
assertEquals( 0L, extractSequenceValue( session ) );
assertEquals( 0L, extractSequenceValue( ((Session)session) ) );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// historically the hilo generators skipped the initial block of values;
@ -131,30 +136,30 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase {
Long generatedValue = (Long) generator.generate( session, null );
assertEquals( 1L, generatedValue.longValue() );
// which should also perform the first read on the sequence which should set it to its "start with" value (1)
assertEquals( 1L, extractSequenceValue( session ) );
assertEquals( 1L, extractSequenceValue( ((Session)session) ) );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
generatedValue = (Long) generator.generate( session, null );
assertEquals( 2L, generatedValue.longValue() );
assertEquals( 2L, extractSequenceValue( session ) );
assertEquals( 2L, extractSequenceValue( ((Session)session) ) );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
generatedValue = (Long) generator.generate( session, null );
assertEquals( 3L, generatedValue.longValue() );
assertEquals( 3L, extractSequenceValue( session ) );
assertEquals( 3L, extractSequenceValue( ((Session)session) ) );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
generatedValue = (Long) generator.generate( session, null );
assertEquals( 4L, generatedValue.longValue() );
assertEquals( 4L, extractSequenceValue( session ) );
assertEquals( 4L, extractSequenceValue( ((Session)session) ) );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
generatedValue = (Long) generator.generate( session, null );
assertEquals( 5L, generatedValue.longValue() );
assertEquals( 5L, extractSequenceValue( session ) );
assertEquals( 5L, extractSequenceValue( ((Session)session) ) );
session.getTransaction().commit();
session.close();
((Session)session).getTransaction().commit();
((Session)session).close();
}
private long extractSequenceValue(Session session) {

View File

@ -1,11 +1,16 @@
//$Id$
package org.hibernate.test.annotations;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.service.ServiceRegistry;
@ -14,21 +19,21 @@ import org.hibernate.testing.ServiceRegistryBuilder;
/**
* @author Emmanuel Bernard
*/
public class ConfigurationTest extends junit.framework.TestCase {
public class ConfigurationTest {
private ServiceRegistry serviceRegistry;
protected void setUp() {
@Before
public void setUp() {
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
}
protected void tearDown() {
@After
public void tearDown() {
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
}
@Test
public void testDeclarativeMix() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
SessionFactory sf = cfg.buildSessionFactory( serviceRegistry );
@ -43,12 +48,12 @@ public class ConfigurationTest extends junit.framework.TestCase {
s.close();
sf.close();
}
@Test
public void testIgnoringHbm() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
cfg.setProperty( AnnotationConfiguration.ARTEFACT_PROCESSING_ORDER, "class" );
cfg.setProperty( Configuration.ARTEFACT_PROCESSING_ORDER, "class" );
SessionFactory sf = cfg.buildSessionFactory( serviceRegistry );
assertNotNull( sf );
Session s = sf.openSession();
@ -67,9 +72,9 @@ public class ConfigurationTest extends junit.framework.TestCase {
s.close();
sf.close();
}
@Test
public void testPrecedenceHbm() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
cfg.addAnnotatedClass( Boat.class );
@ -92,12 +97,12 @@ public class ConfigurationTest extends junit.framework.TestCase {
s.close();
sf.close();
}
@Test
public void testPrecedenceAnnotation() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
cfg.setProperty( AnnotationConfiguration.ARTEFACT_PROCESSING_ORDER, "class, hbm" );
cfg.setProperty( Configuration.ARTEFACT_PROCESSING_ORDER, "class, hbm" );
cfg.addAnnotatedClass( Boat.class );
SessionFactory sf = cfg.buildSessionFactory( serviceRegistry );
assertNotNull( sf );
@ -117,9 +122,9 @@ public class ConfigurationTest extends junit.framework.TestCase {
s.close();
sf.close();
}
@Test
public void testHbmWithSubclassExtends() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.addClass( Ferry.class );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
@ -135,9 +140,9 @@ public class ConfigurationTest extends junit.framework.TestCase {
s.close();
sf.close();
}
@Test
public void testAnnReferencesHbm() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.addAnnotatedClass( Port.class );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );

View File

@ -1,7 +1,9 @@
//$Id$
package org.hibernate.test.annotations;
import org.junit.Test;
import static org.junit.Assert.*;
import org.hibernate.AnnotationException;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
@ -9,9 +11,10 @@ import org.hibernate.testing.ServiceRegistryBuilder;
/**
* @author Emmanuel Bernard
*/
public class SafeMappingTest extends junit.framework.TestCase {
public class SafeMappingTest {
@Test
public void testDeclarativeMix() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Configuration cfg = new Configuration();
cfg.addAnnotatedClass( IncorrectEntity.class );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
ServiceRegistry serviceRegistry = null;

View File

@ -3,9 +3,12 @@ package org.hibernate.test.annotations;
import java.util.Properties;
import junit.framework.TestCase;
import org.junit.Assert;
import org.junit.Test;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.service.ServiceRegistry;
@ -14,14 +17,12 @@ import org.hibernate.testing.ServiceRegistryBuilder;
/**
* @author Emmanuel Bernard
*/
public class SecuredBindingTest extends TestCase {
public class SecuredBindingTest {
public SecuredBindingTest(String x) {
super( x );
}
@Test
public void testConfigurationMethods() throws Exception {
AnnotationConfiguration ac = new AnnotationConfiguration();
Configuration ac = new Configuration();
Properties p = new Properties();
p.put( Environment.DIALECT, "org.hibernate.dialect.HSQLDialect" );
p.put( "hibernate.connection.driver_class", "org.hsqldb.jdbcDrive" );
@ -41,7 +42,7 @@ public class SecuredBindingTest extends TestCase {
}
catch (Exception ignore) {
}
fail( "Driver property overriding should work" );
Assert.fail( "Driver property overriding should work" );
}
catch (HibernateException he) {
//success

View File

@ -0,0 +1,233 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008-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.annotations.access.jpa;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.MappingException;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.property.BasicPropertyAccessor;
import org.hibernate.property.DirectPropertyAccessor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.testing.TestForIssue;
import org.hibernate.tuple.entity.EntityTuplizer;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* Tests verifying the correct behaviour for the usage of {@code @javax.persistence.Access}.
*
* @author Hardy Ferentschik
*/
@SuppressWarnings({ "deprecation" })
public class AccessMappingTest {
private ServiceRegistry serviceRegistry;
@Before
public void setUp() {
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
}
@After
public void tearDown() {
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
}
@Test
public void testInconsistentAnnotationPlacement() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass( Course1.class );
cfg.addAnnotatedClass( Student.class );
try {
cfg.buildSessionFactory( serviceRegistry );
fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." );
}
catch ( MappingException e ) {
// success
}
}
@Test
public void testFieldAnnotationPlacement() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Class<?> classUnderTest = Course6.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel()
.getTuplizer();
assertTrue(
"Field access should be used.",
tuplizer.getIdentifierGetter() instanceof DirectPropertyAccessor.DirectGetter
);
}
@Test
public void testPropertyAnnotationPlacement() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Class<?> classUnderTest = Course7.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel()
.getTuplizer();
assertTrue(
"Property access should be used.",
tuplizer.getIdentifierGetter() instanceof BasicPropertyAccessor.BasicGetter
);
}
@Test
public void testExplicitPropertyAccessAnnotationsOnProperty() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Class<?> classUnderTest = Course2.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel()
.getTuplizer();
assertTrue(
"Property access should be used.",
tuplizer.getIdentifierGetter() instanceof BasicPropertyAccessor.BasicGetter
);
}
@Test
public void testExplicitPropertyAccessAnnotationsOnField() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass( Course4.class );
cfg.addAnnotatedClass( Student.class );
try {
cfg.buildSessionFactory( serviceRegistry );
fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." );
}
catch ( MappingException e ) {
// success
}
}
@Test
public void testExplicitPropertyAccessAnnotationsWithHibernateStyleOverride() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Class<?> classUnderTest = Course3.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel()
.getTuplizer();
assertTrue(
"Field access should be used.",
tuplizer.getIdentifierGetter() instanceof DirectPropertyAccessor.DirectGetter
);
assertTrue(
"Property access should be used.",
tuplizer.getGetter( 0 ) instanceof BasicPropertyAccessor.BasicGetter
);
}
@Test
public void testExplicitPropertyAccessAnnotationsWithJpaStyleOverride() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Class<?> classUnderTest = Course5.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel()
.getTuplizer();
assertTrue(
"Field access should be used.",
tuplizer.getIdentifierGetter() instanceof DirectPropertyAccessor.DirectGetter
);
assertTrue(
"Property access should be used.",
tuplizer.getGetter( 0 ) instanceof BasicPropertyAccessor.BasicGetter
);
}
@Test
public void testDefaultFieldAccessIsInherited() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
Class<?> classUnderTest = User.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Person.class );
cfg.addAnnotatedClass( Being.class );
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel()
.getTuplizer();
assertTrue(
"Field access should be used since the default access mode gets inherited",
tuplizer.getIdentifierGetter() instanceof DirectPropertyAccessor.DirectGetter
);
}
@Test
public void testDefaultPropertyAccessIsInherited() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass( Horse.class );
cfg.addAnnotatedClass( Animal.class );
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
EntityTuplizer tuplizer = factory.getEntityPersister( Animal.class.getName() )
.getEntityMetamodel()
.getTuplizer();
assertTrue(
"Property access should be used since explicity configured via @Access",
tuplizer.getIdentifierGetter() instanceof BasicPropertyAccessor.BasicGetter
);
tuplizer = factory.getEntityPersister( Horse.class.getName() )
.getEntityMetamodel()
.getTuplizer();
assertTrue(
"Field access should be used since the default access mode gets inherited",
tuplizer.getGetter( 0 ) instanceof DirectPropertyAccessor.DirectGetter
);
}
@TestForIssue(jiraKey = "HHH-5004")
@Test
public void testAccessOnClassAndId() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass( Course8.class );
cfg.addAnnotatedClass( Student.class );
cfg.buildSessionFactory( serviceRegistry );
}
}

View File

@ -7,6 +7,7 @@ import java.io.StringWriter;
import org.jboss.logging.Logger;
import org.hibernate.MappingException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.service.ServiceRegistry;
@ -32,6 +33,7 @@ public class BackquoteTest extends BaseUnitTestCase {
private static final Logger log = Logger.getLogger( BackquoteTest.class );
private ServiceRegistry serviceRegistry;
private SessionFactory sessionFactory;
@Before
public void setUp() {
@ -40,6 +42,7 @@ public class BackquoteTest extends BaseUnitTestCase {
@After
public void tearDown() {
if(sessionFactory !=null) sessionFactory.close();
if (serviceRegistry != null) ServiceRegistryBuilder.destroy(serviceRegistry);
}
@ -50,7 +53,7 @@ public class BackquoteTest extends BaseUnitTestCase {
Configuration config = new Configuration();
config.addAnnotatedClass(Bug.class);
config.addAnnotatedClass(Category.class);
config.buildSessionFactory( serviceRegistry );
sessionFactory = config.buildSessionFactory( serviceRegistry );
}
catch( Exception e ) {
StringWriter writer = new StringWriter();
@ -74,7 +77,7 @@ public class BackquoteTest extends BaseUnitTestCase {
Configuration config = new Configuration();
config.addAnnotatedClass(Printer.class);
config.addAnnotatedClass(PrinterCable.class);
config.buildSessionFactory( serviceRegistry );
sessionFactory = config.buildSessionFactory( serviceRegistry );
fail("expected MappingException to be thrown");
}
//we WANT MappingException to be thrown

View File

@ -2,12 +2,16 @@
package org.hibernate.test.annotations.configuration;
import junit.framework.TestCase;
import org.junit.Assert;
import org.junit.Test;
import org.hibernate.cfg.AnnotationConfiguration;
/**
* @author Emmanuel Bernard
*/
public class ConfigurationTest extends TestCase {
public class ConfigurationTest {
@Test
public void testMixPackageAndResourceOrdering() throws Exception {
try {
AnnotationConfiguration config = new AnnotationConfiguration();
@ -15,7 +19,7 @@ public class ConfigurationTest extends TestCase {
config.addPackage( "org.hibernate.test.annotations.configuration" );
}
catch( Exception e ) {
fail("Processing package first when ORM.xml is used should not fail");
Assert.fail( "Processing package first when ORM.xml is used should not fail" );
}
}
}

View File

@ -1,6 +1,8 @@
//$Id$
package org.hibernate.test.annotations.duplicatedgenerator;
import junit.framework.TestCase;
import org.junit.Assert;
import org.junit.Test;
import org.hibernate.AnnotationException;
import org.hibernate.cfg.AnnotationConfiguration;
@ -12,7 +14,8 @@ import org.hibernate.testing.ServiceRegistryBuilder;
/**
* @author Emmanuel Bernard
*/
public class DuplicateTest extends TestCase {
public class DuplicateTest {
@Test
public void testDuplicateEntityName() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
@ -24,7 +27,7 @@ public class DuplicateTest extends TestCase {
cfg.addResource( "org/hibernate/test/annotations/duplicatedgenerator/orm.xml" );
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
cfg.buildSessionFactory( serviceRegistry );
fail( "Should not be able to map the same entity name twice" );
Assert.fail( "Should not be able to map the same entity name twice" );
}
catch (AnnotationException ae) {
//success

Some files were not shown because too many files have changed in this diff Show More