From d820f829341d41f85a307a51a6a7865be648fc00 Mon Sep 17 00:00:00 2001 From: Tsimafei Labanovich Date: Sat, 18 Apr 2026 02:20:57 +0200 Subject: [PATCH 1/6] dbeaver/pro#8766 Boom --- .../org/dbvr/cli/app/CLIApplicationBase.java | 2 +- .../src/org/dbvr/cli/app/CLIWorkspace.java | 8 +- .../community-unittest/dbvr-unittest.product | 1 + .../META-INF/MANIFEST.MF | 2 - .../src/org/dbvr/test/AuthModelsTest.java | 32 ++-- .../src/org/dbvr/test/DBVRTest.java | 22 ++- .../src/org/dbvr/test/DBVRTestSuite.java | 20 ++- .../dbvr/test/DataSourceManagementTest.java | 154 +++++++++--------- .../src/org/dbvr/test/HelpArgTest.java | 50 +++--- .../src/org/dbvr/test/InjectTest.java | 8 +- .../src/org/dbvr/test/InjectionTest.java | 8 +- .../org/dbvr/test/ProjectManagementTest.java | 53 +++--- 12 files changed, 190 insertions(+), 170 deletions(-) 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/bundles/org.dbvr.cli/src/org/dbvr/cli/app/CLIWorkspace.java b/bundles/org.dbvr.cli/src/org/dbvr/cli/app/CLIWorkspace.java index 1d71b8e..440910f 100644 --- a/bundles/org.dbvr.cli/src/org/dbvr/cli/app/CLIWorkspace.java +++ b/bundles/org.dbvr.cli/src/org/dbvr/cli/app/CLIWorkspace.java @@ -169,7 +169,7 @@ public DBPProject getProjectById(@NotNull String projectId) { } @Override - public void initializeProjects() throws DBException { + public void initializeProjects() { List projectPaths = new ArrayList<>(); try { Files.walkFileTree(getAbsolutePath(), new SimpleFileVisitor<>() { @@ -214,7 +214,11 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th activeProject = defaultProject; - initializeWorkspaceSession(); + try { + initializeWorkspaceSession(); + } catch (DBException e) { + log.error("Error initializing workspace session", e); + } } @Nullable 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/META-INF/MANIFEST.MF b/test/org.dbvr.test.platform/META-INF/MANIFEST.MF index 0350c1f..d1b5de1 100644 --- a/test/org.dbvr.test.platform/META-INF/MANIFEST.MF +++ b/test/org.dbvr.test.platform/META-INF/MANIFEST.MF @@ -9,8 +9,6 @@ Bundle-RequiredExecutionEnvironment: JavaSE-21 Bundle-ActivationPolicy: lazy Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.resources, - org.junit, - org.mockito.mockito-core, org.apache.felix.scr, org.dbvr.app.ce, org.dbvr.app.ce.test, 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..1cf44e5 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,31 @@ */ 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.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 { + + @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..907cefb 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,14 +19,14 @@ 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, @@ -36,7 +36,6 @@ public class DBVRTestSuite { 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..e365582 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,8 +161,7 @@ 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"), "Error message expected for hidden project creation"); } @Test @@ -171,6 +170,8 @@ public void testSetDefaultProject() throws Exception { DBPProject project = DBWorkbench.getPlatform().getWorkspace().createProject(name, "Default test"); projectsToDelete.add(project); + DBPProject originalActive = DBWorkbench.getPlatform().getWorkspace().getActiveProject(); + String[] args = { "project", "default", project.getId() }; @@ -178,15 +179,21 @@ public void testSetDefaultProject() throws Exception { 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.")); + 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()); - Assert.assertTrue("Default project should be marked in list output", listOutput.contains("yes")); + Assertions.assertTrue(listOutput.contains("yes"), "Default project should be marked in list output"); + + // Restore the original active project so subsequent tests see a valid workspace state + if (originalActive != null) { + String[] restoreArgs = { "project", "default", originalActive.getId() }; + cmd.executeCommandLineCommands(null, false, false, restoreArgs); + } } @Test @@ -196,17 +203,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"); } } From 470099c820688f619666923a1f2e52d04967ae64 Mon Sep 17 00:00:00 2001 From: Tsimafei Labanovich Date: Sat, 18 Apr 2026 23:10:16 +0200 Subject: [PATCH 2/6] dbeaver/pro#8766 Boom --- test/pom.xml | 1 + 1 file changed, 1 insertion(+) 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 From 80e92bc279cd63c927127fcc0e3237767fdadfe6 Mon Sep 17 00:00:00 2001 From: Tsimafei Labanovich Date: Sat, 18 Apr 2026 23:21:49 +0200 Subject: [PATCH 3/6] dbeaver/pro#8766 Fix DBVRTestSuite: extend DBVRTest to activate OSGITestExtension Without extending DBVRTest, @ExtendWith(OSGITestExtension.class) was never applied to the suite class, so the CLI application was never started before tests ran, causing "Application is not running" for all 27 tests. --- .../org.dbvr.test.platform/src/org/dbvr/test/DBVRTestSuite.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 907cefb..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 @@ -33,7 +33,7 @@ AuthModelsTest.class, InjectTest.class }) -public class DBVRTestSuite { +public class DBVRTestSuite extends DBVRTest { private static CLIApplicationCE applicationCE; public static void initApplication() throws Exception { From 47338019eb79c505cae7c69e178f66cc640343d5 Mon Sep 17 00:00:00 2001 From: Tsimafei Labanovich Date: Sun, 19 Apr 2026 00:23:45 +0200 Subject: [PATCH 4/6] dbeaver/pro#8766 Fix DBVRTest: add @BeforeAll to call initApplication() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In JUnit 4, @BeforeClass on DBVRTestSuite called initApplication() which started the CLI application before tests ran. The JUnit 5 migration stripped @BeforeClass but added nothing to replace it — OSGITestExtension is IDEA-only and is a no-op in CI. Add @BeforeAll setUpApplication() to DBVRTest so initApplication() is called before each test class runs. --- test/org.dbvr.test.platform/src/org/dbvr/test/DBVRTest.java | 6 ++++++ 1 file changed, 6 insertions(+) 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 1cf44e5..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 @@ -20,6 +20,7 @@ import org.jkiss.junit.osgi.annotation.RunWithProduct; 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") @@ -34,6 +35,11 @@ ) public abstract class DBVRTest implements IAsyncApplication { + @BeforeAll + public static void setUpApplication() throws Exception { + DBVRTestSuite.initApplication(); + } + @Override public boolean verifyLaunched() { try { From 967d4d610bbdad3ea00cb2d9d34a8faada12892b Mon Sep 17 00:00:00 2001 From: Tsimafei Labanovich Date: Mon, 20 Apr 2026 01:28:51 +0200 Subject: [PATCH 5/6] dbeaver/pro#8766 Boom --- .../org.dbvr.cli/src/org/dbvr/cli/app/CLIWorkspace.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/bundles/org.dbvr.cli/src/org/dbvr/cli/app/CLIWorkspace.java b/bundles/org.dbvr.cli/src/org/dbvr/cli/app/CLIWorkspace.java index 440910f..1d71b8e 100644 --- a/bundles/org.dbvr.cli/src/org/dbvr/cli/app/CLIWorkspace.java +++ b/bundles/org.dbvr.cli/src/org/dbvr/cli/app/CLIWorkspace.java @@ -169,7 +169,7 @@ public DBPProject getProjectById(@NotNull String projectId) { } @Override - public void initializeProjects() { + public void initializeProjects() throws DBException { List projectPaths = new ArrayList<>(); try { Files.walkFileTree(getAbsolutePath(), new SimpleFileVisitor<>() { @@ -214,11 +214,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th activeProject = defaultProject; - try { - initializeWorkspaceSession(); - } catch (DBException e) { - log.error("Error initializing workspace session", e); - } + initializeWorkspaceSession(); } @Nullable From 04ab6705f8f741a63b8975e44a5b76850061ec65 Mon Sep 17 00:00:00 2001 From: Tsimafei Labanovich Date: Mon, 20 Apr 2026 10:18:20 +0200 Subject: [PATCH 6/6] dbeaver/pro#8766 Boom --- .../org/dbvr/test/ProjectManagementTest.java | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) 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 e365582..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 @@ -161,39 +161,43 @@ public void testCreateHiddenProjectForbidden() throws Exception { var cmd = DBVRTestSuite.getApplication().createCommandLine(); CLIProcessResult result = cmd.executeCommandLineCommands(null, false, false, args); - Assertions.assertTrue(String.join("\n", result.getOutput()).contains("Resource name '.test_prj_hidden' can't start with dot"), "Error message expected for hidden project creation"); + 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); - Assertions.assertNotNull(result.getOutput()); - Assertions.assertTrue(String.join("\n", result.getOutput()).contains("Project '" + name + "' set as default.")); + String[] args = { + "project", "default", project.getId() + }; - 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"); - - // Restore the original active project so subsequent tests see a valid workspace state - if (originalActive != null) { - String[] restoreArgs = { "project", "default", originalActive.getId() }; - cmd.executeCommandLineCommands(null, false, false, restoreArgs); + 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); + } } + } @Test