HHH-6819 Moving CommandExtractorService, MultiLineImportFileTest and SingleLineImportFileTest out of the matrix tests. The tests don't need to run against multiple dbs and the multi line tests are not portable as they are atm.

Also splitting properly source files from resources
This commit is contained in:
Hardy Ferentschik 2011-11-18 16:39:04 +01:00 committed by Strong Liu
parent 2f3c5d8904
commit bcf81aa176
12 changed files with 62 additions and 61 deletions

View File

@ -1,17 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!--
Test for import files.
-->
<hibernate-mapping package="org.hibernate.test.importfile">
<class name="Dog" table="dog">
<id name="id"/>
<many-to-one name="master" column="master_fk"/>
</class>
</hibernate-mapping>

View File

@ -1,18 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!--
Test for import files.
-->
<hibernate-mapping package="org.hibernate.test.importfile">
<class name="Human" table="human">
<id name="id"/>
<property name="firstname" column="fname"/>
<property name="lastname" column="lname"/>
</class>
</hibernate-mapping>

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.importfile; package org.hibernate.test.fileimport;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
@ -37,7 +37,7 @@ import org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor;
public class CommandExtractorServiceTest extends MultiLineImportFileTest { public class CommandExtractorServiceTest extends MultiLineImportFileTest {
@Override @Override
public void configure(Configuration cfg) { public void configure(Configuration cfg) {
cfg.setProperty( Environment.HBM2DDL_IMPORT_FILES, "/multiline-stmt.sql" ); cfg.setProperty( Environment.HBM2DDL_IMPORT_FILES, "/org/hibernate/test/fileimport/multi-line-statements.sql" );
} }
@Override @Override

View File

@ -1,4 +1,4 @@
package org.hibernate.test.importfile; package org.hibernate.test.fileimport;
/** /**

View File

@ -1,4 +1,4 @@
package org.hibernate.test.importfile; package org.hibernate.test.fileimport;
/** /**

View File

@ -21,20 +21,21 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.importfile; package org.hibernate.test.fileimport;
import java.math.BigInteger; import java.math.BigInteger;
import org.junit.Test;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor; import org.hibernate.dialect.H2Dialect;
import org.hibernate.testing.RequiresDialect;
import org.junit.Test;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
@ -43,11 +44,18 @@ import static org.junit.Assert.assertNull;
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/ */
@TestForIssue(jiraKey = "HHH-2403") @TestForIssue(jiraKey = "HHH-2403")
@RequiresDialect(value = H2Dialect.class,
jiraKey = "HHH-6286",
comment = "Only running the tests against H2, because the sql statements in the import file are not generic. " +
"This test should actually not test directly against the db")
public class MultiLineImportFileTest extends BaseCoreFunctionalTestCase { public class MultiLineImportFileTest extends BaseCoreFunctionalTestCase {
@Override @Override
public void configure(Configuration cfg) { public void configure(Configuration cfg) {
cfg.setProperty( Environment.HBM2DDL_IMPORT_FILES, "/multiline-stmt.sql" ); cfg.setProperty( Environment.HBM2DDL_IMPORT_FILES, "/org/hibernate/test/fileimport/multi-line-statements.sql" );
cfg.setProperty( Environment.HBM2DDL_IMPORT_FILES_SQL_EXTRACTOR, MultipleLinesSqlCommandExtractor.class.getName() ); cfg.setProperty(
Environment.HBM2DDL_IMPORT_FILES_SQL_EXTRACTOR,
MultipleLinesSqlCommandExtractor.class.getName()
);
} }
@Override @Override
@ -61,12 +69,13 @@ public class MultiLineImportFileTest extends BaseCoreFunctionalTestCase {
final Transaction tx = s.beginTransaction(); final Transaction tx = s.beginTransaction();
BigInteger count = (BigInteger) s.createSQLQuery( "SELECT COUNT(*) FROM test_data" ).uniqueResult(); BigInteger count = (BigInteger) s.createSQLQuery( "SELECT COUNT(*) FROM test_data" ).uniqueResult();
assertEquals( "incorrect row number", 3L, count.longValue() ); assertEquals( "Incorrect row number", 3L, count.longValue() );
final String multilineText = (String) s.createSQLQuery( "SELECT text FROM test_data WHERE id = 2" ).uniqueResult(); final String multiLineText = (String) s.createSQLQuery( "SELECT text FROM test_data WHERE id = 2" )
// "Multiline comment line 1\r\n-- line 2'\r\n/* line 3 */" .uniqueResult();
final String expected = String.format( "Multiline comment line 1%n-- line 2'%n/* line 3 */" ); // "Multi-line comment line 1\r\n-- line 2'\r\n/* line 3 */"
assertEquals( "multiline string inserted incorrectly", expected, multilineText ); final String expected = String.format( "Multi-line comment line 1%n-- line 2'%n/* line 3 */" );
assertEquals( "Multi-line string inserted incorrectly", expected, multiLineText );
String empty = (String) s.createSQLQuery( "SELECT text FROM test_data WHERE id = 3" ).uniqueResult(); String empty = (String) s.createSQLQuery( "SELECT text FROM test_data WHERE id = 3" ).uniqueResult();
assertNull( "NULL value inserted incorrectly", empty ); assertNull( "NULL value inserted incorrectly", empty );

View File

@ -21,7 +21,8 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.importfile; package org.hibernate.test.fileimport;
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.Test;
@ -40,14 +41,17 @@ import static org.junit.Assert.assertEquals;
public class SingleLineImportFileTest extends BaseCoreFunctionalTestCase { public class SingleLineImportFileTest extends BaseCoreFunctionalTestCase {
@Override @Override
public void configure(Configuration cfg) { public void configure(Configuration cfg) {
cfg.setProperty( Environment.HBM2DDL_IMPORT_FILES, "/humans.sql,/dogs.sql" ); cfg.setProperty(
Environment.HBM2DDL_IMPORT_FILES,
"/org/hibernate/test/fileimport/humans.sql,/org/hibernate/test/fileimport/dogs.sql"
);
} }
@Override @Override
public String[] getMappings() { public String[] getMappings() {
return new String[] { return new String[] {
"importfile/Human.hbm.xml", "fileimport/Human.hbm.xml",
"importfile/Dog.hbm.xml" "fileimport/Dog.hbm.xml"
}; };
} }

View File

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.fileimport">
<class name="Dog" table="dog">
<id name="id"/>
<many-to-one name="master" column="master_fk"/>
</class>
</hibernate-mapping>

View File

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.fileimport">
<class name="Human" table="human">
<id name="id"/>
<property name="firstname" column="fname"/>
<property name="lastname" column="lname"/>
</class>
</hibernate-mapping>

View File

@ -14,7 +14,7 @@ DELETE
/* /*
* Data insertion... * Data insertion...
*/ */
INSERT INTO test_data VALUES (2, 'Multiline comment line 1 INSERT INTO test_data VALUES (2, 'Multi-line comment line 1
-- line 2'' -- line 2''
/* line 3 */'); /* line 3 */');