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:
parent
2f3c5d8904
commit
bcf81aa176
|
@ -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>
|
|
@ -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>
|
|
@ -21,7 +21,7 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.importfile;
|
||||
package org.hibernate.test.fileimport;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
@ -37,7 +37,7 @@ import org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor;
|
|||
public class CommandExtractorServiceTest extends MultiLineImportFileTest {
|
||||
@Override
|
||||
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
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.test.importfile;
|
||||
package org.hibernate.test.fileimport;
|
||||
|
||||
|
||||
/**
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.test.importfile;
|
||||
package org.hibernate.test.fileimport;
|
||||
|
||||
|
||||
/**
|
|
@ -21,20 +21,21 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.importfile;
|
||||
package org.hibernate.test.fileimport;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
@ -42,16 +43,23 @@ import static org.junit.Assert.assertNull;
|
|||
/**
|
||||
* @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 {
|
||||
@Override
|
||||
public void configure(Configuration cfg) {
|
||||
cfg.setProperty( Environment.HBM2DDL_IMPORT_FILES, "/multiline-stmt.sql" );
|
||||
cfg.setProperty( Environment.HBM2DDL_IMPORT_FILES_SQL_EXTRACTOR, MultipleLinesSqlCommandExtractor.class.getName() );
|
||||
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()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
public String[] getMappings() {
|
||||
return NO_MAPPINGS;
|
||||
}
|
||||
|
||||
|
@ -61,12 +69,13 @@ public class MultiLineImportFileTest extends BaseCoreFunctionalTestCase {
|
|||
final Transaction tx = s.beginTransaction();
|
||||
|
||||
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();
|
||||
// "Multiline comment line 1\r\n-- line 2'\r\n/* line 3 */"
|
||||
final String expected = String.format( "Multiline comment line 1%n-- line 2'%n/* line 3 */" );
|
||||
assertEquals( "multiline string inserted incorrectly", expected, multilineText );
|
||||
final String multiLineText = (String) s.createSQLQuery( "SELECT text FROM test_data WHERE id = 2" )
|
||||
.uniqueResult();
|
||||
// "Multi-line comment line 1\r\n-- line 2'\r\n/* line 3 */"
|
||||
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();
|
||||
assertNull( "NULL value inserted incorrectly", empty );
|
|
@ -21,7 +21,8 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.importfile;
|
||||
package org.hibernate.test.fileimport;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -40,30 +41,33 @@ import static org.junit.Assert.assertEquals;
|
|||
public class SingleLineImportFileTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
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
|
||||
public String[] getMappings() {
|
||||
return new String[] {
|
||||
"importfile/Human.hbm.xml",
|
||||
"importfile/Dog.hbm.xml"
|
||||
"fileimport/Human.hbm.xml",
|
||||
"fileimport/Dog.hbm.xml"
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportFile() throws Exception {
|
||||
Session s = openSession( );
|
||||
Session s = openSession();
|
||||
final Transaction tx = s.beginTransaction();
|
||||
final List<?> humans = s.createQuery( "from " + Human.class.getName() ).list();
|
||||
assertEquals( "humans.sql not imported", 3, humans.size() );
|
||||
|
||||
final List<?> dogs = s.createQuery( "from " + Dog.class.getName() ).list();
|
||||
assertEquals( "dogs.sql not imported", 3, dogs.size() );
|
||||
for (Object entity : dogs) {
|
||||
for ( Object entity : dogs ) {
|
||||
s.delete( entity );
|
||||
}
|
||||
for (Object entity : humans) {
|
||||
for ( Object entity : humans ) {
|
||||
s.delete( entity );
|
||||
}
|
||||
tx.commit();
|
|
@ -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>
|
|
@ -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>
|
|
@ -14,7 +14,7 @@ DELETE
|
|||
/*
|
||||
* 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 3 */');
|
||||
|
Loading…
Reference in New Issue