Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions modules/database-commons/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@ description = "Testcontainers :: Database-Commons"
dependencies {
api project(':testcontainers')

testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'

testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
testImplementation 'org.assertj:assertj-core:3.27.4'
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package org.testcontainers.ext;

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.regex.Pattern;

import static org.assertj.core.api.Assertions.assertThat;

public class ScriptScannerTest {
class ScriptScannerTest {

@Test
public void testHugeStringLiteral() {
void testHugeStringLiteral() {
String script = "/* a comment */ \"" + StringUtils.repeat('~', 10000) + "\";";
ScriptScanner scanner = scanner(script);
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.COMMENT);
Expand All @@ -20,7 +20,7 @@ public void testHugeStringLiteral() {
}

@Test
public void testPgIdentifierWithDollarSigns() {
void testPgIdentifierWithDollarSigns() {
ScriptScanner scanner = scanner(
"this$is$a$valid$postgreSQL$identifier " +
"$a$While this is a quoted string$a$$ --just followed by a dollar sign"
Expand All @@ -32,7 +32,7 @@ public void testPgIdentifierWithDollarSigns() {
}

@Test
public void testQuotedLiterals() {
void testQuotedLiterals() {
ScriptScanner scanner = scanner("'this \\'is a literal' \"this \\\" is a literal\"");
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.QUOTED_STRING);
assertThat(scanner.getCurrentMatch()).isEqualTo("'this \\'is a literal'");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.testcontainers.ext;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -10,10 +10,10 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class ScriptSplittingTest {
class ScriptSplittingTest {

@Test
public void testStringDemarcation() {
void testStringDemarcation() {
String script = "SELECT 'foo `bar`'; SELECT 'foo -- `bar`'; SELECT 'foo /* `bar`';";

List<String> expected = Arrays.asList("SELECT 'foo `bar`'", "SELECT 'foo -- `bar`'", "SELECT 'foo /* `bar`'");
Expand All @@ -22,7 +22,7 @@ public void testStringDemarcation() {
}

@Test
public void testIssue1547Case1() {
void testIssue1547Case1() {
String script =
"create database if not exists ttt;\n" +
"\n" +
Expand Down Expand Up @@ -51,7 +51,7 @@ public void testIssue1547Case1() {
}

@Test
public void testIssue1547Case2() {
void testIssue1547Case2() {
String script =
"CREATE TABLE bar (\n" +
" end_time VARCHAR(255)\n" +
Expand All @@ -69,7 +69,7 @@ public void testIssue1547Case2() {
}

@Test
public void testSplittingEnquotedSemicolon() {
void testSplittingEnquotedSemicolon() {
String script = "CREATE TABLE `bar;bar` (\n" + " end_time VARCHAR(255)\n" + ");";

List<String> expected = Arrays.asList("CREATE TABLE `bar;bar` ( end_time VARCHAR(255) )");
Expand All @@ -78,7 +78,7 @@ public void testSplittingEnquotedSemicolon() {
}

@Test
public void testUnusualSemicolonPlacement() {
void testUnusualSemicolonPlacement() {
String script = "SELECT 1;;;;;SELECT 2;\n;SELECT 3\n; SELECT 4;\n SELECT 5";

List<String> expected = Arrays.asList("SELECT 1", "SELECT 2", "SELECT 3", "SELECT 4", "SELECT 5");
Expand All @@ -87,7 +87,7 @@ public void testUnusualSemicolonPlacement() {
}

@Test
public void testCommentedSemicolon() {
void testCommentedSemicolon() {
String script =
"CREATE TABLE bar (\n" + " foo VARCHAR(255)\n" + "); \nDROP PROCEDURE IF EXISTS -- ;\n" + " count_foo";

Expand All @@ -100,7 +100,7 @@ public void testCommentedSemicolon() {
}

@Test
public void testStringEscaping() {
void testStringEscaping() {
String script =
"SELECT \"a /* string literal containing comment characters like -- here\";\n" +
"SELECT \"a 'quoting' \\\"scenario ` involving BEGIN keyword\\\" here\";\n" +
Expand All @@ -116,7 +116,7 @@ public void testStringEscaping() {
}

@Test
public void testBlockCommentExclusion() {
void testBlockCommentExclusion() {
String script = "INSERT INTO bar (foo) /* ; */ VALUES ('hello world');";

List<String> expected = Arrays.asList("INSERT INTO bar (foo) VALUES ('hello world')");
Expand All @@ -125,7 +125,7 @@ public void testBlockCommentExclusion() {
}

@Test
public void testBeginEndKeywordCorrectDetection() {
void testBeginEndKeywordCorrectDetection() {
String script =
"INSERT INTO something_end (begin_with_the_token, another_field) /*end*/ VALUES /* end */ (' begin ', `end`)-- begin\n;";

Expand All @@ -137,7 +137,7 @@ public void testBeginEndKeywordCorrectDetection() {
}

@Test
public void testCommentInStrings() {
void testCommentInStrings() {
String script =
"CREATE TABLE bar (foo VARCHAR(255));\n" +
"\n" +
Expand All @@ -161,7 +161,7 @@ public void testCommentInStrings() {
}

@Test
public void testMultipleBeginEndDetection() {
void testMultipleBeginEndDetection() {
String script =
"CREATE TABLE bar (foo VARCHAR(255));\n" +
"\n" +
Expand Down Expand Up @@ -205,7 +205,7 @@ public void testMultipleBeginEndDetection() {
}

@Test
public void testProcedureBlock() {
void testProcedureBlock() {
String script =
"CREATE PROCEDURE count_foo()\n" +
" BEGIN\n" +
Expand Down Expand Up @@ -264,15 +264,15 @@ public void testProcedureBlock() {
}

@Test
public void testUnclosedBlockComment() {
void testUnclosedBlockComment() {
String script = "SELECT 'foo `bar`'; /*";
assertThatThrownBy(() -> doSplit(script, ScriptUtils.DEFAULT_STATEMENT_SEPARATOR))
.isInstanceOf(ScriptUtils.ScriptParseException.class)
.hasMessageContaining("*/");
}

@Test
public void testIssue1452Case() {
void testIssue1452Case() {
String script =
"create table test (text VARCHAR(255));\n" +
"\n" +
Expand All @@ -288,7 +288,7 @@ public void testIssue1452Case() {
}

@Test
public void testIfLoopBlocks() {
void testIfLoopBlocks() {
String script =
"BEGIN\n" +
" rec_loop: LOOP\n" +
Expand All @@ -310,7 +310,7 @@ public void testIfLoopBlocks() {
}

@Test
public void testIfLoopBlocksSpecificSeparator() {
void testIfLoopBlocksSpecificSeparator() {
String script =
"BEGIN\n" +
" rec_loop: LOOP\n" +
Expand All @@ -336,14 +336,14 @@ public void testIfLoopBlocksSpecificSeparator() {
}

@Test
public void oracleStyleBlocks() {
void oracleStyleBlocks() {
String script = "BEGIN END; /\n" + "BEGIN END;";
List<String> expected = Arrays.asList("BEGIN END;", "BEGIN END;");
splitAndCompare(script, expected, "/");
}

@Test
public void testMultiProcedureMySQLScript() {
void testMultiProcedureMySQLScript() {
String script =
"CREATE PROCEDURE doiterate(p1 INT)\n" +
" BEGIN\n" +
Expand Down Expand Up @@ -398,7 +398,7 @@ public void testMultiProcedureMySQLScript() {
}

@Test
public void testDollarQuotedStrings() {
void testDollarQuotedStrings() {
String script =
"CREATE FUNCTION f ()\n" +
"RETURNS INT\n" +
Expand All @@ -418,7 +418,7 @@ public void testDollarQuotedStrings() {
}

@Test
public void testNestedDollarQuotedString() {
void testNestedDollarQuotedString() {
//see https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-DOLLAR-QUOTING
String script =
"CREATE FUNCTION f() AS $function$\n" +
Expand All @@ -439,7 +439,7 @@ public void testNestedDollarQuotedString() {
}

@Test
public void testUnclosedDollarQuotedString() {
void testUnclosedDollarQuotedString() {
String script = "SELECT $tag$ ..... $";
assertThatThrownBy(() -> doSplit(script, ScriptUtils.DEFAULT_STATEMENT_SEPARATOR))
.isInstanceOf(ScriptUtils.ScriptParseException.class)
Expand Down Expand Up @@ -470,12 +470,12 @@ private List<String> doSplit(String script, String separator) {
}

@Test
public void testIgnoreDelimitersInLiteralsAndComments() {
void testIgnoreDelimitersInLiteralsAndComments() {
assertThat(ScriptUtils.containsSqlScriptDelimiters("'@' /*@*/ \"@\" $tag$@$tag$ --@", "@")).isFalse();
}

@Test
public void testContainsDelimiters() {
void testContainsDelimiters() {
assertThat(ScriptUtils.containsSqlScriptDelimiters("'@' /*@*/ @ \"@\" --@", "@")).isTrue();
}
}
Loading