From 79e6ffe4834b21b061576d676b5aaec463af06f4 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Tue, 6 Oct 2020 16:42:23 +0100 Subject: [PATCH] HHH-14249 Add test for issue --- ...rtWithSpacesAfterTheLastStatementTest.java | 43 +++++++++++++++++++ .../MultiLineImportWithTabsAndSpacesTest.java | 43 +++++++++++++++++++ ...ments-with-spaces-after-last-delimiter.sql | 7 +++ ...atements-starting-with-tabs-and-spaces.sql | 8 ++++ 4 files changed, 101 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/fileimport/MultiLineImportWithSpacesAfterTheLastStatementTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/fileimport/MultiLineImportWithTabsAndSpacesTest.java create mode 100644 hibernate-core/src/test/resources/org/hibernate/test/fileimport/mulit-line-statements-with-spaces-after-last-delimiter.sql create mode 100644 hibernate-core/src/test/resources/org/hibernate/test/fileimport/multi-line-statements-starting-with-tabs-and-spaces.sql diff --git a/hibernate-core/src/test/java/org/hibernate/test/fileimport/MultiLineImportWithSpacesAfterTheLastStatementTest.java b/hibernate-core/src/test/java/org/hibernate/test/fileimport/MultiLineImportWithSpacesAfterTheLastStatementTest.java new file mode 100644 index 0000000000..c8fc9ec090 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/fileimport/MultiLineImportWithSpacesAfterTheLastStatementTest.java @@ -0,0 +1,43 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.fileimport; + +import java.io.InputStream; +import java.io.InputStreamReader; + +import org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor; + +import org.hibernate.testing.TestForIssue; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * @author Andrea Boriero + */ +@TestForIssue(jiraKey = "HHH-14249") +public class MultiLineImportWithSpacesAfterTheLastStatementTest { + public static final String IMPORT_FILE = "org/hibernate/test/fileimport/multi-line-statements-with-spaces-after-last-delimiter.sql"; + + private final MultipleLinesSqlCommandExtractor extractor = new MultipleLinesSqlCommandExtractor(); + + @Test + public void testExtraction() throws Exception { + final ClassLoader classLoader = ClassLoader.getSystemClassLoader(); + + try (final InputStream stream = classLoader.getResourceAsStream( IMPORT_FILE )) { + assertThat( stream, notNullValue() ); + try (final InputStreamReader reader = new InputStreamReader( stream )) { + final String[] commands = extractor.extractCommands( reader ); + assertThat( commands, notNullValue() ); + assertThat( commands.length, is( 3 ) ); + } + } + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/fileimport/MultiLineImportWithTabsAndSpacesTest.java b/hibernate-core/src/test/java/org/hibernate/test/fileimport/MultiLineImportWithTabsAndSpacesTest.java new file mode 100644 index 0000000000..3b1f7a9a8d --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/fileimport/MultiLineImportWithTabsAndSpacesTest.java @@ -0,0 +1,43 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.fileimport; + +import java.io.InputStream; +import java.io.InputStreamReader; + +import org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor; + +import org.hibernate.testing.TestForIssue; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * @author Andrea Boriero + */ +@TestForIssue(jiraKey = "HHH-14249") +public class MultiLineImportWithTabsAndSpacesTest { + public static final String IMPORT_FILE = "org/hibernate/test/fileimport/multi-line-statements-starting-with-tabs-and-spaces.sql"; + + private final MultipleLinesSqlCommandExtractor extractor = new MultipleLinesSqlCommandExtractor(); + + @Test + public void testExtraction() throws Exception { + final ClassLoader classLoader = ClassLoader.getSystemClassLoader(); + + try (final InputStream stream = classLoader.getResourceAsStream( IMPORT_FILE )) { + assertThat( stream, notNullValue() ); + try (final InputStreamReader reader = new InputStreamReader( stream )) { + final String[] commands = extractor.extractCommands( reader ); + assertThat( commands, notNullValue() ); + assertThat( commands.length, is( 3 ) ); + } + } + } +} diff --git a/hibernate-core/src/test/resources/org/hibernate/test/fileimport/mulit-line-statements-with-spaces-after-last-delimiter.sql b/hibernate-core/src/test/resources/org/hibernate/test/fileimport/mulit-line-statements-with-spaces-after-last-delimiter.sql new file mode 100644 index 0000000000..89efab8b04 --- /dev/null +++ b/hibernate-core/src/test/resources/org/hibernate/test/fileimport/mulit-line-statements-with-spaces-after-last-delimiter.sql @@ -0,0 +1,7 @@ + CREATE TABLE test_data ( + id NUMBER NOT NULL PRIMARY KEY -- primary key +, text VARCHAR2(100) /* any other data */ +); DELETE + FROM test_data; + +INSERT INTO test_data VALUES (1, 'sample'); \ No newline at end of file diff --git a/hibernate-core/src/test/resources/org/hibernate/test/fileimport/multi-line-statements-starting-with-tabs-and-spaces.sql b/hibernate-core/src/test/resources/org/hibernate/test/fileimport/multi-line-statements-starting-with-tabs-and-spaces.sql new file mode 100644 index 0000000000..2fb325f658 --- /dev/null +++ b/hibernate-core/src/test/resources/org/hibernate/test/fileimport/multi-line-statements-starting-with-tabs-and-spaces.sql @@ -0,0 +1,8 @@ + + CREATE TABLE test_data ( + id NUMBER NOT NULL PRIMARY KEY -- primary key +, text VARCHAR2(100) /* any other data */ + ); DELETE + FROM test_data; + +INSERT INTO test_data VALUES (1, 'sample');