From 82753268e6dde4b1746989616167e6a8208e14e7 Mon Sep 17 00:00:00 2001 From: Georgii Date: Wed, 22 Jan 2025 18:44:29 +0400 Subject: [PATCH] dbeaver/dbeaver-infra#187 PRO osgi test runner (#3190) * dbeaver/dbeaver-infra#187 PRO osgi test runner * dbeaver/dbeaver-infra#187 working CBEE & WIP DC runners * dbeaver/dbeaver-infra#187 code cleanup & fix maven runs * dbeaver/dbeaver-infra#187 code cleanup * dbeaver/dbeaver-infra#187 don't asyncLaunch desktop apps --- osgi-app.properties | 9 +- .../build.properties | 2 + .../feature.properties | 4 + .../io.cloudbeaver.test.feature/feature.xml | 20 ++++ .../io.cloudbeaver.test.feature/pom.xml | 15 +++ .../CloudbeaverServerTest.product | 75 +++++++++++++++ server/product/web-server-test/pom.xml | 74 +++++++++++++++ .../product-branding.properties | 14 +++ .../META-INF/MANIFEST.MF | 1 + .../io/cloudbeaver/CloudbeaverMockTest.java | 29 ++++++ .../src/io/cloudbeaver/app/CEAppStarter.java | 92 +++++++++++++++++++ .../io/cloudbeaver/model/rm/RMNIOTest.java | 8 +- .../cloudbeaver/model/rm/lock/RMLockTest.java | 13 +-- .../test/platform/AuthenticationTest.java | 14 +-- .../test/platform/CEServerTestSuite.java | 75 +-------------- .../test/platform/ConnectionsTest.java | 8 +- .../test/platform/ResourceManagerTest.java | 8 +- .../test/platform/SQLQueryTranslatorTest.java | 3 +- 18 files changed, 365 insertions(+), 99 deletions(-) create mode 100644 server/features/io.cloudbeaver.test.feature/build.properties create mode 100644 server/features/io.cloudbeaver.test.feature/feature.properties create mode 100644 server/features/io.cloudbeaver.test.feature/feature.xml create mode 100644 server/features/io.cloudbeaver.test.feature/pom.xml create mode 100644 server/product/web-server-test/CloudbeaverServerTest.product create mode 100644 server/product/web-server-test/pom.xml create mode 100644 server/product/web-server-test/product-branding.properties create mode 100644 server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/CloudbeaverMockTest.java create mode 100644 server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/app/CEAppStarter.java diff --git a/osgi-app.properties b/osgi-app.properties index e4e5098873..8d7c3cfc72 100644 --- a/osgi-app.properties +++ b/osgi-app.properties @@ -6,7 +6,8 @@ bundlesPaths=\ dbeaver-common/modules;\ dbeaver/plugins;\ cloudbeaver/server/bundles;\ - dbeaver-jdbc-libsql + dbeaver-jdbc-libsql;\ + cloudbeaver/server/test testLibraries=\ org.junit;\ org.mockito.mockito-core;\ @@ -22,12 +23,10 @@ testBundles=\ org.opentest4j productsPaths=\ dbeaver/product/community/DBeaver.product;\ - cloudbeaver/server/product/web-server/CloudbeaverServer.product:../../opt/cloudbeaver; + cloudbeaver/server/product/web-server/CloudbeaverServer.product:../../opt/cloudbeaver;\ + cloudbeaver/server/product/web-server-test/CloudbeaverServerTest.product:../../opt/cloudbeaver; ideaConfigurationFilesPaths=\ dbeaver/.ide/.idea; -testBundlePaths=\ - dbeaver/test;\ - cloudbeaver/server/test; additionalModuleRoots=\ opt; optionalFeatureRepositories=\ diff --git a/server/features/io.cloudbeaver.test.feature/build.properties b/server/features/io.cloudbeaver.test.feature/build.properties new file mode 100644 index 0000000000..b3a611b5c9 --- /dev/null +++ b/server/features/io.cloudbeaver.test.feature/build.properties @@ -0,0 +1,2 @@ +bin.includes = feature.xml,\ + feature.properties diff --git a/server/features/io.cloudbeaver.test.feature/feature.properties b/server/features/io.cloudbeaver.test.feature/feature.properties new file mode 100644 index 0000000000..bac6d075f2 --- /dev/null +++ b/server/features/io.cloudbeaver.test.feature/feature.properties @@ -0,0 +1,4 @@ +featureName=Cloudbeaver Test feature +providerName=DBeaver Corp +description=Cloudbeaver Test feature +copyrightcopyright=\u00A9 2010-2024, DBeaver Corp diff --git a/server/features/io.cloudbeaver.test.feature/feature.xml b/server/features/io.cloudbeaver.test.feature/feature.xml new file mode 100644 index 0000000000..8f8ce6193b --- /dev/null +++ b/server/features/io.cloudbeaver.test.feature/feature.xml @@ -0,0 +1,20 @@ + + + + + %description + + + + %copyright + + + + + + diff --git a/server/features/io.cloudbeaver.test.feature/pom.xml b/server/features/io.cloudbeaver.test.feature/pom.xml new file mode 100644 index 0000000000..62b1f676aa --- /dev/null +++ b/server/features/io.cloudbeaver.test.feature/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + io.cloudbeaver + features + 1.0.0-SNAPSHOT + ../ + + io.cloudbeaver.test.feature + 1.0.0-SNAPSHOT + eclipse-feature + diff --git a/server/product/web-server-test/CloudbeaverServerTest.product b/server/product/web-server-test/CloudbeaverServerTest.product new file mode 100644 index 0000000000..db340de85a --- /dev/null +++ b/server/product/web-server-test/CloudbeaverServerTest.product @@ -0,0 +1,75 @@ + + + + + + + + + -web-config conf/cloudbeaver.conf -registryMultiLanguage + + + -Dfile.encoding=UTF-8 + --add-modules=ALL-SYSTEM + --add-opens=java.base/java.io=ALL-UNNAMED + --add-opens=java.base/java.lang=ALL-UNNAMED + --add-opens=java.base/java.lang.reflect=ALL-UNNAMED + --add-opens=java.base/java.net=ALL-UNNAMED + --add-opens=java.base/java.nio=ALL-UNNAMED + --add-opens=java.base/java.nio.charset=ALL-UNNAMED + --add-opens=java.base/java.text=ALL-UNNAMED + --add-opens=java.base/java.time=ALL-UNNAMED + --add-opens=java.base/java.util=ALL-UNNAMED + --add-opens=java.base/java.util.concurrent=ALL-UNNAMED + --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED + --add-opens=java.base/jdk.internal.vm=ALL-UNNAMED + --add-opens=java.base/jdk.internal.misc=ALL-UNNAMED + --add-opens=java.base/sun.nio.ch=ALL-UNNAMED + --add-opens=java.base/sun.security.ssl=ALL-UNNAMED + --add-opens=java.base/sun.security.action=ALL-UNNAMED + --add-opens=java.base/sun.security.util=ALL-UNNAMED + --add-opens=java.security.jgss/sun.security.jgss=ALL-UNNAMED + --add-opens=java.security.jgss/sun.security.krb5=ALL-UNNAMED + --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED + --add-opens=java.sql/java.sql=ALL-UNNAMED + + + + + + https://cloudbeaver.io/about/ + + CloudBeaver - Cloud Database Manager + Copyright (C) 2019-2022 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. + + + + + + + + + + + + + + + + + + diff --git a/server/product/web-server-test/pom.xml b/server/product/web-server-test/pom.xml new file mode 100644 index 0000000000..2a87413b67 --- /dev/null +++ b/server/product/web-server-test/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + io.cloudbeaver + cloudbeaver + 1.0.0-SNAPSHOT + ../../ + + 24.3.2-SNAPSHOT + web-server-test + eclipse-repository + Cloudbeaver Server Product + + + + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + + + all + all + all + + + + + + + org.eclipse.tycho + tycho-p2-director-plugin + ${tycho-version} + + + + io.cloudbeaver.product + cloudbeaver-server-${dbeaver-version} + + + + + + materialize-products + + materialize-products + + + + archive-products + + + + + + + + + org.eclipse.tycho + tycho-p2-repository-plugin + ${tycho-version} + + false + true + + + + + + diff --git a/server/product/web-server-test/product-branding.properties b/server/product/web-server-test/product-branding.properties new file mode 100644 index 0000000000..74c54fa047 --- /dev/null +++ b/server/product/web-server-test/product-branding.properties @@ -0,0 +1,14 @@ +packageName=cloudbeaver +appName=CloudBeaver +productEclipseId=io.cloudbeaver.product +productModifier=ce +productName=CloudBeaver +productBrandText=Cloud Database Manager +productDescription=Cloud Database Manager +productTrademark=DBeaver is a trademark of DBeaver Corp +productCopyright=DBeaver Corp +productEmail=support@dbeaver.com +productCompany=DBeaver Corp +productWebSite=https://dbeaver.com/ +productBundleId=io.cloudbeaver.product +productRepository=dbeaver/cloudbeaver 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 a55337eba2..ed07586b4c 100644 --- a/server/test/io.cloudbeaver.test.platform/META-INF/MANIFEST.MF +++ b/server/test/io.cloudbeaver.test.platform/META-INF/MANIFEST.MF @@ -12,6 +12,7 @@ Require-Bundle: org.eclipse.core.runtime, org.mockito.mockito-core, org.apache.felix.scr, org.jkiss.dbeaver.model, + org.jkiss.dbeaver.osgi.test.runner;visibility:=reexport, org.jkiss.dbeaver.model.sql, org.jkiss.dbeaver.registry, org.jkiss.dbeaver.ext.generic, 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 new file mode 100644 index 0000000000..2b6e9f8a36 --- /dev/null +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/CloudbeaverMockTest.java @@ -0,0 +1,29 @@ +package io.cloudbeaver; + +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 java.net.CookieManager; +import java.net.http.HttpClient; + +@RunWithProduct("CloudbeaverServerTest.product") +@RunnerProxy(MockitoJUnitRunner.class) +@RunWith(OSGITestRunner.class) +@RunWithApplication(bundleName = "io.cloudbeaver.server.ce", registryName = "io.cloudbeaver.product.ce.application", args = {"-web-config", "workspace/conf/cloudbeaver.conf"}) +public abstract class CloudbeaverMockTest implements IAsyncApplication { + 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() + .cookieHandler(new CookieManager()) + .version(HttpClient.Version.HTTP_2) + .build();; + public boolean verifyLaunched() { + return WebTestUtils.getServerStatus(httpClient, SERVER_STATUS_URL); + } +} 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 new file mode 100644 index 0000000000..fbd24c8ec6 --- /dev/null +++ b/server/test/io.cloudbeaver.test.platform/src/io/cloudbeaver/app/CEAppStarter.java @@ -0,0 +1,92 @@ +package io.cloudbeaver.app; + +import io.cloudbeaver.auth.provider.local.LocalAuthProvider; +import io.cloudbeaver.server.CBApplication; +import io.cloudbeaver.server.CBApplicationCE; +import io.cloudbeaver.test.WebGQLClient; +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 java.net.CookieManager; +import java.net.http.HttpClient; +import java.util.Map; + +public class CEAppStarter { + private static final String GQL_API_URL = "http://localhost:18978/api/gql"; + private static final String SERVER_STATUS_URL = "http://localhost:18978/status"; + private static final Map TEST_CREDENTIALS = Map.of( + LocalAuthProvider.CRED_USER, "test", + LocalAuthProvider.CRED_PASSWORD, SecurityUtils.makeDigest("test") + ); + + private static CBApplication testApp; + + public static void startServerIfNotStarted() throws Exception { + System.out.println("Start CBApplication"); + if (DBWorkbench.isPlatformStarted() && DBWorkbench.getPlatform().getApplication() instanceof CBApplication) { + testApp = (CBApplication) DBWorkbench.getPlatform().getApplication(); + return; + } + testApp = new CBApplicationCE(); + Thread thread = new Thread(() -> testApp.start(null)); + thread.start(); + HttpClient httpClient = HttpClient.newBuilder() + .cookieHandler(new CookieManager()) + .version(HttpClient.Version.HTTP_2) + .build(); + long startTime = System.currentTimeMillis(); + long endTime = 0; + boolean setUpIsDone = false; + while (!setUpIsDone && endTime < 300000) { + setUpIsDone = WebTestUtils.getServerStatus(httpClient, SERVER_STATUS_URL); + endTime = System.currentTimeMillis() - startTime; + } + if (!setUpIsDone) { + throw new Exception("Server is not running"); + } + } + + @AfterClass + public static void shutdownServer() { + testApp.stop(); + } + + public static CBApplication getTestApp() { + return testApp; + } + + public static WebGQLClient createClient() { + HttpClient httpClient = HttpClient.newBuilder() + .cookieHandler(new CookieManager()) + .version(HttpClient.Version.HTTP_2) + .build(); + return createClient(httpClient); + } + + public static WebGQLClient createClient(@NotNull HttpClient httpClient) { + return new WebGQLClient(httpClient, GQL_API_URL); + } + + public static Map authenticateTestUser(@NotNull WebGQLClient client) throws Exception { + return authenticateTestUser(client, TEST_CREDENTIALS); + } + + public static Map authenticateTestUser( + @NotNull WebGQLClient client, + @NotNull Map credentials + ) throws Exception { + return client.sendQuery( + WebGQLClient.GQL_AUTHENTICATE, + Map.of( + "provider", LocalAuthProvider.PROVIDER_ID, + "credentials", credentials + ) + ); + } + + private CEAppStarter() { + } +} 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 495b4e5362..8ea616144c 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 @@ -16,6 +16,7 @@ */ package io.cloudbeaver.model.rm; +import io.cloudbeaver.app.CEAppStarter; import io.cloudbeaver.model.session.WebSession; import io.cloudbeaver.server.CBConstants; import io.cloudbeaver.service.rm.nio.RMNIOFileSystem; @@ -54,12 +55,13 @@ public class RMNIOTest { @BeforeClass public static void init() throws Exception { var cookieManager = new CookieManager(); + CEAppStarter.startServerIfNotStarted(); var httpClient = HttpClient.newBuilder() .cookieHandler(cookieManager) .version(HttpClient.Version.HTTP_2) .build(); - WebGQLClient client = CEServerTestSuite.createClient(httpClient); - Map authInfo = CEServerTestSuite.authenticateTestUser(client); + WebGQLClient client = CEAppStarter.createClient(httpClient); + Map authInfo = CEAppStarter.authenticateTestUser(client); Assert.assertEquals(SMAuthStatus.SUCCESS.name(), JSONUtils.getString(authInfo, "authStatus")); String sessionId = cookieManager.getCookieStore().getCookies() @@ -68,7 +70,7 @@ public class RMNIOTest { .findFirst() .get() .getValue(); - webSession = (WebSession) CEServerTestSuite.getTestApp().getSessionManager().getSession(sessionId); + webSession = (WebSession) CEAppStarter.getTestApp().getSessionManager().getSession(sessionId); Assert.assertNotNull(webSession); var projectName = "NIO_Test" + SecurityUtils.generateUniqueId(); testProject = webSession.getRmController().createProject(projectName, null); 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 04501c3899..49e67ee4cb 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 @@ -16,6 +16,7 @@ */ package io.cloudbeaver.model.rm.lock; +import io.cloudbeaver.app.CEAppStarter; import io.cloudbeaver.test.platform.CEServerTestSuite; import org.jkiss.dbeaver.Log; import org.junit.Assert; @@ -39,7 +40,7 @@ public class RMLockTest { @Test public void testProjectAccessUsingSeveralControllers() throws Throwable { - var lockController1 = new TestLockController(CEServerTestSuite.getTestApp(), 1); + var lockController1 = new TestLockController(CEAppStarter.getTestApp(), 1); CountDownLatch thread1CDL = new CountDownLatch(1); CountDownLatch thread2CDL = new CountDownLatch(1); @@ -63,7 +64,7 @@ public class RMLockTest { }; int atLeastWaitCalls = 1; - var lockController2 = Mockito.spy(new TestLockController(CEServerTestSuite.getTestApp(), 1000)); + var lockController2 = Mockito.spy(new TestLockController(CEAppStarter.getTestApp(), 1000)); Mockito.doAnswer(new Answer() { private int count = 0; @@ -105,7 +106,7 @@ public class RMLockTest { @Test public void testAccessToDifferentProjects() throws Throwable { - var lockController1 = new TestLockController(CEServerTestSuite.getTestApp(), 1); + var lockController1 = new TestLockController(CEAppStarter.getTestApp(), 1); CountDownLatch thread1CDL = new CountDownLatch(1); CountDownLatch thread2CDL = new CountDownLatch(1); @@ -131,7 +132,7 @@ public class RMLockTest { } }; - var lockController2 = new TestLockController(CEServerTestSuite.getTestApp(), 1); + var lockController2 = new TestLockController(CEAppStarter.getTestApp(), 1); Runnable runnable2 = () -> { try { try (var lock = lockController2.lockProject(project2, "testAccessToDifferentProjects2")) { @@ -163,7 +164,7 @@ public class RMLockTest { @Test public void testForceUnlock() throws Throwable { - var lockController1 = new TestLockController(CEServerTestSuite.getTestApp(), 1); + var lockController1 = new TestLockController(CEAppStarter.getTestApp(), 1); CountDownLatch thread1CDL = new CountDownLatch(1); CountDownLatch globalCountDown = new CountDownLatch(2); @@ -183,7 +184,7 @@ public class RMLockTest { } }; - var lockController2 = Mockito.spy(new TestLockController(CEServerTestSuite.getTestApp(), 100)); + var lockController2 = Mockito.spy(new TestLockController(CEAppStarter.getTestApp(), 100)); Runnable runnable2 = () -> { try { try (var lock = lockController2.lockProject(project1, "testForceUnlock2")) { 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 e2bebd4db8..b6c24f8886 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 @@ -16,6 +16,8 @@ */ package io.cloudbeaver.test.platform; +import io.cloudbeaver.CloudbeaverMockTest; +import io.cloudbeaver.app.CEAppStarter; import io.cloudbeaver.auth.provider.local.LocalAuthProvider; import io.cloudbeaver.auth.provider.rp.RPAuthProvider; import io.cloudbeaver.test.WebGQLClient; @@ -30,7 +32,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -public class AuthenticationTest { +public class AuthenticationTest extends CloudbeaverMockTest { private static final String GQL_OPEN_SESSION = """ mutation openSession($defaultLocale: String) { result: openSession(defaultLocale: $defaultLocale) { @@ -52,19 +54,19 @@ public class AuthenticationTest { @Test public void testLoginUser() throws Exception { - WebGQLClient client = CEServerTestSuite.createClient(); - Map authInfo = CEServerTestSuite.authenticateTestUser(client); + WebGQLClient client = CEAppStarter.createClient(); + Map authInfo = CEAppStarter.authenticateTestUser(client); Assert.assertEquals(SMAuthStatus.SUCCESS.name(), JSONUtils.getString(authInfo, "authStatus")); } @Test public void testLoginUserWithCamelCase() throws Exception { - WebGQLClient client = CEServerTestSuite.createClient(); + WebGQLClient client = CEAppStarter.createClient(); for (String userId : Set.of("Test", "tESt", "tesT", "TEST")) { Map credsWithCamelCase = getUserCredentials(userId); // authenticating with user - Map authInfo = CEServerTestSuite.authenticateTestUser(client, credsWithCamelCase); + Map authInfo = CEAppStarter.authenticateTestUser(client, credsWithCamelCase); Assert.assertEquals(SMAuthStatus.SUCCESS.name(), JSONUtils.getString(authInfo, "authStatus")); Map activeUser = client.sendQuery(GQL_ACTIVE_USER, null); Assert.assertEquals(userId.toLowerCase(), JSONUtils.getString(activeUser, "userId")); @@ -87,7 +89,7 @@ public class AuthenticationTest { @Test public void testReverseProxyAnonymousModeLogin() throws Exception { - WebGQLClient client = CEServerTestSuite.createClient(); + WebGQLClient client = CEAppStarter.createClient(); String testUserId = "reverseProxyTestUser"; List headers = List.of(RPAuthProvider.X_USER, testUserId, RPAuthProvider.X_TEAM, "user"); Map sessionInfo = client.sendQueryWithHeaders(GQL_OPEN_SESSION, null, headers); 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 b133f1baa5..a086cb8b5d 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 @@ -17,24 +17,14 @@ package io.cloudbeaver.test.platform; -import io.cloudbeaver.auth.provider.local.LocalAuthProvider; +import io.cloudbeaver.app.CEAppStarter; import io.cloudbeaver.model.rm.RMNIOTest; import io.cloudbeaver.model.rm.lock.RMLockTest; -import io.cloudbeaver.server.CBApplication; -import io.cloudbeaver.server.CBApplicationCE; -import io.cloudbeaver.test.WebGQLClient; -import io.cloudbeaver.utils.WebTestUtils; -import org.jkiss.code.NotNull; -import org.jkiss.utils.SecurityUtils; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.junit.runners.Suite; -import java.net.CookieManager; -import java.net.http.HttpClient; -import java.util.Map; - @RunWith(Suite.class) @Suite.SuiteClasses( { @@ -48,72 +38,13 @@ import java.util.Map; ) public class CEServerTestSuite { - private static final String GQL_API_URL = "http://localhost:18978/api/gql"; - private static final String SERVER_STATUS_URL = "http://localhost:18978/status"; - private static final Map TEST_CREDENTIALS = Map.of( - LocalAuthProvider.CRED_USER, "test", - LocalAuthProvider.CRED_PASSWORD, SecurityUtils.makeDigest("test") - ); - - private static CBApplication testApp; - @BeforeClass public static void startServer() throws Exception { - System.out.println("Start CBApplication"); - testApp = new CBApplicationCE(); - Thread thread = new Thread(() -> testApp.start(null)); - thread.start(); - HttpClient httpClient = HttpClient.newBuilder() - .cookieHandler(new CookieManager()) - .version(HttpClient.Version.HTTP_2) - .build(); - long startTime = System.currentTimeMillis(); - long endTime = 0; - boolean setUpIsDone = false; - while (!setUpIsDone && endTime < 300000) { - setUpIsDone = WebTestUtils.getServerStatus(httpClient, SERVER_STATUS_URL); - endTime = System.currentTimeMillis() - startTime; - } - if (!setUpIsDone) { - throw new Exception("Server is not running"); - } + CEAppStarter.startServerIfNotStarted(); } @AfterClass public static void shutdownServer() { - testApp.stop(); - } - - public static CBApplication getTestApp() { - return testApp; - } - - public static WebGQLClient createClient() { - HttpClient httpClient = HttpClient.newBuilder() - .cookieHandler(new CookieManager()) - .version(HttpClient.Version.HTTP_2) - .build(); - return createClient(httpClient); - } - - public static WebGQLClient createClient(@NotNull HttpClient httpClient) { - return new WebGQLClient(httpClient, GQL_API_URL); - } - - public static Map authenticateTestUser(@NotNull WebGQLClient client) throws Exception { - return authenticateTestUser(client, TEST_CREDENTIALS); - } - - public static Map authenticateTestUser( - @NotNull WebGQLClient client, - @NotNull Map credentials - ) throws Exception { - return client.sendQuery( - WebGQLClient.GQL_AUTHENTICATE, - Map.of( - "provider", LocalAuthProvider.PROVIDER_ID, - "credentials", credentials - ) - ); + 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 1a59389d65..70a6839dcb 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 @@ -17,6 +17,8 @@ package io.cloudbeaver.test.platform; +import io.cloudbeaver.CloudbeaverMockTest; +import io.cloudbeaver.app.CEAppStarter; import io.cloudbeaver.test.WebGQLClient; import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.model.data.json.JSONUtils; @@ -30,7 +32,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -public class ConnectionsTest { +public class ConnectionsTest extends CloudbeaverMockTest { private static final String GQL_CONNECTIONS_GET = """ query userConnections { result: userConnections { @@ -64,8 +66,8 @@ public class ConnectionsTest { @Test public void testBCreateConnection() throws Exception { - WebGQLClient client = CEServerTestSuite.createClient(); - CEServerTestSuite.authenticateTestUser(client); + WebGQLClient client = CEAppStarter.createClient(); + CEAppStarter.authenticateTestUser(client); Map configuration = new LinkedHashMap<>(); Map variables = new LinkedHashMap<>(); 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 e4bdfebdf3..443733587c 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 @@ -17,6 +17,8 @@ package io.cloudbeaver.test.platform; +import io.cloudbeaver.CloudbeaverMockTest; +import io.cloudbeaver.app.CEAppStarter; import io.cloudbeaver.model.rm.local.LocalResourceController; import io.cloudbeaver.server.CBApplication; import io.cloudbeaver.test.WebGQLClient; @@ -32,7 +34,7 @@ import org.junit.Test; import java.nio.file.Path; import java.util.Map; -public class ResourceManagerTest { +public class ResourceManagerTest extends CloudbeaverMockTest { private static WebGQLClient client; private static final String GQL_RESOURCES_CREATE = """ @@ -69,8 +71,8 @@ public class ResourceManagerTest { @BeforeClass public static void init() throws Exception { Assert.assertTrue(CBApplication.getInstance().getAppConfiguration().isResourceManagerEnabled()); - client = CEServerTestSuite.createClient(); - Map authInfo = CEServerTestSuite.authenticateTestUser(client); + client = CEAppStarter.createClient(); + Map authInfo = CEAppStarter.authenticateTestUser(client); Assert.assertEquals(SMAuthStatus.SUCCESS.name(), JSONUtils.getString(authInfo, "authStatus")); } 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 416aaa8656..f8af2eca03 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 @@ -16,6 +16,7 @@ */ package io.cloudbeaver.test.platform; +import io.cloudbeaver.CloudbeaverMockTest; import org.jkiss.code.NotNull; import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.ext.h2.model.H2SQLDialect; @@ -34,7 +35,7 @@ import org.junit.Test; import java.util.HashMap; import java.util.Map; -public class SQLQueryTranslatorTest { +public class SQLQueryTranslatorTest extends CloudbeaverMockTest { @Test public void createSimpleTable() throws DBException { var basicSql = "CREATE TABLE CB_AUTH_SUBJECT (SUBJECT_ID VARCHAR(128) NOT NULL," +