diff --git a/bundles/org.dbvr.cli/src/org/dbvr/cli/app/CLIApplicationBase.java b/bundles/org.dbvr.cli/src/org/dbvr/cli/app/CLIApplicationBase.java index cb51e03..6b974c6 100644 --- a/bundles/org.dbvr.cli/src/org/dbvr/cli/app/CLIApplicationBase.java +++ b/bundles/org.dbvr.cli/src/org/dbvr/cli/app/CLIApplicationBase.java @@ -51,7 +51,7 @@ public class CLIApplicationBase extends BaseApplicationImpl { private static final Log log = Log.getLog(CLIApplicationBase.class); protected Path workspaceDirCurrent; - private boolean started = false; + private volatile boolean started = false; private static final String[] DEFAULT_ARGS = new String[] {AbstractTopLevelCommand.HELP_OPTION}; private DBPPreferenceStore preferenceStore; diff --git a/product/community-unittest/dbvr-unittest.product b/product/community-unittest/dbvr-unittest.product index 7fbefbd..e3f1c1d 100644 --- a/product/community-unittest/dbvr-unittest.product +++ b/product/community-unittest/dbvr-unittest.product @@ -59,6 +59,7 @@ + diff --git a/test/org.dbvr.test.platform/src/org/dbvr/test/AuthModelsTest.java b/test/org.dbvr.test.platform/src/org/dbvr/test/AuthModelsTest.java index 2e59930..27bc9ec 100644 --- a/test/org.dbvr.test.platform/src/org/dbvr/test/AuthModelsTest.java +++ b/test/org.dbvr.test.platform/src/org/dbvr/test/AuthModelsTest.java @@ -23,8 +23,8 @@ import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration; import org.jkiss.dbeaver.model.connection.DBPDriver; import org.jkiss.dbeaver.runtime.DBWorkbench; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.UUID; @@ -41,8 +41,8 @@ public void testListAllAuthModels() throws Exception { var cmd = DBVRTestSuite.getApplication().createCommandLine(); CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); - Assert.assertNotNull(result.getOutput()); - Assert.assertFalse(result.getOutput().isEmpty()); + Assertions.assertNotNull(result.getOutput()); + Assertions.assertFalse(result.getOutput().isEmpty()); } @Test @@ -56,12 +56,12 @@ public void testFilterByDriver() throws Exception { var cmd = DBVRTestSuite.getApplication().createCommandLine(); CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); - Assert.assertNotNull(result.getOutput()); - Assert.assertFalse(result.getOutput().isEmpty()); + Assertions.assertNotNull(result.getOutput()); + Assertions.assertFalse(result.getOutput().isEmpty()); String output = result.getOutput().getFirst(); - Assert.assertTrue(output.contains("Applicable Drivers: H2 Embedded")); - Assert.assertTrue(output.contains("Auth Model ID: native")); + Assertions.assertTrue(output.contains("Applicable Drivers: H2 Embedded")); + Assertions.assertTrue(output.contains("Auth Model ID: native")); } @Test @@ -75,12 +75,12 @@ public void testFilterByProvider() throws Exception { var cmd = DBVRTestSuite.getApplication().createCommandLine(); CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); - Assert.assertNotNull(result.getOutput()); - Assert.assertFalse(result.getOutput().isEmpty()); + Assertions.assertNotNull(result.getOutput()); + Assertions.assertFalse(result.getOutput().isEmpty()); String output = result.getOutput().getFirst(); - Assert.assertTrue(output.contains("Auth Model ID:")); - Assert.assertTrue(output.contains("Applicable Drivers:")); + Assertions.assertTrue(output.contains("Auth Model ID:")); + Assertions.assertTrue(output.contains("Applicable Drivers:")); } @Test @@ -96,12 +96,12 @@ public void testFilterByConnection() throws Exception { var cmd = DBVRTestSuite.getApplication().createCommandLine(); CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); - Assert.assertNotNull(result.getOutput()); - Assert.assertFalse(result.getOutput().isEmpty()); + Assertions.assertNotNull(result.getOutput()); + Assertions.assertFalse(result.getOutput().isEmpty()); String output = result.getOutput().getFirst(); - Assert.assertTrue(output.contains("Applicable Drivers: H2 Embedded")); - Assert.assertTrue(output.contains("Auth Model ID: native")); + Assertions.assertTrue(output.contains("Applicable Drivers: H2 Embedded")); + Assertions.assertTrue(output.contains("Auth Model ID: native")); } finally { ds.getRegistry().removeDataSource(ds); } diff --git a/test/org.dbvr.test.platform/src/org/dbvr/test/DBVRTest.java b/test/org.dbvr.test.platform/src/org/dbvr/test/DBVRTest.java index 81669bf..d72f867 100644 --- a/test/org.dbvr.test.platform/src/org/dbvr/test/DBVRTest.java +++ b/test/org.dbvr.test.platform/src/org/dbvr/test/DBVRTest.java @@ -16,23 +16,37 @@ */ package org.dbvr.test; -import org.jkiss.junit.osgi.OSGITestRunner; import org.jkiss.junit.osgi.annotation.RunWithApplication; import org.jkiss.junit.osgi.annotation.RunWithProduct; -import org.jkiss.junit.osgi.annotation.RunnerProxy; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.jkiss.junit.osgi.behaviors.IAsyncApplication; +import org.jkiss.junit.osgi.extension.OSGITestExtension; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.extension.ExtendWith; @RunWithProduct("dbvr-unittest.product") -@RunnerProxy(MockitoJUnitRunner.class) -@RunWith(OSGITestRunner.class) +@ExtendWith(OSGITestExtension.class) @RunWithApplication( bundleName = "org.dbvr.app.ce", registryName = "org.dbvr.app.ce.application", + waitForWorkbench = false, properties = { @RunWithApplication.Property(name = "osgi.instance.area", value = "./target/workpsace") } ) -public abstract class DBVRTest { +public abstract class DBVRTest implements IAsyncApplication { + + @BeforeAll + public static void setUpApplication() throws Exception { + DBVRTestSuite.initApplication(); + } + + @Override + public boolean verifyLaunched() { + try { + return DBVRTestSuite.getApplication().isStarted(); + } catch (Exception e) { + return false; + } + } } diff --git a/test/org.dbvr.test.platform/src/org/dbvr/test/DBVRTestSuite.java b/test/org.dbvr.test.platform/src/org/dbvr/test/DBVRTestSuite.java index 2688739..3184e52 100644 --- a/test/org.dbvr.test.platform/src/org/dbvr/test/DBVRTestSuite.java +++ b/test/org.dbvr.test.platform/src/org/dbvr/test/DBVRTestSuite.java @@ -19,24 +19,23 @@ import org.dbvr.cli.app.ce.CLIApplicationCE; import org.jkiss.code.NotNull; import org.jkiss.dbeaver.DBException; +import org.jkiss.dbeaver.model.impl.app.AbstractApplication; import org.jkiss.dbeaver.runtime.DBWorkbench; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; -@RunWith(Suite.class) -@Suite.SuiteClasses({ +@Suite +@SelectClasses({ HelpArgTest.class, DataSourceManagementTest.class, ProjectManagementTest.class, AuthModelsTest.class, InjectTest.class }) -public class DBVRTestSuite { +public class DBVRTestSuite extends DBVRTest { private static CLIApplicationCE applicationCE; - @BeforeClass public static void initApplication() throws Exception { System.out.println("Start CLI Application"); if (DBWorkbench.isPlatformStarted()) { @@ -71,10 +70,13 @@ public static void initApplication() throws Exception { @NotNull public static CLIApplicationCE getApplication() throws DBException { if (applicationCE == null) { - if (DBWorkbench.isPlatformStarted()) { - return (CLIApplicationCE) DBWorkbench.getPlatform().getApplication(); + Object instance = AbstractApplication.getInstanceOrNull(); + if (instance instanceof CLIApplicationCE ce) { + applicationCE = ce; + } + if (applicationCE == null) { + throw new DBException("Application is not running"); } - throw new DBException("Application is not running"); } return applicationCE; diff --git a/test/org.dbvr.test.platform/src/org/dbvr/test/DataSourceManagementTest.java b/test/org.dbvr.test.platform/src/org/dbvr/test/DataSourceManagementTest.java index 0212460..bf1f76e 100644 --- a/test/org.dbvr.test.platform/src/org/dbvr/test/DataSourceManagementTest.java +++ b/test/org.dbvr.test.platform/src/org/dbvr/test/DataSourceManagementTest.java @@ -30,8 +30,8 @@ import org.jkiss.dbeaver.model.net.DBWUtils; import org.jkiss.dbeaver.registry.network.NetworkHandlerRegistry; import org.jkiss.dbeaver.runtime.DBWorkbench; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.UUID; @@ -53,15 +53,15 @@ public void testCreate() throws Exception { var cmd = DBVRTestSuite.getApplication().createCommandLine(); CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); - Assert.assertNotNull(result.getOutput()); - Assert.assertEquals(1, result.getOutput().size()); + Assertions.assertNotNull(result.getOutput()); + Assertions.assertEquals(1, result.getOutput().size()); String createdId = result.getOutput().getFirst(); DBPProject project = DBWorkbench.getPlatform().getWorkspace().getActiveProject(); - Assert.assertNotNull(project); + Assertions.assertNotNull(project); DBPDataSourceContainer ds = project.getDataSourceRegistry().getDataSource(createdId); - Assert.assertNotNull(ds); - Assert.assertEquals(uniqName, ds.getName()); + Assertions.assertNotNull(ds); + Assertions.assertEquals(uniqName, ds.getName()); project.getDataSourceRegistry().removeDataSource(ds); } @@ -88,25 +88,25 @@ public void testCreateWithSSH() throws Exception { var cmd = DBVRTestSuite.getApplication().createCommandLine(); CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); - Assert.assertNotNull(result.getOutput()); - Assert.assertEquals(1, result.getOutput().size()); + Assertions.assertNotNull(result.getOutput()); + Assertions.assertEquals(1, result.getOutput().size()); if (result.getExitCode() == CLIConstants.EXIT_CODE_ERROR) { - Assert.fail("Error during datasource creation: " + String.join("\n", result.getOutput())); + Assertions.fail("Error during datasource creation: " + String.join("\n", result.getOutput())); } String createdId = result.getOutput().get(0); DBPProject project = DBWorkbench.getPlatform().getWorkspace().getActiveProject(); - Assert.assertNotNull(project); + Assertions.assertNotNull(project); DBPDataSourceContainer ds = project.getDataSourceRegistry().getDataSource(createdId); - Assert.assertNotNull(ds); - Assert.assertEquals(uniqName, ds.getName()); + Assertions.assertNotNull(ds); + Assertions.assertEquals(uniqName, ds.getName()); DBWHandlerConfiguration sshConf = ds.getConnectionConfiguration().getHandler(DBWUtils.SSH_TUNNEL); - Assert.assertNotNull(sshConf); - Assert.assertEquals("test_host", sshConf.getProperty("host")); - Assert.assertEquals("/opt/test/path", sshConf.getProperty("keyPath")); - Assert.assertEquals(uniqUser, sshConf.getUserName()); - Assert.assertEquals(uniqPwd, sshConf.getPassword()); - Assert.assertEquals("PUBLIC_KEY", sshConf.getProperty("authType")); + Assertions.assertNotNull(sshConf); + Assertions.assertEquals("test_host", sshConf.getProperty("host")); + Assertions.assertEquals("/opt/test/path", sshConf.getProperty("keyPath")); + Assertions.assertEquals(uniqUser, sshConf.getUserName()); + Assertions.assertEquals(uniqPwd, sshConf.getPassword()); + Assertions.assertEquals("PUBLIC_KEY", sshConf.getProperty("authType")); project.getDataSourceRegistry().removeDataSource(ds); } @@ -117,17 +117,17 @@ public void testDelete() throws Exception { createFakeDataSource(uniqName); var registry = DBWorkbench.getPlatform().getWorkspace().getActiveProject() .getDataSourceRegistry(); - Assert.assertNotNull(registry.findDataSourceByName(uniqName)); + Assertions.assertNotNull(registry.findDataSourceByName(uniqName)); var cmd = DBVRTestSuite.getApplication().createCommandLine(); var args = new String[] { "datasource", "delete", uniqName }; CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); - Assert.assertNotNull(result.getOutput()); - Assert.assertEquals(1, result.getOutput().size()); - Assert.assertTrue(result.getOutput().get(0).contains(uniqName)); - Assert.assertNull(registry.findDataSourceByName(uniqName)); + Assertions.assertNotNull(result.getOutput()); + Assertions.assertEquals(1, result.getOutput().size()); + Assertions.assertTrue(result.getOutput().get(0).contains(uniqName)); + Assertions.assertNull(registry.findDataSourceByName(uniqName)); } @Test @@ -137,10 +137,10 @@ public void testUpdate() throws Exception { DBPDataSourceContainer ds = createFakeDataSource(uniqName); var registry = DBWorkbench.getPlatform().getWorkspace().getActiveProject() .getDataSourceRegistry(); - Assert.assertNotNull(registry.findDataSourceByName(uniqName)); + Assertions.assertNotNull(registry.findDataSourceByName(uniqName)); var cmd = DBVRTestSuite.getApplication().createCommandLine(); String newRandomHost = "host" + UUID.randomUUID(); - Assert.assertNotEquals(newRandomHost, ds.getConnectionConfiguration().getHostName()); + Assertions.assertNotEquals(newRandomHost, ds.getConnectionConfiguration().getHostName()); var args = new String[] { "datasource", "update", ds.getId(), @@ -150,14 +150,14 @@ public void testUpdate() throws Exception { ds = registry.findDataSourceByName(uniqName); - Assert.assertNotNull(ds); - Assert.assertEquals(newRandomHost, ds.getConnectionConfiguration().getHostName()); + Assertions.assertNotNull(ds); + Assertions.assertEquals(newRandomHost, ds.getConnectionConfiguration().getHostName()); - Assert.assertNotNull(result.getOutput()); - Assert.assertEquals(1, result.getOutput().size()); + Assertions.assertNotNull(result.getOutput()); + Assertions.assertEquals(1, result.getOutput().size()); String output = result.getOutput().getFirst(); - Assert.assertTrue(output.contains(newRandomHost)); - Assert.assertTrue(output.contains(uniqName)); + Assertions.assertTrue(output.contains(newRandomHost)); + Assertions.assertTrue(output.contains(uniqName)); registry.removeDataSource(ds); } @@ -173,27 +173,27 @@ public void testView() throws Exception { "datasource", "view", ds.getId() }; CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); - Assert.assertNotNull(result.getOutput()); - Assert.assertEquals(uniqUser, ds.getConnectionConfiguration().getUserName()); - Assert.assertEquals(uniqPwd, ds.getConnectionConfiguration().getUserPassword()); - Assert.assertEquals(1, result.getOutput().size()); + Assertions.assertNotNull(result.getOutput()); + Assertions.assertEquals(uniqUser, ds.getConnectionConfiguration().getUserName()); + Assertions.assertEquals(uniqPwd, ds.getConnectionConfiguration().getUserPassword()); + Assertions.assertEquals(1, result.getOutput().size()); String output = result.getOutput().getFirst(); - Assert.assertTrue(output.contains(uniqName)); - Assert.assertFalse(output.contains(uniqUser)); - Assert.assertFalse(output.contains(uniqPwd)); + Assertions.assertTrue(output.contains(uniqName)); + Assertions.assertFalse(output.contains(uniqUser)); + Assertions.assertFalse(output.contains(uniqPwd)); var sshConf = ds.getConnectionConfiguration().getHandler(DBWUtils.SSH_TUNNEL); - Assert.assertNotNull(sshConf); - Assert.assertNotNull(sshConf.getPassword()); - Assert.assertNotNull(sshConf.getUserName()); + Assertions.assertNotNull(sshConf); + Assertions.assertNotNull(sshConf.getPassword()); + Assertions.assertNotNull(sshConf.getUserName()); - Assert.assertFalse(output.contains(sshConf.getPassword())); - Assert.assertFalse(output.contains(sshConf.getUserName())); - Assert.assertFalse(output.contains("turbo_secure_prop")); + Assertions.assertFalse(output.contains(sshConf.getPassword())); + Assertions.assertFalse(output.contains(sshConf.getUserName())); + Assertions.assertFalse(output.contains("turbo_secure_prop")); - Assert.assertNotNull(sshConf.getSecureProperty("turbo_secure_prop")); - Assert.assertFalse(output.contains(sshConf.getSecureProperty("turbo_secure_prop"))); + Assertions.assertNotNull(sshConf.getSecureProperty("turbo_secure_prop")); + Assertions.assertFalse(output.contains(sshConf.getSecureProperty("turbo_secure_prop"))); var registry = DBWorkbench.getPlatform().getWorkspace().getActiveProject() @@ -210,14 +210,14 @@ public void testList() throws Exception { "datasource", "list" }; CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); - Assert.assertNotNull(result.getOutput()); - Assert.assertEquals(1, result.getOutput().size()); + Assertions.assertNotNull(result.getOutput()); + Assertions.assertEquals(1, result.getOutput().size()); String output = result.getOutput().getFirst(); - Assert.assertTrue(output.contains("ID")); - Assert.assertTrue(output.contains("NAME")); - Assert.assertTrue(output.contains("DRIVER")); - Assert.assertTrue(output.contains(ds.getId())); - Assert.assertTrue(output.contains(uniqName)); + Assertions.assertTrue(output.contains("ID")); + Assertions.assertTrue(output.contains("NAME")); + Assertions.assertTrue(output.contains("DRIVER")); + Assertions.assertTrue(output.contains(ds.getId())); + Assertions.assertTrue(output.contains(uniqName)); var registry = DBWorkbench.getPlatform().getWorkspace().getActiveProject() .getDataSourceRegistry(); @@ -242,17 +242,17 @@ public void testMove() throws Exception { // datasource removed from the source project DBPProject sourceProject = DBWorkbench.getPlatform().getWorkspace().getActiveProject(); - Assert.assertNull(sourceProject.getDataSourceRegistry().getDataSource(dsId)); + Assertions.assertNull(sourceProject.getDataSourceRegistry().getDataSource(dsId)); // datasource must exist in the target project DBPDataSourceContainer movedDs = targetProject.getDataSourceRegistry().findDataSourceByName(uniqName); - Assert.assertNotNull(movedDs); + Assertions.assertNotNull(movedDs); - Assert.assertNotNull(result.getOutput()); - Assert.assertEquals(1, result.getOutput().size()); + Assertions.assertNotNull(result.getOutput()); + Assertions.assertEquals(1, result.getOutput().size()); String output = result.getOutput().getFirst(); - Assert.assertTrue(output.contains(uniqName)); - Assert.assertTrue(output.contains(targetProjectName)); + Assertions.assertTrue(output.contains(uniqName)); + Assertions.assertTrue(output.contains(targetProjectName)); } finally { DBWorkbench.getPlatform().getWorkspace().deleteProject(targetProject); } @@ -273,10 +273,10 @@ public void testMoveSameProject() throws Exception { CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); String output = String.join("\n", result.getOutput()); - Assert.assertEquals("Move to same project should fail with ILLEGAL_ARGUMENTS. Output: " + output, - CLIConstants.EXIT_CODE_ILLEGAL_ARGUMENTS, result.getExitCode()); - Assert.assertTrue("Output should contain word 'same'. Actual output: " + output, - output.contains("same")); + Assertions.assertEquals(CLIConstants.EXIT_CODE_ILLEGAL_ARGUMENTS, result.getExitCode(), + "Move to same project should fail with ILLEGAL_ARGUMENTS. Output: " + output); + Assertions.assertTrue(output.contains("same"), + "Output should contain word 'same'. Actual output: " + output); } finally { registry.removeDataSource(registry.getDataSource(ds.getId())); } @@ -289,12 +289,12 @@ public void testHelpWhenWhenCommandWithNoParams() throws Exception { "datasource" }; CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); - Assert.assertNotNull(result.getOutput()); - Assert.assertFalse(result.getOutput().isEmpty()); + Assertions.assertNotNull(result.getOutput()); + Assertions.assertFalse(result.getOutput().isEmpty()); String output = result.getOutput().getFirst(); - Assert.assertTrue(output.contains("Usage: dbvr datasource")); - Assert.assertTrue(output.contains("create")); - Assert.assertTrue(output.contains("list")); + Assertions.assertTrue(output.contains("Usage: dbvr datasource")); + Assertions.assertTrue(output.contains("create")); + Assertions.assertTrue(output.contains("list")); } @Test @@ -310,10 +310,10 @@ public void testCreateWithUrlAndHostConflict() throws Exception { CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); String output = String.join("\n", result.getOutput()); - Assert.assertEquals(CLIConstants.EXIT_CODE_ERROR, result.getExitCode()); - Assert.assertNotNull(result.getOutput()); - Assert.assertFalse(result.getOutput().isEmpty()); - Assert.assertTrue(output.contains("mutually exclusive")); + Assertions.assertEquals(CLIConstants.EXIT_CODE_ERROR, result.getExitCode()); + Assertions.assertNotNull(result.getOutput()); + Assertions.assertFalse(result.getOutput().isEmpty()); + Assertions.assertTrue(output.contains("mutually exclusive")); } @Test @@ -332,10 +332,10 @@ public void testUpdateWithUrlAndPortConflict() throws Exception { CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); String output = String.join("\n", result.getOutput()); - Assert.assertEquals(CLIConstants.EXIT_CODE_ERROR, result.getExitCode()); - Assert.assertNotNull(result.getOutput()); - Assert.assertFalse(result.getOutput().isEmpty()); - Assert.assertTrue(output.contains("mutually exclusive")); + Assertions.assertEquals(CLIConstants.EXIT_CODE_ERROR, result.getExitCode()); + Assertions.assertNotNull(result.getOutput()); + Assertions.assertFalse(result.getOutput().isEmpty()); + Assertions.assertTrue(output.contains("mutually exclusive")); registry.removeDataSource(ds); } diff --git a/test/org.dbvr.test.platform/src/org/dbvr/test/HelpArgTest.java b/test/org.dbvr.test.platform/src/org/dbvr/test/HelpArgTest.java index 54b963e..62d8004 100644 --- a/test/org.dbvr.test.platform/src/org/dbvr/test/HelpArgTest.java +++ b/test/org.dbvr.test.platform/src/org/dbvr/test/HelpArgTest.java @@ -20,8 +20,8 @@ import org.jkiss.code.NotNull; import org.jkiss.dbeaver.model.cli.CLIProcessResult; import org.jkiss.utils.CommonUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class HelpArgTest extends DBVRTest { @@ -31,18 +31,18 @@ public void testHelpArg() throws Exception { var cmd = DBVRTestSuite.getApplication().createCommandLine(); CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); - Assert.assertNotNull(result.getOutput()); + Assertions.assertNotNull(result.getOutput()); } @Test public void testEmptyArgs() throws Exception { String[] args = {"--help"}; CLIProcessResult resultWithArg = DBVRTestSuite.getApplication().executeCommandLine(args); - Assert.assertNotNull(resultWithArg.getOutput()); + Assertions.assertNotNull(resultWithArg.getOutput()); String[] noArgs = {}; CLIProcessResult resultNoArg = DBVRTestSuite.getApplication().executeCommandLine(noArgs); - Assert.assertEquals(resultWithArg.getOutput(), resultNoArg.getOutput()); + Assertions.assertEquals(resultWithArg.getOutput(), resultNoArg.getOutput()); } @@ -50,18 +50,18 @@ public void testEmptyArgs() throws Exception { public void testHelpFormatAndOptionsOrder() throws Exception { String[] args = {TestCommand.TEST_COMMAND_NAME, "--help"}; CLIProcessResult result = DBVRTestSuite.getApplication().executeCommandLine(args); - Assert.assertNotNull(result.getOutput()); - Assert.assertEquals(1, result.getOutput().size()); + Assertions.assertNotNull(result.getOutput()); + Assertions.assertEquals(1, result.getOutput().size()); String help = result.getOutput().getFirst(); - Assert.assertTrue(CommonUtils.isNotEmpty(help)); + Assertions.assertTrue(CommonUtils.isNotEmpty(help)); String[] commandDescAndOptions = help.split(TestCommand.DESCRIPTION); - Assert.assertEquals(2, commandDescAndOptions.length); + Assertions.assertEquals(2, commandDescAndOptions.length); String allArgsHelp = commandDescAndOptions[1].trim(); - Assert.assertTrue(CommonUtils.isNotEmpty(allArgsHelp)); + Assertions.assertTrue(CommonUtils.isNotEmpty(allArgsHelp)); //because it global option and must be only in top level help - Assert.assertFalse(allArgsHelp.contains("--debug-logs")); + Assertions.assertFalse(allArgsHelp.contains("--debug-logs")); String[] allArgsByLine = allArgsHelp.split("\n"); @@ -69,32 +69,32 @@ public void testHelpFormatAndOptionsOrder() throws Exception { String position2 = allArgsByLine[1].trim(); String position3 = allArgsByLine[2].trim(); - Assert.assertFalse(position1.contains("required")); + Assertions.assertFalse(position1.contains("required")); //required position param not sorted - Assert.assertTrue(position2.contains("required")); - Assert.assertFalse(position3.contains("required")); + Assertions.assertTrue(position2.contains("required")); + Assertions.assertFalse(position3.contains("required")); String reqOption1 = allArgsByLine[4].trim(); String reqOption2 = allArgsByLine[6].trim(); // cause line 6 - it help for command from line 4 - Assert.assertTrue(reqOption1.startsWith(TestCommand.TEST_REQ_FIRST)); - Assert.assertTrue(reqOption1.contains("required")); - Assert.assertTrue(reqOption2.startsWith(TestCommand.TEST_REQ_IN_MIDDLE)); - Assert.assertTrue(reqOption2.contains("required")); - Assert.assertFalse(findOptionLine(allArgsByLine, TestCommand.TEST_PARAM_NAME_NOT_REQ).contains("required")); + Assertions.assertTrue(reqOption1.startsWith(TestCommand.TEST_REQ_FIRST)); + Assertions.assertTrue(reqOption1.contains("required")); + Assertions.assertTrue(reqOption2.startsWith(TestCommand.TEST_REQ_IN_MIDDLE)); + Assertions.assertTrue(reqOption2.contains("required")); + Assertions.assertFalse(findOptionLine(allArgsByLine, TestCommand.TEST_PARAM_NAME_NOT_REQ).contains("required")); - Assert.assertTrue(findOptionLine(allArgsByLine, TestCommand.TEST_INT_ARRAY).contains("(integer[])")); - Assert.assertTrue(findOptionLine(allArgsByLine, TestCommand.TEST_INT_LIST).contains("(integer[])")); - Assert.assertTrue(findOptionLine(allArgsByLine, TestCommand.TEST_DOUBLE).contains("(double)")); - Assert.assertTrue(findOptionLine(allArgsByLine, TestCommand.TEST_STRING_LIST).contains("(string[])")); + Assertions.assertTrue(findOptionLine(allArgsByLine, TestCommand.TEST_INT_ARRAY).contains("(integer[])")); + Assertions.assertTrue(findOptionLine(allArgsByLine, TestCommand.TEST_INT_LIST).contains("(integer[])")); + Assertions.assertTrue(findOptionLine(allArgsByLine, TestCommand.TEST_DOUBLE).contains("(double)")); + Assertions.assertTrue(findOptionLine(allArgsByLine, TestCommand.TEST_STRING_LIST).contains("(string[])")); String example1 = allArgsByLine[allArgsByLine.length - 2].trim(); String example2 = allArgsByLine[allArgsByLine.length - 1].trim(); - Assert.assertEquals("- dbvr " + TestCommand.EXAMPLE_COMMAND1, example1); - Assert.assertEquals("- dbvr " + TestCommand.EXAMPLE_COMMAND2, example2); + Assertions.assertEquals("- dbvr " + TestCommand.EXAMPLE_COMMAND1, example1); + Assertions.assertEquals("- dbvr " + TestCommand.EXAMPLE_COMMAND2, example2); } diff --git a/test/org.dbvr.test.platform/src/org/dbvr/test/InjectTest.java b/test/org.dbvr.test.platform/src/org/dbvr/test/InjectTest.java index 3dd2d8f..5201a05 100644 --- a/test/org.dbvr.test.platform/src/org/dbvr/test/InjectTest.java +++ b/test/org.dbvr.test.platform/src/org/dbvr/test/InjectTest.java @@ -19,8 +19,8 @@ import org.dbvr.cli.app.ce.command.TestCommand; import org.dbvr.cli.app.ce.command.TestTransformer; import org.jkiss.utils.CommonUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class InjectTest extends DBVRTest { @Test @@ -30,7 +30,7 @@ public void testThatParamInjected() throws Exception { }; var result = DBVRTestSuite.getApplication().executeCommandLine(args); - Assert.assertFalse(CommonUtils.isEmpty(result.getOutput())); - Assert.assertTrue(result.getOutput().getFirst().contains(TestTransformer.RANDOM_PARAM_NAME)); + Assertions.assertFalse(CommonUtils.isEmpty(result.getOutput())); + Assertions.assertTrue(result.getOutput().getFirst().contains(TestTransformer.RANDOM_PARAM_NAME)); } } \ No newline at end of file diff --git a/test/org.dbvr.test.platform/src/org/dbvr/test/InjectionTest.java b/test/org.dbvr.test.platform/src/org/dbvr/test/InjectionTest.java index 0142401..3b86453 100644 --- a/test/org.dbvr.test.platform/src/org/dbvr/test/InjectionTest.java +++ b/test/org.dbvr.test.platform/src/org/dbvr/test/InjectionTest.java @@ -20,8 +20,8 @@ import org.dbvr.cli.app.ce.command.TestCommand; import org.dbvr.cli.app.ce.command.TestTransformer; import org.jkiss.utils.CommonUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class InjectionTest extends DBVRTest { @@ -32,7 +32,7 @@ public void testThatParamInjected() throws Exception { }; var result = DBVRTestSuite.getApplication().executeCommandLine(args); - Assert.assertFalse(CommonUtils.isEmpty(result.getOutput())); - Assert.assertTrue(result.getOutput().getFirst().contains(TestTransformer.RANDOM_PARAM_NAME)); + Assertions.assertFalse(CommonUtils.isEmpty(result.getOutput())); + Assertions.assertTrue(result.getOutput().getFirst().contains(TestTransformer.RANDOM_PARAM_NAME)); } } diff --git a/test/org.dbvr.test.platform/src/org/dbvr/test/ProjectManagementTest.java b/test/org.dbvr.test.platform/src/org/dbvr/test/ProjectManagementTest.java index 10f17d0..3a511ac 100644 --- a/test/org.dbvr.test.platform/src/org/dbvr/test/ProjectManagementTest.java +++ b/test/org.dbvr.test.platform/src/org/dbvr/test/ProjectManagementTest.java @@ -21,9 +21,9 @@ import org.jkiss.dbeaver.model.cli.CLIProcessResult; import org.jkiss.dbeaver.model.impl.app.BaseProjectImpl; import org.jkiss.dbeaver.runtime.DBWorkbench; -import org.junit.After; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.nio.file.Files; import java.nio.file.Path; @@ -37,7 +37,7 @@ public class ProjectManagementTest extends DBVRTest { private final List projectsToDelete = new ArrayList<>(); - @After + @AfterEach public void tearDown() { for (DBPProject project : projectsToDelete) { try { @@ -63,9 +63,9 @@ public void testCreateProject() throws Exception { cmd.executeCommandLineCommands(null, false, false, args); DBPProject project = DBWorkbench.getPlatform().getWorkspace().getProject(name); - Assert.assertNotNull(project); + Assertions.assertNotNull(project); projectsToDelete.add(project); - Assert.assertEquals(desc, project.getDescription()); + Assertions.assertEquals(desc, project.getDescription()); } @Test @@ -84,11 +84,11 @@ public void testRenameProject() throws Exception { cmd.executeCommandLineCommands(null, false, false, args); DBPProject renamedProject = DBWorkbench.getPlatform().getWorkspace().getProject(newName); - Assert.assertNotNull(renamedProject); + Assertions.assertNotNull(renamedProject); if (renamedProject != project) { projectsToDelete.add(renamedProject); } - Assert.assertEquals(newDesc, renamedProject.getDescription()); + Assertions.assertEquals(newDesc, renamedProject.getDescription()); } @Test @@ -104,7 +104,7 @@ public void testDeleteProject() throws Exception { var cmd = DBVRTestSuite.getApplication().createCommandLine(); cmd.executeCommandLineCommands(null, false, false, args); - Assert.assertNull(DBWorkbench.getPlatform().getWorkspace().getProject(name)); + Assertions.assertNull(DBWorkbench.getPlatform().getWorkspace().getProject(name)); } @Test @@ -120,13 +120,13 @@ public void testListProjects() throws Exception { var cmd = DBVRTestSuite.getApplication().createCommandLine(); CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); - Assert.assertNotNull(result.getOutput()); + Assertions.assertNotNull(result.getOutput()); boolean found = false; String allOutput = String.join("\n", result.getOutput()); if (allOutput.contains(name)) { found = true; } - Assert.assertTrue("Project " + name + " not found in output: " + result.getOutput(), found); + Assertions.assertTrue(found, "Project " + name + " not found in output: " + result.getOutput()); } @Test @@ -142,13 +142,13 @@ public void testListProjectsNoDescription() throws Exception { var cmd = DBVRTestSuite.getApplication().createCommandLine(); CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); - Assert.assertNotNull(result.getOutput()); + Assertions.assertNotNull(result.getOutput()); boolean found = false; String allOutput = String.join("\n", result.getOutput()); if (allOutput.contains(name)) { found = true; } - Assert.assertTrue("Project " + name + " (no desc) not found in output: " + result.getOutput(), found); + Assertions.assertTrue(found, "Project " + name + " (no desc) not found in output: " + result.getOutput()); } @Test @@ -161,32 +161,43 @@ public void testCreateHiddenProjectForbidden() throws Exception { var cmd = DBVRTestSuite.getApplication().createCommandLine(); CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); - Assert.assertTrue("Error message expected for hidden project creation", - String.join("\n", result.getOutput()).contains("Resource name '.test_prj_hidden' can't start with dot")); + Assertions.assertTrue(String.join("\n", result.getOutput()).contains("Resource name '.test_prj_hidden' can't start with dot")); } @Test public void testSetDefaultProject() throws Exception { - String name = "test_prj_" + UUID.randomUUID(); - DBPProject project = DBWorkbench.getPlatform().getWorkspace().createProject(name, "Default test"); - projectsToDelete.add(project); + DBPProject originalActive = DBWorkbench.getPlatform().getWorkspace().getActiveProject(); + var cmd = DBVRTestSuite.getApplication().createCommandLine(); - String[] args = { - "project", "default", project.getId() - }; + try { + String name = "test_prj_" + UUID.randomUUID(); + DBPProject project = DBWorkbench.getPlatform().getWorkspace().createProject(name, "Default test"); + projectsToDelete.add(project); - var cmd = DBVRTestSuite.getApplication().createCommandLine(); - CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); - Assert.assertNotNull(result.getOutput()); - Assert.assertTrue(String.join("\n", result.getOutput()).contains("Project '" + name + "' set as default.")); + String[] args = { + "project", "default", project.getId() + }; + + CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); + + Assertions.assertNotNull(result.getOutput()); + Assertions.assertTrue(String.join("\n", result.getOutput()).contains("Project '" + name + "' set as default.")); + + String[] listArgs = { + "project", "list" + }; + CLIProcessResult listResult = cmd.executeCommandLineCommands(null, false, false, listArgs); + String listOutput = String.join("\n", listResult.getOutput()); + Assertions.assertTrue(listOutput.contains("yes"), "Default project should be marked in list output"); + + } finally { + if (originalActive != null) { + String[] restoreArgs = { "project", "default", originalActive.getId() }; + cmd.executeCommandLineCommands(null, false, false, restoreArgs); + } + } - String[] listArgs = { - "project", "list" - }; - CLIProcessResult listResult = cmd.executeCommandLineCommands(null, false, false, listArgs); - String listOutput = String.join("\n", listResult.getOutput()); - Assert.assertTrue("Default project should be marked in list output", listOutput.contains("yes")); } @Test @@ -196,17 +207,17 @@ public void testProjectFileCreation() throws Exception { projectsToDelete.add(project); Path projectFile = project.getAbsolutePath().resolve(BaseProjectImpl.PROJECT_FILE); - Assert.assertTrue("Project file must exist", Files.exists(projectFile)); + Assertions.assertTrue(Files.exists(projectFile), "Project file must exist"); String content = Files.readString(projectFile); - Assert.assertTrue("Project file must contain project name", content.contains("" + name + "")); - Assert.assertTrue("Project file must contain DBeaver nature", content.contains("org.jkiss.dbeaver.DBeaverNature")); + Assertions.assertTrue(content.contains("" + name + ""), "Project file must contain project name"); + Assertions.assertTrue(content.contains("org.jkiss.dbeaver.DBeaverNature"), "Project file must contain DBeaver nature"); // Test rename String newName = name + "_ren"; DBWorkbench.getPlatform().getWorkspace().renameProject(project, newName); Path newProjectFile = project.getAbsolutePath().resolve(BaseProjectImpl.PROJECT_FILE); - Assert.assertTrue("Project file must exist after rename", Files.exists(newProjectFile)); + Assertions.assertTrue(Files.exists(newProjectFile), "Project file must exist after rename"); String newContent = Files.readString(newProjectFile); - Assert.assertTrue("Project file must contain new project name", newContent.contains("" + newName + "")); + Assertions.assertTrue(newContent.contains("" + newName + ""), "Project file must contain new project name"); } } diff --git a/test/pom.xml b/test/pom.xml index cef93e7..2518e44 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -30,6 +30,7 @@ org.dbvr.app.ce.application org.dbvr.app.test.product default + junit6 ./target/workspace