Skip to content

Commit

Permalink
[trivial] formatted and removed copypasta comments (#6)
Browse files Browse the repository at this point in the history
Co-authored-by: Bernd Eckenfels <[email protected]>
  • Loading branch information
ecki and Bernd Eckenfels authored Oct 18, 2023
1 parent ad1ce16 commit 4ad427f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
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

0 comments on commit 4ad427f

Please sign in to comment.