From 4ad427ff8e369f584dfbb3b8579596c0be3ec741 Mon Sep 17 00:00:00 2001 From: Bernd Date: Wed, 18 Oct 2023 17:23:55 +0200 Subject: [PATCH] [trivial] formatted and removed copypasta comments (#6) Co-authored-by: Bernd Eckenfels --- .../bis6resources/tests/MSSQLServerTests.java | 54 +++++++++++-------- .../bis6resources/tests/OracleTests.java | 5 -- .../bis6resources/tests/PostgresTests.java | 3 +- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/tests/src/test/java/com/seeburger/bis6resources/tests/MSSQLServerTests.java b/tests/src/test/java/com/seeburger/bis6resources/tests/MSSQLServerTests.java index abcd109..d10029e 100644 --- a/tests/src/test/java/com/seeburger/bis6resources/tests/MSSQLServerTests.java +++ b/tests/src/test/java/com/seeburger/bis6resources/tests/MSSQLServerTests.java @@ -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"; @@ -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 @@ -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; @@ -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"); @@ -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); } @@ -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", diff --git a/tests/src/test/java/com/seeburger/bis6resources/tests/OracleTests.java b/tests/src/test/java/com/seeburger/bis6resources/tests/OracleTests.java index e6fc9a7..21ca5fe 100644 --- a/tests/src/test/java/com/seeburger/bis6resources/tests/OracleTests.java +++ b/tests/src/test/java/com/seeburger/bis6resources/tests/OracleTests.java @@ -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"); @@ -183,6 +181,3 @@ private void executeScript(String login, String file) throws UnsupportedOperatio //System.out.println(">> result " + result); } } - - - diff --git a/tests/src/test/java/com/seeburger/bis6resources/tests/PostgresTests.java b/tests/src/test/java/com/seeburger/bis6resources/tests/PostgresTests.java index 7a75d54..234b2ea 100644 --- a/tests/src/test/java/com/seeburger/bis6resources/tests/PostgresTests.java +++ b/tests/src/test/java/com/seeburger/bis6resources/tests/PostgresTests.java @@ -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'"); @@ -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 */} } }