From f728590b90899775c7dee31991b192863eb24fa6 Mon Sep 17 00:00:00 2001 From: Tsimafei Labanovich Date: Tue, 9 Jun 2026 16:26:42 +0200 Subject: [PATCH] dbeaver/pro#8766 Migrage from junit 4 to junit 6 (#4290) * dbeaver/pro#8766 Boom * dbeaver/pro#8766 Boom * dbeaver/pro#8766 Boom * dbeaver/pro#8766 Boom --- .../META-INF/MANIFEST.MF | 3 +- .../io/cloudbeaver/CloudbeaverMockTest.java | 38 ++++++++-- .../src/io/cloudbeaver/app/CEAppStarter.java | 7 +- .../DBLTextDocumentServiceContextTest.java | 42 +++++----- .../model/lsp/DBLTextDocumentServiceTest.java | 76 +++++++++---------- .../DBLTextDocumentServiceWorkspaceTest.java | 14 ++-- .../model/lsp/H2DataSourceTest.java | 14 ++-- .../navigator/WebNavigatorNodeInfoTest.java | 24 +++--- .../io/cloudbeaver/model/rm/RMNIOTest.java | 60 +++++++-------- .../cloudbeaver/model/rm/lock/RMLockTest.java | 40 +++++----- .../model/session/WebSessionProjectTest.java | 54 ++++++------- .../model/session/WebSessionTest.java | 29 ++++--- .../test/platform/AuthenticationTest.java | 16 ++-- .../CBEventsLongPollingServletTest.java | 14 ++-- .../test/platform/CEServerTestSuite.java | 18 ++--- .../test/platform/ConnectionsTest.java | 36 ++++----- .../test/platform/NoSessionTest.java | 6 +- .../test/platform/ResourceManagerTest.java | 32 ++++---- .../test/platform/SQLQueryTranslatorTest.java | 10 +-- server/test/pom.xml | 1 + 20 files changed, 284 insertions(+), 250 deletions(-) diff --git a/server/test/io.cloudbeaver.test.platform/META-INF/MANIFEST.MF b/server/test/io.cloudbeaver.test.platform/META-INF/MANIFEST.MF index 4053ce80fc..17af949298 100644 --- a/server/test/io.cloudbeaver.test.platform/META-INF/MANIFEST.MF +++ b/server/test/io.cloudbeaver.test.platform/META-INF/MANIFEST.MF @@ -7,8 +7,7 @@ Bundle-Release-Date: 20220606 Bundle-Vendor: DBeaver Corp Bundle-RequiredExecutionEnvironment: JavaSE-21 Bundle-ActivationPolicy: lazy -Require-Bundle: org.junit, - org.mockito.mockito-core, +Require-Bundle: org.eclipse.core.runtime, org.apache.felix.scr, org.jkiss.dbeaver.osgi.test.runner;visibility:=reexport, org.jkiss.dbeaver.model.sql, diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/CloudbeaverMockTest.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/CloudbeaverMockTest.java index f0a2cebd06..7d1591a3c4 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/CloudbeaverMockTest.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/CloudbeaverMockTest.java @@ -1,20 +1,37 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2026 DBeaver Corp and others + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.cloudbeaver; +import io.cloudbeaver.app.CEAppStarter; import io.cloudbeaver.utils.WebTestUtils; -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.jkiss.junit.osgi.behaviors.IAsyncApplication; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.jkiss.junit.osgi.extension.OSGITestExtension; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.MockitoAnnotations; import java.net.CookieManager; import java.net.http.HttpClient; @RunWithProduct("CloudbeaverServerUnitTest.product") -@RunnerProxy(MockitoJUnitRunner.class) -@RunWith(OSGITestRunner.class) +@ExtendWith(OSGITestExtension.class) @RunWithApplication( bundleName = "io.cloudbeaver.server.ce", registryName = "io.cloudbeaver.product.ce.application", @@ -22,6 +39,15 @@ import java.net.http.HttpClient; vmArgs = {"logback.configurationFile", "workspace/conf/logback.xml"} ) public abstract class CloudbeaverMockTest implements IAsyncApplication { + @BeforeAll + public static void startServer() throws Exception { + CEAppStarter.startServerIfNotStarted(); + } + + @BeforeEach + public void setupMocks() { + MockitoAnnotations.openMocks(this); + } private static final String GQL_API_URL = "http://localhost:18978/api/gql"; private static final String SERVER_STATUS_URL = "http://localhost:18978/status"; private final HttpClient httpClient = HttpClient.newBuilder() diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/app/CEAppStarter.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/app/CEAppStarter.java index 0d3d5155ff..793a86f481 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/app/CEAppStarter.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/app/CEAppStarter.java @@ -24,7 +24,7 @@ import io.cloudbeaver.utils.WebTestUtils; import org.jkiss.code.NotNull; import org.jkiss.dbeaver.runtime.DBWorkbench; import org.jkiss.utils.SecurityUtils; -import org.junit.AfterClass; +import org.junit.jupiter.api.AfterAll; import java.net.CookieManager; import java.net.http.HttpClient; @@ -43,6 +43,9 @@ public class CEAppStarter { public static void startServerIfNotStarted() throws Exception { System.out.println("Start CBApplication"); + if (testApp != null) { + return; + } if (DBWorkbench.isPlatformStarted() && DBWorkbench.getPlatform().getApplication() instanceof CBApplication) { testApp = (CBApplication) DBWorkbench.getPlatform().getApplication(); return; @@ -66,7 +69,7 @@ public class CEAppStarter { } } - @AfterClass + @AfterAll public static void shutdownServer() { testApp.stop(); } diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/lsp/DBLTextDocumentServiceContextTest.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/lsp/DBLTextDocumentServiceContextTest.java index 783fdf8616..326f32d32b 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/lsp/DBLTextDocumentServiceContextTest.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/lsp/DBLTextDocumentServiceContextTest.java @@ -19,8 +19,8 @@ package io.cloudbeaver.model.lsp; import org.eclipse.lsp4j.*; import org.jkiss.dbeaver.ext.h2.model.H2SQLDialect; import org.jkiss.dbeaver.model.lsp.context.ContextAwareDocument; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -35,12 +35,12 @@ public class DBLTextDocumentServiceContextTest extends H2DataSourceTest { ); ContextAwareDocument contextedDocument = DocumentServiceTestUtils.getDocument(service, document.getUri()); - Assert.assertNotNull(contextedDocument); - Assert.assertEquals(dataSourceDescriptor.getDataSource(), contextedDocument.getDataSource()); - Assert.assertNotNull(contextedDocument.getExecutionContext()); - Assert.assertEquals(dataSourceDescriptor.getDataSource(), contextedDocument.getExecutionContext().getDataSource()); - Assert.assertTrue(contextedDocument.getSyntaxManager().getDialect() instanceof H2SQLDialect); - Assert.assertNotNull(contextedDocument.getRuleManager()); + Assertions.assertNotNull(contextedDocument); + Assertions.assertEquals(dataSourceDescriptor.getDataSource(), contextedDocument.getDataSource()); + Assertions.assertNotNull(contextedDocument.getExecutionContext()); + Assertions.assertEquals(dataSourceDescriptor.getDataSource(), contextedDocument.getExecutionContext().getDataSource()); + Assertions.assertTrue(contextedDocument.getSyntaxManager().getDialect() instanceof H2SQLDialect); + Assertions.assertNotNull(contextedDocument.getRuleManager()); } @Test @@ -69,14 +69,14 @@ public class DBLTextDocumentServiceContextTest extends H2DataSourceTest { profile->>'name' AS name; """.trim(); - Assert.assertEquals(expectedQuery.trim(), edit.getNewText()); + Assertions.assertEquals(expectedQuery.trim(), edit.getNewText()); Position start = edit.getRange().getStart(); - Assert.assertEquals(0, start.getLine()); - Assert.assertEquals(0, start.getCharacter()); + Assertions.assertEquals(0, start.getLine()); + Assertions.assertEquals(0, start.getCharacter()); Position end = edit.getRange().getEnd(); - Assert.assertEquals(1, end.getLine()); - Assert.assertEquals(97, end.getCharacter()); + Assertions.assertEquals(1, end.getLine()); + Assertions.assertEquals(97, end.getCharacter()); } @Test @@ -90,8 +90,8 @@ public class DBLTextDocumentServiceContextTest extends H2DataSourceTest { CompletionList completions = service.completion(completionParams).get().getRight(); - Assert.assertNotNull(completions); - Assert.assertTrue(completions.getItems().isEmpty()); + Assertions.assertNotNull(completions); + Assertions.assertTrue(completions.getItems().isEmpty()); } @Test @@ -105,9 +105,9 @@ public class DBLTextDocumentServiceContextTest extends H2DataSourceTest { CompletionList completions = service.completion(completionParams).get().getRight(); - Assert.assertNotNull(completions); - Assert.assertFalse(completions.getItems().isEmpty()); - Assert.assertEquals("SELECT", completions.getItems().getFirst().getLabel()); + Assertions.assertNotNull(completions); + Assertions.assertFalse(completions.getItems().isEmpty()); + Assertions.assertEquals("SELECT", completions.getItems().getFirst().getLabel()); } @Test @@ -124,8 +124,8 @@ public class DBLTextDocumentServiceContextTest extends H2DataSourceTest { CompletionList completions = service.completion(completionParams).get().getRight(); - Assert.assertNotNull(completions); - Assert.assertEquals(1, completions.getItems().size()); - Assert.assertEquals("FROM", completions.getItems().getFirst().getLabel()); + Assertions.assertNotNull(completions); + Assertions.assertEquals(1, completions.getItems().size()); + Assertions.assertEquals("FROM", completions.getItems().getFirst().getLabel()); } } diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/lsp/DBLTextDocumentServiceTest.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/lsp/DBLTextDocumentServiceTest.java index 8aac7f0da8..81e435af9d 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/lsp/DBLTextDocumentServiceTest.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/lsp/DBLTextDocumentServiceTest.java @@ -1,6 +1,6 @@ /* * DBeaver - Universal Database Manager - * Copyright (C) 2010-2025 DBeaver Corp and others + * Copyright (C) 2010-2026 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,9 @@ import org.jkiss.dbeaver.model.lsp.DBLTextDocumentService; import org.jkiss.dbeaver.model.lsp.context.ContextAwareDocument; import org.jkiss.dbeaver.model.sql.SQLSyntaxManager; import org.jkiss.dbeaver.model.sql.parser.SQLRuleManager; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.Objects; @@ -38,7 +38,7 @@ import java.util.concurrent.ExecutionException; public class DBLTextDocumentServiceTest extends CloudbeaverMockTest { private DBLTextDocumentService service; - @Before + @BeforeEach public void setUp() { service = new DBLTextDocumentService(); } @@ -55,9 +55,9 @@ public class DBLTextDocumentServiceTest extends CloudbeaverMockTest { service.didOpen(params); ContextAwareDocument document = DocumentServiceTestUtils.getDocument(service, uri); - Assert.assertNotNull(document); - Assert.assertEquals(document.getSyntaxManager().getDialect(), BasicSQLDialect.INSTANCE); - Assert.assertNull(document.getExecutionContext()); + Assertions.assertNotNull(document); + Assertions.assertEquals(document.getSyntaxManager().getDialect(), BasicSQLDialect.INSTANCE); + Assertions.assertNull(document.getExecutionContext()); } @Test @@ -67,14 +67,14 @@ public class DBLTextDocumentServiceTest extends CloudbeaverMockTest { service.didOpen(new DidOpenTextDocumentParams(textDocument)); ContextAwareDocument savedDocument = DocumentServiceTestUtils.getDocument(service, textDocument.getUri()); - Assert.assertNotNull(savedDocument); - Assert.assertEquals(query, savedDocument.getText()); + Assertions.assertNotNull(savedDocument); + Assertions.assertEquals(query, savedDocument.getText()); SQLSyntaxManager syntaxManager = savedDocument.getSyntaxManager(); - Assert.assertNotNull(syntaxManager); - Assert.assertEquals(BasicSQLDialect.INSTANCE, syntaxManager.getDialect()); + Assertions.assertNotNull(syntaxManager); + Assertions.assertEquals(BasicSQLDialect.INSTANCE, syntaxManager.getDialect()); SQLRuleManager ruleManager = savedDocument.getRuleManager(); - Assert.assertNotNull(ruleManager); + Assertions.assertNotNull(ruleManager); } @Test @@ -84,10 +84,10 @@ public class DBLTextDocumentServiceTest extends CloudbeaverMockTest { ContextAwareDocument savedDocument = Objects.requireNonNull(DocumentServiceTestUtils.getDocument(service, textDocument.getUri())); SQLSyntaxManager syntaxManager = savedDocument.getSyntaxManager(); - Assert.assertNotNull(syntaxManager); - Assert.assertEquals(BasicSQLDialect.INSTANCE, syntaxManager.getDialect()); + Assertions.assertNotNull(syntaxManager); + Assertions.assertEquals(BasicSQLDialect.INSTANCE, syntaxManager.getDialect()); SQLRuleManager ruleManager = savedDocument.getRuleManager(); - Assert.assertNotNull(ruleManager); + Assertions.assertNotNull(ruleManager); } @Test @@ -103,8 +103,8 @@ public class DBLTextDocumentServiceTest extends CloudbeaverMockTest { service.didChange(new DidChangeTextDocumentParams(textDocumentChange, contentChanges)); ContextAwareDocument updatedDocument = DocumentServiceTestUtils.getDocument(service, textDocument.getUri()); - Assert.assertNotNull(updatedDocument); - Assert.assertEquals(updatedSql, updatedDocument.getText()); + Assertions.assertNotNull(updatedDocument); + Assertions.assertEquals(updatedSql, updatedDocument.getText()); } @Test @@ -120,10 +120,10 @@ public class DBLTextDocumentServiceTest extends CloudbeaverMockTest { TextDocumentContentChangeEvent event2 = new TextDocumentContentChangeEvent(updatedSql2); List contentChanges = List.of(event1, event2); - Assert.assertThrows( - "Unexpected number of document changes: 2", + Assertions.assertThrows( IllegalArgumentException.class, - () -> service.didChange(new DidChangeTextDocumentParams(textDocumentChange, contentChanges)) + () -> service.didChange(new DidChangeTextDocumentParams(textDocumentChange, contentChanges)), + "Unexpected number of document changes: 2" ); } @@ -138,7 +138,7 @@ public class DBLTextDocumentServiceTest extends CloudbeaverMockTest { service.didClose(closeParams); ContextAwareDocument updatedDocument = DocumentServiceTestUtils.getDocument(service, textDocument.getUri()); - Assert.assertNull(updatedDocument); + Assertions.assertNull(updatedDocument); } @Test @@ -155,15 +155,15 @@ public class DBLTextDocumentServiceTest extends CloudbeaverMockTest { FROM tablename AS alias; """; - Assert.assertEquals(expectedQuery.trim(), textEdit.getNewText()); + Assertions.assertEquals(expectedQuery.trim(), textEdit.getNewText()); Position start = textEdit.getRange().getStart(); - Assert.assertEquals(0, start.getCharacter()); - Assert.assertEquals(0, start.getLine()); + Assertions.assertEquals(0, start.getCharacter()); + Assertions.assertEquals(0, start.getLine()); Position end = textEdit.getRange().getEnd(); - Assert.assertEquals(0, end.getLine()); - Assert.assertEquals(42, end.getCharacter()); + Assertions.assertEquals(0, end.getLine()); + Assertions.assertEquals(42, end.getCharacter()); } @Test @@ -190,15 +190,15 @@ public class DBLTextDocumentServiceTest extends CloudbeaverMockTest { schemaname3.tablename3 ; """.trim(); - Assert.assertEquals(expectedQuery.trim(), textEdit.getNewText()); + Assertions.assertEquals(expectedQuery.trim(), textEdit.getNewText()); Position start = textEdit.getRange().getStart(); - Assert.assertEquals(0, start.getCharacter()); - Assert.assertEquals(0, start.getLine()); + Assertions.assertEquals(0, start.getCharacter()); + Assertions.assertEquals(0, start.getLine()); Position end = textEdit.getRange().getEnd(); - Assert.assertEquals(3, end.getLine()); - Assert.assertEquals(1, end.getCharacter()); + Assertions.assertEquals(3, end.getLine()); + Assertions.assertEquals(1, end.getCharacter()); } @Test @@ -223,10 +223,10 @@ public class DBLTextDocumentServiceTest extends CloudbeaverMockTest { END $$; """.trim(); - Assert.assertEquals(expectedQuery.trim(), textEdit.getNewText()); + Assertions.assertEquals(expectedQuery.trim(), textEdit.getNewText()); Position end = textEdit.getRange().getEnd(); - Assert.assertEquals(1, end.getLine()); - Assert.assertEquals(63, end.getCharacter()); + Assertions.assertEquals(1, end.getLine()); + Assertions.assertEquals(63, end.getCharacter()); } @Test @@ -238,7 +238,7 @@ public class DBLTextDocumentServiceTest extends CloudbeaverMockTest { SemanticTokensParams params = new SemanticTokensParams(new TextDocumentIdentifier(document.getUri())); Integer[] tokensData = service.semanticTokensFull(params).get().getData().toArray(new Integer[0]); - Assert.assertArrayEquals( + Assertions.assertArrayEquals( new Integer[] {0, 0, 6, 0, 0}, tokensData ); @@ -259,7 +259,7 @@ public class DBLTextDocumentServiceTest extends CloudbeaverMockTest { 0, 23, 5, 0, 0, // WHERE 0, 39, 5, 1, 0 // 'Doe' }; - Assert.assertArrayEquals( + Assertions.assertArrayEquals( expectedData, tokensData ); @@ -286,7 +286,7 @@ public class DBLTextDocumentServiceTest extends CloudbeaverMockTest { 3, 0, 5, 0, 0, // WHERE 4, 14, 5, 1, 0 // 'Doe' }; - Assert.assertArrayEquals( + Assertions.assertArrayEquals( expectedData, tokensData ); diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/lsp/DBLTextDocumentServiceWorkspaceTest.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/lsp/DBLTextDocumentServiceWorkspaceTest.java index 6ff8ab8ac1..c85947a048 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/lsp/DBLTextDocumentServiceWorkspaceTest.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/lsp/DBLTextDocumentServiceWorkspaceTest.java @@ -25,9 +25,9 @@ import org.jkiss.dbeaver.model.lsp.DBLServerSessionProvider; import org.jkiss.dbeaver.model.lsp.DBLTextDocumentService; import org.jkiss.dbeaver.model.lsp.context.ContextAwareDocument; import org.jkiss.dbeaver.registry.DataSourceRegistry; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -35,12 +35,12 @@ public class DBLTextDocumentServiceWorkspaceTest extends H2DataSourceTest { private static final String PROJECT_ID = "DBLTextDocumentServiceProject"; private static final String DATA_SOURCE_ID = "workspace-test-data-source"; - private DBLTextDocumentService service = new DBLTextDocumentService(new TestSessionProvider()); + private DBLTextDocumentService service; protected DBPWorkspace workspace; protected DBPProject project; - @Before + @BeforeEach public void setUpWorkspace() { workspace = Mockito.mock(DBPWorkspace.class); project = Mockito.mock(DBPProject.class); @@ -71,7 +71,7 @@ public class DBLTextDocumentServiceWorkspaceTest extends H2DataSourceTest { service.didOpen(new DidOpenTextDocumentParams(document)); ContextAwareDocument contextAwareDocument = DocumentServiceTestUtils.getDocument(service, document.getUri()); - Assert.assertNotNull(contextAwareDocument); - Assert.assertEquals(dataSourceDescriptor.getDataSource(), contextAwareDocument.getDataSource()); + Assertions.assertNotNull(contextAwareDocument); + Assertions.assertEquals(dataSourceDescriptor.getDataSource(), contextAwareDocument.getDataSource()); } } diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/lsp/H2DataSourceTest.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/lsp/H2DataSourceTest.java index 8d8bcc7b34..cb99d167f2 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/lsp/H2DataSourceTest.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/lsp/H2DataSourceTest.java @@ -30,8 +30,8 @@ import org.jkiss.dbeaver.model.runtime.LoggingProgressMonitor; import org.jkiss.dbeaver.registry.DataSourceDescriptor; import org.jkiss.dbeaver.runtime.DBWorkbench; import org.jkiss.dbeaver.utils.PrefUtils; -import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import java.nio.file.Path; import java.sql.SQLException; @@ -45,7 +45,7 @@ public abstract class H2DataSourceTest extends CloudbeaverMockTest { protected DBLTextDocumentService service; - @Before + @BeforeEach public void setUp() throws DBException { PrefUtils.setDefaultPreferenceValue( DBWorkbench.getPlatform().getPreferenceStore(), @@ -64,11 +64,11 @@ public abstract class H2DataSourceTest extends CloudbeaverMockTest { ); try (JDBCStatement stmt = databaseSession.createStatement()) { - Assert.assertFalse(stmt.execute("CREATE TABLE TEST_TABLE1 (id IDENTITY NOT NULL PRIMARY KEY, a VARCHAR, b INT)")); - Assert.assertFalse(stmt.execute("CREATE TABLE TEST_TABLE2 (id IDENTITY NOT NULL PRIMARY KEY, a VARCHAR, b INT)")); + Assertions.assertFalse(stmt.execute("CREATE TABLE TEST_TABLE1 (id IDENTITY NOT NULL PRIMARY KEY, a VARCHAR, b INT)")); + Assertions.assertFalse(stmt.execute("CREATE TABLE TEST_TABLE2 (id IDENTITY NOT NULL PRIMARY KEY, a VARCHAR, b INT)")); for (int i = 0; i < 100; i++) { - Assert.assertFalse(stmt.execute("INSERT INTO TEST_TABLE1 (a, b) VALUES ('test" + i + "', " + i + ")")); - Assert.assertFalse(stmt.execute("INSERT INTO TEST_TABLE2 (a, b) VALUES ('test" + i + "', " + i + ")")); + Assertions.assertFalse(stmt.execute("INSERT INTO TEST_TABLE1 (a, b) VALUES ('test" + i + "', " + i + ")")); + Assertions.assertFalse(stmt.execute("INSERT INTO TEST_TABLE2 (a, b) VALUES ('test" + i + "', " + i + ")")); } } catch (SQLException e) { throw new IllegalStateException(e); diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/navigator/WebNavigatorNodeInfoTest.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/navigator/WebNavigatorNodeInfoTest.java index ec6d3762f5..1042a99352 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/navigator/WebNavigatorNodeInfoTest.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/navigator/WebNavigatorNodeInfoTest.java @@ -22,8 +22,8 @@ import io.cloudbeaver.service.navigator.WebNavigatorNodeInfo; import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode; import org.jkiss.dbeaver.model.navigator.DBNNode; import org.jkiss.dbeaver.model.struct.DBSObject; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; public class WebNavigatorNodeInfoTest extends CloudbeaverMockTest { @@ -44,13 +44,13 @@ public class WebNavigatorNodeInfoTest extends CloudbeaverMockTest { WebNavigatorNodeInfo info = new WebNavigatorNodeInfo(session, node); - Assert.assertEquals("node/path", info.getId()); - Assert.assertEquals("node://uri", info.getUri()); - Assert.assertEquals("NodeName", info.getName()); - Assert.assertEquals("A description", info.getDescription()); - Assert.assertEquals("nodeType", info.getNodeType()); - Assert.assertTrue(info.isHasChildren()); - Assert.assertEquals("node://uri", info.toString()); + Assertions.assertEquals("node/path", info.getId()); + Assertions.assertEquals("node://uri", info.getUri()); + Assertions.assertEquals("NodeName", info.getName()); + Assertions.assertEquals("A description", info.getDescription()); + Assertions.assertEquals("nodeType", info.getNodeType()); + Assertions.assertTrue(info.isHasChildren()); + Assertions.assertEquals("node://uri", info.toString()); } @Test @@ -66,11 +66,11 @@ public class WebNavigatorNodeInfoTest extends CloudbeaverMockTest { WebNavigatorNodeInfo info = new WebNavigatorNodeInfo(session, dbNode); - Assert.assertNotNull(info.getObject()); - Assert.assertEquals("DBNodeName", info.getName()); + Assertions.assertNotNull(info.getObject()); + Assertions.assertEquals("DBNodeName", info.getName()); Mockito.when(session.getLocale()).thenReturn("es"); - Assert.assertEquals("DBNodeName1", info.getName()); + Assertions.assertEquals("DBNodeName1", info.getName()); } diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/rm/RMNIOTest.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/rm/RMNIOTest.java index 62f4f8e2d1..9c617f0eae 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/rm/RMNIOTest.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/rm/RMNIOTest.java @@ -29,10 +29,10 @@ import org.jkiss.dbeaver.model.data.json.JSONUtils; import org.jkiss.dbeaver.model.rm.RMController; import org.jkiss.dbeaver.model.rm.RMProject; import org.jkiss.utils.SecurityUtils; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.net.URI; @@ -49,22 +49,22 @@ public class RMNIOTest extends CloudbeaverMockTest { private static RMProject testProject; private static RMNIOFileSystemProvider rmFsProvider; - @BeforeClass + @BeforeAll public static void init() throws Exception { CEAppStarter.startServerIfNotStarted(); WebGQLClient client = CEAppStarter.createClient(); Map authInfo = CEAppStarter.authenticateTestUser(client); - Assert.assertEquals(SMAuthStatus.SUCCESS.name(), JSONUtils.getString(authInfo, "authStatus")); + Assertions.assertEquals(SMAuthStatus.SUCCESS.name(), JSONUtils.getString(authInfo, "authStatus")); String sessionId = client.getSessionIdCookie(); webSession = (WebSession) CEAppStarter.getTestApp().getSessionManager().getSession(sessionId); - Assert.assertNotNull(webSession); + Assertions.assertNotNull(webSession); var projectName = "NIO_Test" + SecurityUtils.generateUniqueId(); testProject = webSession.getRmController().createProject(projectName, null); rmFsProvider = new RMNIOFileSystemProvider(webSession.getRmController()); } - @AfterClass + @AfterAll public static void destroy() throws Exception { if (webSession != null && testProject != null) { webSession.getUserContext().getRmController().deleteProject(testProject.getId()); @@ -75,19 +75,19 @@ public class RMNIOTest extends CloudbeaverMockTest { public void projectPathTest() throws DBException { var projectUri = getProjectUri(); RMPath path = (RMPath) rmFsProvider.getPath(projectUri); - Assert.assertEquals(path.getRmProjectId(), testProject.getId()); - Assert.assertTrue(path.isProjectPath()); - Assert.assertTrue(path.isAbsolute()); - Assert.assertNull(path.getParent()); - Assert.assertNull(path.getRoot()); - Assert.assertTrue(Files.isDirectory(path)); - Assert.assertTrue(Files.exists(path)); + Assertions.assertEquals(path.getRmProjectId(), testProject.getId()); + Assertions.assertTrue(path.isProjectPath()); + Assertions.assertTrue(path.isAbsolute()); + Assertions.assertNull(path.getParent()); + Assertions.assertNull(path.getRoot()); + Assertions.assertTrue(Files.isDirectory(path)); + Assertions.assertTrue(Files.exists(path)); } @Test public void testNotExistProject() { RMPath notExistPath = new RMPath(new RMNIOFileSystem("s_not_exist", rmFsProvider)); - Assert.assertFalse(Files.exists(notExistPath)); + Assertions.assertFalse(Files.exists(notExistPath)); } @Test @@ -96,17 +96,17 @@ public class RMNIOTest extends CloudbeaverMockTest { String randomProject = "s_random_project_" + randomName; RMPath newProjectPath = new RMPath(new RMNIOFileSystem(randomProject, rmFsProvider)); - Assert.assertFalse(Files.exists(newProjectPath)); + Assertions.assertFalse(Files.exists(newProjectPath)); //create project via nio Files.createDirectory(newProjectPath); - Assert.assertTrue(Files.exists(newProjectPath)); - Assert.assertNotNull(webSession.getRmController().getProject(randomProject, false, false)); + Assertions.assertTrue(Files.exists(newProjectPath)); + Assertions.assertNotNull(webSession.getRmController().getProject(randomProject, false, false)); //delete project via nio Files.delete(newProjectPath); - Assert.assertFalse(Files.exists(newProjectPath)); - Assert.assertNull(webSession.getRmController().getProject(randomProject, false, false)); + Assertions.assertFalse(Files.exists(newProjectPath)); + Assertions.assertNull(webSession.getRmController().getProject(randomProject, false, false)); } @Test @@ -114,7 +114,7 @@ public class RMNIOTest extends CloudbeaverMockTest { RMPath rootPath = (RMPath) rmFsProvider.getPath(getProjectUri()); String scriptName = "child.sql"; Path scriptPath = rootPath.resolve(scriptName); - Assert.assertEquals(getProjectUri() + "/" + "child.sql", scriptPath.toString()); + Assertions.assertEquals(getProjectUri() + "/" + "child.sql", scriptPath.toString()); } @Test @@ -130,8 +130,8 @@ public class RMNIOTest extends CloudbeaverMockTest { list .map(path -> ((RMPath) path).getResourcePath()) .collect(Collectors.toSet()); - Assert.assertTrue(filesFromNio.contains(file1)); - Assert.assertTrue(filesFromNio.contains(file2)); + Assertions.assertTrue(filesFromNio.contains(file1)); + Assertions.assertTrue(filesFromNio.contains(file2)); } } @@ -144,8 +144,8 @@ public class RMNIOTest extends CloudbeaverMockTest { //create file Files.createFile(scriptPath); - Assert.assertTrue(Files.exists(scriptPath)); - Assert.assertNotNull(rm.getResource(testProject.getId(), script)); + Assertions.assertTrue(Files.exists(scriptPath)); + Assertions.assertNotNull(rm.getResource(testProject.getId(), script)); //set content rm://s_test_project/test_script.sql @@ -153,13 +153,13 @@ public class RMNIOTest extends CloudbeaverMockTest { Files.writeString(scriptPath, sql); String dataFromNio = Files.readString(scriptPath); String dataFromRM = new String(rm.getResourceContents(testProject.getId(), script)); - Assert.assertEquals(sql, dataFromNio); - Assert.assertEquals(sql, dataFromRM); + Assertions.assertEquals(sql, dataFromNio); + Assertions.assertEquals(sql, dataFromRM); //delete Files.delete(scriptPath); - Assert.assertFalse(Files.exists(scriptPath)); - Assert.assertNull(rm.getResource(testProject.getId(), script)); + Assertions.assertFalse(Files.exists(scriptPath)); + Assertions.assertNull(rm.getResource(testProject.getId(), script)); } diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/rm/lock/RMLockTest.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/rm/lock/RMLockTest.java index a92f0a701b..a1f8dd0b4a 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/rm/lock/RMLockTest.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/rm/lock/RMLockTest.java @@ -1,6 +1,6 @@ /* * DBeaver - Universal Database Manager - * Copyright (C) 2010-2025 DBeaver Corp and others + * Copyright (C) 2010-2026 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,10 @@ package io.cloudbeaver.model.rm.lock; import io.cloudbeaver.CloudbeaverMockTest; import io.cloudbeaver.app.CEAppStarter; import org.jkiss.dbeaver.Log; -import org.junit.*; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -35,16 +38,17 @@ public class RMLockTest extends CloudbeaverMockTest { private static final Log log = Log.getLog(RMLockTest.class); private final String project1 = "s_fakeProject1"; private final String project2 = "s_fakeProject2"; - private static final ExecutorService executor = Executors.newFixedThreadPool(2); + private static ExecutorService executor; - @AfterClass - public static void shutdown() { - executor.shutdown(); - } - - @BeforeClass + @BeforeAll public static void startServer() throws Exception { CEAppStarter.startServerIfNotStarted(); + executor = Executors.newFixedThreadPool(2); + } + + @AfterAll + public static void shutdown() { + executor.shutdown(); } @Test @@ -90,8 +94,8 @@ public class RMLockTest extends CloudbeaverMockTest { Runnable runnable2 = () -> { try { thread2CDL.await(1, TimeUnit.MINUTES); - Assert.assertTrue("Project not locket by thread 1", isLockedByThread1.get()); - Assert.assertTrue("Project not locked", lockController2.isFileLocked(project1)); + Assertions.assertTrue(isLockedByThread1.get(), "Project not locket by thread 1"); + Assertions.assertTrue(lockController2.isFileLocked(project1), "Project not locked"); try (var lock = lockController2.lock(project1, "testThatProjectLocked2")) { //that we were really waiting for the file and the lock was not removed earlier Mockito.verify(lockController2, Mockito.atLeast(atLeastWaitCalls)).awaitingUnlock(Mockito.any()); @@ -110,7 +114,7 @@ public class RMLockTest extends CloudbeaverMockTest { if (exceptionReference.get() != null) { throw exceptionReference.get(); } - Assert.assertFalse(lockController2.isFileLocked(project1)); + Assertions.assertFalse(lockController2.isFileLocked(project1)); } @Test @@ -130,7 +134,7 @@ public class RMLockTest extends CloudbeaverMockTest { isLockedByThread1.set(true); thread2InitCDL.countDown(); thread1CDL.await(1, TimeUnit.MINUTES); - Assert.assertTrue("Project2 not locked by thread2", isLockedByThread2.get()); + Assertions.assertTrue(isLockedByThread2.get(), "Project2 not locked by thread2"); thread2CDL.countDown(); } catch (Throwable e) { log.error(e); @@ -146,7 +150,7 @@ public class RMLockTest extends CloudbeaverMockTest { try { try (var lock = lockController2.lock(project2, "testAccessToDifferentProjects2")) { thread2InitCDL.await(); - Assert.assertTrue("Project1 not locket by thread1", isLockedByThread1.get()); + Assertions.assertTrue(isLockedByThread1.get(), "Project1 not locket by thread1"); isLockedByThread2.set(true); thread1CDL.countDown(); thread2CDL.await(); @@ -167,8 +171,8 @@ public class RMLockTest extends CloudbeaverMockTest { throw exceptionReference.get(); } - Assert.assertFalse(lockController2.isFileLocked(project1)); - Assert.assertFalse(lockController2.isFileLocked(project2)); + Assertions.assertFalse(lockController2.isFileLocked(project1)); + Assertions.assertFalse(lockController2.isFileLocked(project2)); } @Test @@ -197,7 +201,7 @@ public class RMLockTest extends CloudbeaverMockTest { Runnable runnable2 = () -> { try { try (var lock = lockController2.lock(project1, "testForceUnlock2")) { - Assert.assertTrue("Project1 not locket by thread1", isLockedByThread1.get()); + Assertions.assertTrue(isLockedByThread1.get(), "Project1 not locket by thread1"); Mockito.verify(lockController2, Mockito.atLeast(5)).isLocked(Mockito.any()); thread1CDL.countDown(); } @@ -215,6 +219,6 @@ public class RMLockTest extends CloudbeaverMockTest { if (exceptionReference.get() != null) { throw exceptionReference.get(); } - Assert.assertFalse(lockController2.isFileLocked(project1)); + Assertions.assertFalse(lockController2.isFileLocked(project1)); } } diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/session/WebSessionProjectTest.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/session/WebSessionProjectTest.java index 9afcdeee61..3662425e32 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/session/WebSessionProjectTest.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/session/WebSessionProjectTest.java @@ -29,9 +29,9 @@ import org.jkiss.dbeaver.model.rm.RMProjectType; import org.jkiss.dbeaver.model.websocket.event.datasource.WSDataSourceEvent; import org.jkiss.dbeaver.model.websocket.event.datasource.WSDataSourceProperty; import org.jkiss.dbeaver.registry.DataSourceDescriptor; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.Mockito; @@ -44,7 +44,7 @@ public class WebSessionProjectTest extends CloudbeaverMockTest { private RMProject rmProject; - @Before + @BeforeEach public void setUp() throws Exception { var sessionContext = Mockito.mock(SMSessionContext.class); Mockito.when(webSession.getSessionContext()).thenReturn(sessionContext); @@ -69,14 +69,14 @@ public class WebSessionProjectTest extends CloudbeaverMockTest { // add connection var info = project.addConnection(ds); - Assert.assertNotNull(info); + Assertions.assertNotNull(info); var fetched = project.findWebConnectionInfo("ds1"); - Assert.assertNotNull(fetched); - Assert.assertEquals("ds1", fetched.getDataSourceContainer().getId()); + Assertions.assertNotNull(fetched); + Assertions.assertEquals("ds1", fetched.getDataSourceContainer().getId()); // remove connection project.removeConnection(ds); - Assert.assertNull(project.findWebConnectionInfo("ds1")); + Assertions.assertNull(project.findWebConnectionInfo("ds1")); } @Test @@ -91,7 +91,7 @@ public class WebSessionProjectTest extends CloudbeaverMockTest { return registry; } }; - Assert.assertThrows(DBWebException.class, () -> project.getWebConnectionInfo("missing")); + Assertions.assertThrows(DBWebException.class, () -> project.getWebConnectionInfo("missing")); } @Test @@ -115,9 +115,9 @@ public class WebSessionProjectTest extends CloudbeaverMockTest { List connections = project.getConnections(); Mockito.verify(registry, Mockito.times(1)).getDataSources(); - Assert.assertNotNull(connections); - Assert.assertEquals(1, connections.size()); - Assert.assertEquals("ds1", project.getConnections().getFirst().getDataSourceContainer().getId()); + Assertions.assertNotNull(connections); + Assertions.assertEquals(1, connections.size()); + Assertions.assertEquals("ds1", project.getConnections().getFirst().getDataSourceContainer().getId()); } @Test @@ -140,10 +140,10 @@ public class WebSessionProjectTest extends CloudbeaverMockTest { Mockito.when(event.getDataSourceIds()).thenReturn(List.of("ds1")); boolean res = project.updateProjectDataSources(event); - Assert.assertTrue(res); + Assertions.assertTrue(res); var info = project.findWebConnectionInfo("ds1"); - Assert.assertNotNull(info); - Assert.assertEquals("ds1", info.getDataSourceContainer().getId()); + Assertions.assertNotNull(info); + Assertions.assertEquals("ds1", info.getDataSourceContainer().getId()); } @@ -164,20 +164,20 @@ public class WebSessionProjectTest extends CloudbeaverMockTest { } }; - Assert.assertNotNull(project.getConnections()); + Assertions.assertNotNull(project.getConnections()); WSDataSourceEvent event = Mockito.mock(WSDataSourceEvent.class); Mockito.when(event.getId()).thenReturn(WSDataSourceEvent.UPDATED); Mockito.when(event.getDataSourceIds()).thenReturn(List.of("ds1")); Mockito.when(event.getProperty()).thenReturn(WSDataSourceProperty.NAME); - Assert.assertTrue(project.updateProjectDataSources(event)); + Assertions.assertTrue(project.updateProjectDataSources(event)); var info = project.findWebConnectionInfo("ds1"); - Assert.assertNotNull(info); - Assert.assertEquals("ds1", info.getDataSourceContainer().getId()); + Assertions.assertNotNull(info); + Assertions.assertEquals("ds1", info.getDataSourceContainer().getId()); Mockito.when(event.getProperty()).thenReturn(WSDataSourceProperty.INTERNAL); - Assert.assertFalse(project.updateProjectDataSources(event)); + Assertions.assertFalse(project.updateProjectDataSources(event)); } @@ -204,8 +204,8 @@ public class WebSessionProjectTest extends CloudbeaverMockTest { Mockito.when(event.getDataSourceIds()).thenReturn(List.of("ds1")); boolean res = project.updateProjectDataSources(event); - Assert.assertTrue(res); - Assert.assertNull(project.findWebConnectionInfo("ds1")); + Assertions.assertTrue(res); + Assertions.assertNull(project.findWebConnectionInfo("ds1")); } @Test @@ -226,8 +226,8 @@ public class WebSessionProjectTest extends CloudbeaverMockTest { Mockito.when(event.getDataSourceIds()).thenReturn(List.of("ds1")); boolean res = project.updateProjectDataSources(event); - Assert.assertFalse(res); - Assert.assertNull(project.findWebConnectionInfo("ds1")); + Assertions.assertFalse(res); + Assertions.assertNull(project.findWebConnectionInfo("ds1")); } @Test @@ -253,9 +253,9 @@ public class WebSessionProjectTest extends CloudbeaverMockTest { // when registry is marked as loaded, it should not be queried again Mockito.verify(registry, Mockito.never()).getDataSources(); - Assert.assertNotNull(connections); - Assert.assertEquals(1, connections.size()); - Assert.assertEquals("ds1", project.getConnections().getFirst().getDataSourceContainer().getId()); + Assertions.assertNotNull(connections); + Assertions.assertEquals(1, connections.size()); + Assertions.assertEquals("ds1", project.getConnections().getFirst().getDataSourceContainer().getId()); } } diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/session/WebSessionTest.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/session/WebSessionTest.java index 5c8aff73e7..5ff57b5c25 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/session/WebSessionTest.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/model/session/WebSessionTest.java @@ -22,9 +22,9 @@ import io.cloudbeaver.model.app.ServletAuthApplication; import org.jkiss.dbeaver.model.websocket.event.WSEventController; import org.jkiss.utils.function.ThrowableConsumer; import org.jkiss.utils.function.ThrowableFunction; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.Collections; @@ -35,7 +35,7 @@ public class WebSessionTest extends CloudbeaverMockTest { private WebSession session; - @Before + @BeforeEach public void initWebSession() throws Exception { session = new WebSession(getFakeRequestInfo(), mockApplication(), Collections.emptyMap()); } @@ -44,13 +44,13 @@ public class WebSessionTest extends CloudbeaverMockTest { public void localeAndBasicAttributes() throws Exception { // Locale session.setLocale("test-locale"); - Assert.assertEquals("test-locale", session.getLocale()); + Assertions.assertEquals("test-locale", session.getLocale()); session.setLocale(null); - Assert.assertEquals(Locale.getDefault().getLanguage(), session.getLocale()); + Assertions.assertEquals(Locale.getDefault().getLanguage(), session.getLocale()); // Persistent attribute must survive reset/close session.setAttribute("persistentKey", "persistValue", true); - Assert.assertEquals("persistValue", session.getAttribute("persistentKey")); + Assertions.assertEquals("persistValue", session.getAttribute("persistentKey")); // Non-persistent attribute created via getAttribute with creator/disposer AtomicBoolean disposed = new AtomicBoolean(false); @@ -60,24 +60,23 @@ public class WebSessionTest extends CloudbeaverMockTest { }; String created = session.getAttribute("createdKey", creator, disposer); - Assert.assertEquals("created", created); + Assertions.assertEquals("created", created); // persistent attribute should still be available - Assert.assertEquals("persistValue", session.getAttribute("persistentKey")); + Assertions.assertEquals("persistValue", session.getAttribute("persistentKey")); session.close(); // persistent attribute should иу тгдд - Assert.assertNull("persistValue", session.getAttribute("persistentKey")); - - Assert.assertTrue("disposer must be invoked during close()", disposed.get()); + Assertions.assertNull(session.getAttribute("persistentKey"), "persistValue"); + Assertions.assertTrue(disposed.get(), "disposer must be invoked during close()"); } @Test public void asyncTaskStatusNotFound() throws Exception { - Assert.assertThrows( - "DBWebException must be thrown for unknown async task", - DBWebException.class, () -> session.asyncTaskStatus("nonexistent-task", false) + Assertions.assertThrows( + DBWebException.class, () -> session.asyncTaskStatus("nonexistent-task", false), + "DBWebException must be thrown for unknown async task" ); } diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/AuthenticationTest.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/AuthenticationTest.java index d24d611a50..df0827b755 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/AuthenticationTest.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/AuthenticationTest.java @@ -25,8 +25,8 @@ import org.jkiss.code.NotNull; import org.jkiss.dbeaver.model.auth.SMAuthStatus; import org.jkiss.dbeaver.model.data.json.JSONUtils; import org.jkiss.utils.SecurityUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; @@ -56,7 +56,7 @@ public class AuthenticationTest extends CloudbeaverMockTest { public void testLoginUser() throws Exception { WebGQLClient client = CEAppStarter.createClient(); Map authInfo = CEAppStarter.authenticateTestUser(client); - Assert.assertEquals(SMAuthStatus.SUCCESS.name(), JSONUtils.getString(authInfo, "authStatus")); + Assertions.assertEquals(SMAuthStatus.SUCCESS.name(), JSONUtils.getString(authInfo, "authStatus")); } @@ -67,14 +67,14 @@ public class AuthenticationTest extends CloudbeaverMockTest { Map credsWithCamelCase = getUserCredentials(userId); // authenticating with user Map authInfo = CEAppStarter.authenticateTestUser(client, credsWithCamelCase); - Assert.assertEquals(SMAuthStatus.SUCCESS.name(), JSONUtils.getString(authInfo, "authStatus")); + Assertions.assertEquals(SMAuthStatus.SUCCESS.name(), JSONUtils.getString(authInfo, "authStatus")); Map activeUser = client.sendQuery(GQL_ACTIVE_USER, null); - Assert.assertEquals(userId.toLowerCase(), JSONUtils.getString(activeUser, "userId")); + Assertions.assertEquals(userId.toLowerCase(), JSONUtils.getString(activeUser, "userId")); // making logout client.sendQuery(GQL_AUTH_LOGOUT, Map.of("provider", "local")); activeUser = client.sendQuery(GQL_ACTIVE_USER, null); - Assert.assertNotEquals(userId.toLowerCase(), JSONUtils.getString(activeUser, "userId")); + Assertions.assertNotEquals(userId.toLowerCase(), JSONUtils.getString(activeUser, "userId")); } } @@ -95,9 +95,9 @@ public class AuthenticationTest extends CloudbeaverMockTest { headers.put(RPAuthProvider.X_USER, testUserId); headers.put(RPAuthProvider.X_TEAM, "user"); Map sessionInfo = client.sendQueryWithHeaders(GQL_OPEN_SESSION, null, headers); - Assert.assertTrue(JSONUtils.getBoolean(sessionInfo, "valid")); + Assertions.assertTrue(JSONUtils.getBoolean(sessionInfo, "valid")); Map activeUser = client.sendQuery(GQL_ACTIVE_USER, null); - Assert.assertEquals(testUserId, JSONUtils.getString(activeUser, "userId")); + Assertions.assertEquals(testUserId, JSONUtils.getString(activeUser, "userId")); } } diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/CBEventsLongPollingServletTest.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/CBEventsLongPollingServletTest.java index e7a0f8e35c..1ab392c1b4 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/CBEventsLongPollingServletTest.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/CBEventsLongPollingServletTest.java @@ -29,9 +29,9 @@ import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.model.websocket.WSConstants; import org.jkiss.utils.CommonUtils; import org.jkiss.utils.HttpConstants; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; @@ -47,7 +47,7 @@ public class CBEventsLongPollingServletTest extends CloudbeaverMockTest { @Mock WebHeadlessSession headlessSession; - @Before + @BeforeEach public void initMocks() { request = Mockito.mock(HttpServletRequest.class); sessionManager = Mockito.mock(WebAppSessionManager.class); @@ -98,7 +98,7 @@ public class CBEventsLongPollingServletTest extends CloudbeaverMockTest { BaseWebSession resolved = invokeResolve(new TestServlet(), request); - Assert.assertSame(headlessSession, resolved); + Assertions.assertSame(headlessSession, resolved); } @Test @@ -111,7 +111,7 @@ public class CBEventsLongPollingServletTest extends CloudbeaverMockTest { ArgumentMatchers.any(), ArgumentMatchers.anyBoolean())) .thenReturn(null); - Assert.assertNull(invokeResolve(new TestServlet(), request)); + Assertions.assertNull(invokeResolve(new TestServlet(), request)); } @Test @@ -125,7 +125,7 @@ public class CBEventsLongPollingServletTest extends CloudbeaverMockTest { ArgumentMatchers.any(WebHttpRequestInfo.class), ArgumentMatchers.eq(true))) .thenThrow(new RuntimeException("Get HeadlessSession failed")); - Assert.assertNull(invokeResolve(new TestServlet(), request)); + Assertions.assertNull(invokeResolve(new TestServlet(), request)); } private BaseWebSession invokeResolve(TestServlet servlet, HttpServletRequest req) { diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/CEServerTestSuite.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/CEServerTestSuite.java index 55abc4d694..fa13299c88 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/CEServerTestSuite.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/CEServerTestSuite.java @@ -1,6 +1,6 @@ /* * DBeaver - Universal Database Manager - * Copyright (C) 2010-2025 DBeaver Corp and others + * Copyright (C) 2010-2026 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,13 +23,13 @@ import io.cloudbeaver.model.rm.RMNIOTest; import io.cloudbeaver.model.rm.lock.RMLockTest; import io.cloudbeaver.model.session.WebSessionProjectTest; import io.cloudbeaver.model.session.WebSessionTest; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; -@RunWith(Suite.class) -@Suite.SuiteClasses( +@Suite +@SelectClasses( { ConnectionsTest.class, SQLQueryTranslatorTest.class, @@ -45,12 +45,12 @@ import org.junit.runners.Suite; ) public class CEServerTestSuite { - @BeforeClass + @BeforeAll public static void startServer() throws Exception { CEAppStarter.startServerIfNotStarted(); } - @AfterClass + @AfterAll public static void shutdownServer() { CEAppStarter.shutdownServer(); } diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/ConnectionsTest.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/ConnectionsTest.java index ebda986a10..4f5de15232 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/ConnectionsTest.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/ConnectionsTest.java @@ -1,6 +1,6 @@ /* * DBeaver - Universal Database Manager - * Copyright (C) 2010-2024 DBeaver Corp and others + * Copyright (C) 2010-2026 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,8 @@ import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.model.data.json.JSONUtils; import org.jkiss.dbeaver.runtime.DBWorkbench; import org.jkiss.dbeaver.utils.GeneralUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.nio.file.Path; import java.util.LinkedHashMap; @@ -82,24 +82,24 @@ public class ConnectionsTest extends CloudbeaverMockTest { Map configuration = new LinkedHashMap<>(); Map variables = new LinkedHashMap<>(); variables.put("config", configuration); - Assert.assertThrows( - "Template connection or driver must be specified", + Assertions.assertThrows( DBException.class, - () -> client.sendQuery(GQL_CONNECTIONS_CREATE, variables) + () -> client.sendQuery(GQL_CONNECTIONS_CREATE, variables), + "Template connection or driver must be specified" ); String templateId = "test_template"; configuration.put("templateId", templateId); - Assert.assertThrows( - "Template connection '" + templateId + "' not found", + Assertions.assertThrows( DBException.class, - () -> client.sendQuery(GQL_CONNECTIONS_CREATE, variables) + () -> client.sendQuery(GQL_CONNECTIONS_CREATE, variables), + "Template connection '" + templateId + "' not found" ); configuration.remove("templateId"); configuration.put("driverId", "postgresql:postgres-jdbc"); Map addedConnection = client.sendQuery(GQL_CONNECTIONS_CREATE, variables); - Assert.assertNotNull(addedConnection); + Assertions.assertNotNull(addedConnection); checkAddedConnection(client, addedConnection); String addedConnectionId = JSONUtils.getString(addedConnection, "id"); @@ -111,24 +111,26 @@ public class ConnectionsTest extends CloudbeaverMockTest { variables1.put("config", config1); variables1.put("nodePath", nodePath); - Assert.assertThrows( + Assertions.assertThrows( DBException.class, () -> client.sendQuery(GQL_COPY_CONNECTION_FROM_NODE, variables1) ); variables1.put("projectId", "u_test"); Map copiedConnection = client.sendQuery(GQL_COPY_CONNECTION_FROM_NODE, variables1); - Assert.assertNotNull(copiedConnection); + Assertions.assertNotNull(copiedConnection); checkAddedConnection(client, copiedConnection); String copiedConnectionId = JSONUtils.getString(copiedConnection, "id"); - Assert.assertTrue(client.sendQuery(GQL_CONNECTIONS_DELETE, Map.of("id", addedConnectionId))); - Assert.assertTrue(client.sendQuery(GQL_CONNECTIONS_DELETE, Map.of("id", copiedConnectionId))); + Boolean deleted1 = client.sendQuery(GQL_CONNECTIONS_DELETE, Map.of("id", addedConnectionId)); + Assertions.assertTrue(deleted1); + Boolean deleted2 = client.sendQuery(GQL_CONNECTIONS_DELETE, Map.of("id", copiedConnectionId)); + Assertions.assertTrue(deleted2); } private void checkAddedConnection(@NotNull WebGQLClient client, @NotNull Map addedConnection) throws Exception { List> connections = client.sendQuery(GQL_CONNECTIONS_GET, null); - Assert.assertTrue(connections.contains(addedConnection)); - Assert.assertNotNull(JSONUtils.getString(addedConnection, "id")); + Assertions.assertTrue(connections.contains(addedConnection)); + Assertions.assertNotNull(JSONUtils.getString(addedConnection, "id")); String nodePath = JSONUtils.getString(addedConnection, "nodePath"); - Assert.assertNotNull(nodePath); + Assertions.assertNotNull(nodePath); } } diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/NoSessionTest.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/NoSessionTest.java index bf7d4ff75d..989b789620 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/NoSessionTest.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/NoSessionTest.java @@ -18,8 +18,8 @@ package io.cloudbeaver.test.platform; import io.cloudbeaver.CloudbeaverMockTest; import io.cloudbeaver.app.CEAppStarter; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.net.CookieManager; import java.net.URI; @@ -44,6 +44,6 @@ public class NoSessionTest extends CloudbeaverMockTest { httpClient.send(request, HttpResponse.BodyHandlers.ofByteArray()); - Assert.assertTrue(cookieManager.getCookieStore().getCookies().isEmpty()); + Assertions.assertTrue(cookieManager.getCookieStore().getCookies().isEmpty()); } } diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/ResourceManagerTest.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/ResourceManagerTest.java index 443733587c..144bec249f 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/ResourceManagerTest.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/ResourceManagerTest.java @@ -1,6 +1,6 @@ /* * DBeaver - Universal Database Manager - * Copyright (C) 2010-2024 DBeaver Corp and others + * Copyright (C) 2010-2026 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,9 +27,9 @@ import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.model.auth.SMAuthStatus; import org.jkiss.dbeaver.model.data.json.JSONUtils; import org.jkiss.utils.IOUtils; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.nio.file.Path; import java.util.Map; @@ -68,34 +68,34 @@ public class ResourceManagerTest extends CloudbeaverMockTest { } }"""; - @BeforeClass + @BeforeAll public static void init() throws Exception { - Assert.assertTrue(CBApplication.getInstance().getAppConfiguration().isResourceManagerEnabled()); + Assertions.assertTrue(CBApplication.getInstance().getAppConfiguration().isResourceManagerEnabled()); client = CEAppStarter.createClient(); Map authInfo = CEAppStarter.authenticateTestUser(client); - Assert.assertEquals(SMAuthStatus.SUCCESS.name(), JSONUtils.getString(authInfo, "authStatus")); + Assertions.assertEquals(SMAuthStatus.SUCCESS.name(), JSONUtils.getString(authInfo, "authStatus")); } @Test public void createDeleteResourceTest() throws Exception { String projectId = "u_test"; String resourcePath = "testScript.sql"; - Assert.assertTrue(createResource(projectId, resourcePath, false)); - Assert.assertThrows( - "Resource '" + IOUtils.getFileNameWithoutExtension(Path.of(resourcePath)) + "' already exists", + Assertions.assertTrue(createResource(projectId, resourcePath, false)); + Assertions.assertThrows( DBException.class, - () -> createResource(projectId, resourcePath, false) + () -> createResource(projectId, resourcePath, false), + "Resource '" + IOUtils.getFileNameWithoutExtension(Path.of(resourcePath)) + "' already exists" ); - Assert.assertTrue(createResource(projectId, resourcePath, true)); - Assert.assertTrue(deleteResource(projectId, resourcePath)); + Assertions.assertTrue(createResource(projectId, resourcePath, true)); + Assertions.assertTrue(deleteResource(projectId, resourcePath)); } @Test public void listResourcesWithInvalidProjectId() throws Exception { - Assert.assertThrows( - "Project id is empty", + Assertions.assertThrows( DBException.class, - () -> client.sendQuery(GQL_RESOURCES_LIST, Map.of("projectId", "")) + () -> client.sendQuery(GQL_RESOURCES_LIST, Map.of("projectId", "")), + "Project id is empty" ); } diff --git a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/SQLQueryTranslatorTest.java b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/SQLQueryTranslatorTest.java index 849699a9fd..97640d69e1 100644 --- a/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/SQLQueryTranslatorTest.java +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/test/platform/SQLQueryTranslatorTest.java @@ -29,8 +29,8 @@ import org.jkiss.dbeaver.model.sql.SQLDialect; import org.jkiss.dbeaver.model.sql.translate.SQLQueryTranslator; import org.jkiss.dbeaver.runtime.DBWorkbench; import org.jkiss.dbeaver.utils.GeneralUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.LinkedHashMap; @@ -208,10 +208,10 @@ public class SQLQueryTranslatorTest extends CloudbeaverMockTest { preferenceStore, basicSql ); - Assert.assertEquals( - entry.getKey().getDialectId() + " has invalid syntax " + translated, + Assertions.assertEquals( normalizeScript(entry.getValue()), - normalizeScript(translated) + normalizeScript(translated), + entry.getKey().getDialectId() + " has invalid syntax " + translated ); } } diff --git a/server/test/pom.xml b/server/test/pom.xml index 26b4da16e8..e214dc1661 100644 --- a/server/test/pom.xml +++ b/server/test/pom.xml @@ -58,6 +58,7 @@ io.cloudbeaver.product.ce.application io.cloudbeaver.product.ce.product default + junit6 io.cloudbeaver.test.platform.CEServerTestSuite -web-config workspace/conf/cloudbeaver.conf