Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[trivial] formatted and removed copypasta comments #6

Merged
merged 1 commit into from
Oct 18, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
* This test will use MS SQL Server Database in Testcontainer to apply the
* sample scripts and validate that they are in effect.
*/
class MSSQLServerTests {
class MSSQLServerTests
{
private static final String OWNPASS = "Secret12345";
private static final String RUNPASS = "Secret1234";

Expand All @@ -46,7 +47,8 @@ class MSSQLServerTests {

@BeforeAll
static void setUpBeforeClass()
throws Exception {
throws Exception
{
System.out.println("Starting container...");

// we do this here to not hide the fail reason in Initializer Exception
Expand All @@ -59,8 +61,10 @@ static void setUpBeforeClass()

@AfterAll
static void afterClass()
throws Exception {
if (dbContainer != null) {
throws Exception
{
if (dbContainer != null)
{
var tmp = dbContainer;
dbContainer = null;

Expand All @@ -71,21 +75,21 @@ static void afterClass()
}

@Test
void testCreateDatabase() throws UnsupportedOperationException, IOException, InterruptedException, SQLException {
// we need to run in PDB and not use OMF, also can use smaller files
void testCreateDatabase() throws UnsupportedOperationException, IOException, InterruptedException, SQLException
{
adjustAndTransferFile("create-database.sql",
"ownpass secret", "ownpass " + OWNPASS,
// configure file location
"-- :setvar dir \"C:\\Program Files\\Microsoft SQL Server\\MSSQL15.PROD\\MSSQL\\DATA\\\"", ":setvar dir \"/var/opt/mssql/data/\"",
// these particular warnings should not trigger assert
"WARNING: Edition", "W: Edition",
// unify end message for assert
"Finished create-database.", "Finished.");
"ownpass secret", "ownpass " + OWNPASS,
// configure file location
"-- :setvar dir \"C:\\Program Files\\Microsoft SQL Server\\MSSQL15.PROD\\MSSQL\\DATA\\\"", ":setvar dir \"/var/opt/mssql/data/\"",
// these particular warnings should not trigger assert
"WARNING: Edition", "W: Edition",
// unify end message for assert
"Finished create-database.", "Finished.");

adjustAndTransferFile("create-user.sql",
"runpass secret", "runpass " + RUNPASS,
// unify end message for assert
"Finished create-user.", "Finished.");
"runpass secret", "runpass " + RUNPASS,
// unify end message for assert
"Finished create-user.", "Finished.");

var sa = "-U"+dbContainer.getUsername()+" -P"+dbContainer.getPassword();
executeScript(sa, "create-database.sql");
Expand All @@ -96,22 +100,25 @@ void testCreateDatabase() throws UnsupportedOperationException, IOException, Int

// test db owner can login and create a table
try (Connection c = DriverManager.getConnection(url, "seeasdb0", OWNPASS);
Statement s = c.createStatement();) {
Statement s = c.createStatement();)
{
s.executeUpdate("CREATE TABLE tTest(cTest VARCHAR(256))");
}

// test runtimew user can login and select the new table
try (Connection c = DriverManager.getConnection(url, "seerun0", RUNPASS);
Statement s = c.createStatement();) {
Statement s = c.createStatement();)
{
// this also validated the search path finds the table
try (var r = s.executeQuery("SELECT cTest from tTest");) {
}
try (var r = s.executeQuery("SELECT cTest from tTest");) { /* empty */}
}
}

/** Copy the file(s) from base directory to container /tmp. */
private void transferFiles(String... files) {
for (String f : files) {
private void transferFiles(String... files)
{
for (String f : files)
{
MountableFile mf = MountableFile.forHostPath(BASE + f);
dbContainer.copyFileToContainer(mf, "/tmp/" + f);
}
Expand Down Expand Up @@ -152,7 +159,8 @@ private void adjustAndTransferFile(String file, String... replacements) throws I
* @param file sql file name in /tmp directory in container
*/
private void executeScript(String login, String file)
throws UnsupportedOperationException, IOException, InterruptedException {
throws UnsupportedOperationException, IOException, InterruptedException
{
System.out.println("Executing " + file + " as " + login);

ExecResult r = dbContainer.execInContainer("bash", "-ce",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ void testCreateDatabase() throws UnsupportedOperationException, IOException, Int
adjustAndTransferFile("create-user.sql",
"-- ALTER SESSION SET CONTAINER=\"PDBSEEBIS\";", "ALTER SESSION SET CONTAINER=\"FREEPDB1\";");

//transferFiles("grant-runtime-user.sql");

executeScript("/ AS SYSDBA", "create-tbs.sql");
executeScript("/ AS SYSDBA", "create-roles.sql");
executeScript("/ AS SYSDBA", "create-schema.sql");
Expand Down Expand Up @@ -183,6 +181,3 @@ private void executeScript(String login, String file) throws UnsupportedOperatio
//System.out.println(">> result " + result);
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ static void afterClass()
@Test
void testCreateDatabase() throws UnsupportedOperationException, IOException, InterruptedException, SQLException
{
// we need to run in PDB and not use OMF, also can use smaller files
adjustAndTransferFile("seetst-ddl.sql",
"\\prompt 'Enter new owner - user password: ' owner_pass", "\\set owner_pass 'secret'",
"\\prompt 'Enter new runtime-user password: ' runtime_pass", "\\set runtime_pass 'secret'");
Expand All @@ -96,7 +95,7 @@ void testCreateDatabase() throws UnsupportedOperationException, IOException, Int
Statement s = c.createStatement(); )
{
// this also validated the search path finds the table
try(var r = s.executeQuery("SELECT cTest from tTest");) { }
try(var r = s.executeQuery("SELECT cTest from tTest");) { /* empty */}
}
}

Expand Down