Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,54 @@
/*
* 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",
args = {"-web-config", "workspace/conf/cloudbeaver.conf"},
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";

Check warning on line 51 in server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/CloudbeaverMockTest.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 'VARIABLE_DEF' should be separated from previous line. Raw Output: /github/workspace/./server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/CloudbeaverMockTest.java:51:5: warning: 'VARIABLE_DEF' should be separated from previous line. (com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck)
private static final String SERVER_STATUS_URL = "http://localhost:18978/status";
private final HttpClient httpClient = HttpClient.newBuilder()
.cookieHandler(new CookieManager())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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;
Expand All @@ -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;
Expand All @@ -66,7 +69,7 @@ public static void startServerIfNotStarted() throws Exception {
}
}

@AfterClass
@AfterAll
public static void shutdownServer() {
testApp.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
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;
Expand All @@ -35,12 +35,12 @@ public void shouldInitH2Context() {
);

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
Expand Down Expand Up @@ -69,14 +69,14 @@ INSERT INTO users (id, profile) VALUES (1,'{"name": "JohnDoe"}'::jsonb) ON CONFL
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
Expand All @@ -90,8 +90,8 @@ public void shouldReturnEmptyCompletionsForInvalidPosition() throws ExecutionExc

CompletionList completions = service.completion(completionParams).get().getRight();

Assert.assertNotNull(completions);
Assert.assertTrue(completions.getItems().isEmpty());
Assertions.assertNotNull(completions);
Assertions.assertTrue(completions.getItems().isEmpty());
}

@Test
Expand All @@ -105,9 +105,9 @@ public void shouldSuggestKeywordCompletion() throws ExecutionException, Interrup

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
Expand All @@ -124,8 +124,8 @@ public void shouldSuggestMultilineKeywordCompletion() throws ExecutionException,

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());
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -23,9 +23,9 @@
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;
Expand All @@ -38,7 +38,7 @@
public class DBLTextDocumentServiceTest extends CloudbeaverMockTest {
private DBLTextDocumentService service;

@Before
@BeforeEach
public void setUp() {
service = new DBLTextDocumentService();
}
Expand All @@ -55,9 +55,9 @@ public void shouldOpenDocumentWithArbitraryURI() {
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
Expand All @@ -67,14 +67,14 @@ public void shouldOpenDocument() {
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
Expand All @@ -84,10 +84,10 @@ public void shouldInitDefaultSyntax() {

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
Expand All @@ -103,8 +103,8 @@ public void shouldOpenAndChangeDocument() {
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
Expand All @@ -120,10 +120,10 @@ public void shouldFailSubmittingMultipleChangesToDocument() {
TextDocumentContentChangeEvent event2 = new TextDocumentContentChangeEvent(updatedSql2);
List<TextDocumentContentChangeEvent> 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"
);
}

Expand All @@ -138,7 +138,7 @@ public void shouldOpenAndCloseDocument() {
service.didClose(closeParams);

ContextAwareDocument updatedDocument = DocumentServiceTestUtils.getDocument(service, textDocument.getUri());
Assert.assertNull(updatedDocument);
Assertions.assertNull(updatedDocument);
}

@Test
Expand All @@ -155,15 +155,15 @@ public void shouldFormatSingleLineQuery() throws ExecutionException, Interrupted
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
Expand All @@ -190,15 +190,15 @@ public void shouldFormatMultilineQuery() throws ExecutionException, InterruptedE
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
Expand All @@ -223,10 +223,10 @@ CREATE TABLE logs (id serial PRIMARY KEY,
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
Expand All @@ -238,7 +238,7 @@ public void shouldReturnKeywordTokenData() throws ExecutionException, Interrupte
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
);
Expand All @@ -259,7 +259,7 @@ public void shouldReturnMultipleTokensData() throws ExecutionException, Interrup
0, 23, 5, 0, 0, // WHERE
0, 39, 5, 1, 0 // 'Doe'
};
Assert.assertArrayEquals(
Assertions.assertArrayEquals(
expectedData,
tokensData
);
Expand All @@ -286,7 +286,7 @@ public void shouldReturnMultilineTokensData() throws ExecutionException, Interru
3, 0, 5, 0, 0, // WHERE
4, 14, 5, 1, 0 // 'Doe'
};
Assert.assertArrayEquals(
Assertions.assertArrayEquals(
expectedData,
tokensData
);
Expand Down
Loading
Loading