mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
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
This commit is contained in:
+4
-5
@@ -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=\
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
bin.includes = feature.xml,\
|
||||
feature.properties
|
||||
@@ -0,0 +1,4 @@
|
||||
featureName=Cloudbeaver Test feature
|
||||
providerName=DBeaver Corp
|
||||
description=Cloudbeaver Test feature
|
||||
copyrightcopyright=\u00A9 2010-2024, DBeaver Corp
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<feature
|
||||
id="io.cloudbeaver.test.feature"
|
||||
label="%featureName"
|
||||
version="1.0.0.qualifier"
|
||||
provider-name="%providerName"
|
||||
plugin="io.cloudbeaver.model">
|
||||
|
||||
<description>
|
||||
%description
|
||||
</description>
|
||||
|
||||
<copyright>
|
||||
%copyright
|
||||
</copyright>
|
||||
|
||||
<plugin id="io.cloudbeaver.test.platform" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
|
||||
<!-- Logging -->
|
||||
|
||||
</feature>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>io.cloudbeaver</groupId>
|
||||
<artifactId>features</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
<artifactId>io.cloudbeaver.test.feature</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-feature</packaging>
|
||||
</project>
|
||||
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?pde version="3.5"?>
|
||||
|
||||
<product name="CloudBeaver ce Server" uid="io.cloudbeaver.product" id="io.cloudbeaver.product.ce.product"
|
||||
application="io.cloudbeaver.product.ce.application" version="24.3.2.qualifier" useFeatures="true"
|
||||
includeLaunchers="false">
|
||||
|
||||
<configIni use="default">
|
||||
</configIni>
|
||||
<launcherArgs>
|
||||
<programArgs>-web-config conf/cloudbeaver.conf -registryMultiLanguage</programArgs>
|
||||
<programArgsMac></programArgsMac>
|
||||
<vmArgs>
|
||||
-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
|
||||
</vmArgs>
|
||||
<vmArgsMac></vmArgsMac>
|
||||
</launcherArgs>
|
||||
|
||||
<license>
|
||||
<url>https://cloudbeaver.io/about/</url>
|
||||
<text>
|
||||
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.
|
||||
</text>
|
||||
</license>
|
||||
|
||||
<plugins>
|
||||
</plugins>
|
||||
|
||||
<features>
|
||||
<feature id="io.cloudbeaver.product.ce.feature"/>
|
||||
<feature id="io.cloudbeaver.test.feature"/>
|
||||
</features>
|
||||
|
||||
<configurations>
|
||||
<plugin id="org.eclipse.osgi" autoStart="true" startLevel="-1"/>
|
||||
<plugin id="org.apache.felix.scr" autoStart="true" startLevel="1"/>
|
||||
<plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="4"/>
|
||||
</configurations>
|
||||
|
||||
</product>
|
||||
@@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>io.cloudbeaver</groupId>
|
||||
<artifactId>cloudbeaver</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
<version>24.3.2-SNAPSHOT</version>
|
||||
<artifactId>web-server-test</artifactId>
|
||||
<packaging>eclipse-repository</packaging>
|
||||
<name>Cloudbeaver Server Product</name>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.tycho</groupId>
|
||||
<artifactId>target-platform-configuration</artifactId>
|
||||
<version>${tycho-version}</version>
|
||||
<configuration>
|
||||
<environments>
|
||||
<environment>
|
||||
<os>all</os>
|
||||
<ws>all</ws>
|
||||
<arch>all</arch>
|
||||
</environment>
|
||||
</environments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.eclipse.tycho</groupId>
|
||||
<artifactId>tycho-p2-director-plugin</artifactId>
|
||||
<version>${tycho-version}</version>
|
||||
<configuration>
|
||||
<products>
|
||||
<product>
|
||||
<id>io.cloudbeaver.product</id>
|
||||
<archiveFileName>cloudbeaver-server-${dbeaver-version}</archiveFileName>
|
||||
</product>
|
||||
</products>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>materialize-products</id>
|
||||
<goals>
|
||||
<goal>materialize-products</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>archive-products</id>
|
||||
<goals>
|
||||
<!--<goal>archive-products</goal>-->
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Disable P2 repository generation -->
|
||||
<plugin>
|
||||
<groupId>org.eclipse.tycho</groupId>
|
||||
<artifactId>tycho-p2-repository-plugin</artifactId>
|
||||
<version>${tycho-version}</version>
|
||||
<configuration>
|
||||
<createArtifactRepository>false</createArtifactRepository>
|
||||
<skipArchive>true</skipArchive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -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
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<String, Object> 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<String, Object> authenticateTestUser(@NotNull WebGQLClient client) throws Exception {
|
||||
return authenticateTestUser(client, TEST_CREDENTIALS);
|
||||
}
|
||||
|
||||
public static Map<String, Object> authenticateTestUser(
|
||||
@NotNull WebGQLClient client,
|
||||
@NotNull Map<String, Object> credentials
|
||||
) throws Exception {
|
||||
return client.sendQuery(
|
||||
WebGQLClient.GQL_AUTHENTICATE,
|
||||
Map.of(
|
||||
"provider", LocalAuthProvider.PROVIDER_ID,
|
||||
"credentials", credentials
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private CEAppStarter() {
|
||||
}
|
||||
}
|
||||
@@ -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<String, Object> authInfo = CEServerTestSuite.authenticateTestUser(client);
|
||||
WebGQLClient client = CEAppStarter.createClient(httpClient);
|
||||
Map<String, Object> 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);
|
||||
|
||||
+7
-6
@@ -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")) {
|
||||
|
||||
+8
-6
@@ -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<String, Object> authInfo = CEServerTestSuite.authenticateTestUser(client);
|
||||
WebGQLClient client = CEAppStarter.createClient();
|
||||
Map<String, Object> 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<String, Object> credsWithCamelCase = getUserCredentials(userId);
|
||||
// authenticating with user
|
||||
Map<String, Object> authInfo = CEServerTestSuite.authenticateTestUser(client, credsWithCamelCase);
|
||||
Map<String, Object> authInfo = CEAppStarter.authenticateTestUser(client, credsWithCamelCase);
|
||||
Assert.assertEquals(SMAuthStatus.SUCCESS.name(), JSONUtils.getString(authInfo, "authStatus"));
|
||||
Map<String, Object> 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<String> headers = List.of(RPAuthProvider.X_USER, testUserId, RPAuthProvider.X_TEAM, "user");
|
||||
Map<String, Object> sessionInfo = client.sendQueryWithHeaders(GQL_OPEN_SESSION, null, headers);
|
||||
|
||||
+3
-72
@@ -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<String, Object> 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<String, Object> authenticateTestUser(@NotNull WebGQLClient client) throws Exception {
|
||||
return authenticateTestUser(client, TEST_CREDENTIALS);
|
||||
}
|
||||
|
||||
public static Map<String, Object> authenticateTestUser(
|
||||
@NotNull WebGQLClient client,
|
||||
@NotNull Map<String, Object> credentials
|
||||
) throws Exception {
|
||||
return client.sendQuery(
|
||||
WebGQLClient.GQL_AUTHENTICATE,
|
||||
Map.of(
|
||||
"provider", LocalAuthProvider.PROVIDER_ID,
|
||||
"credentials", credentials
|
||||
)
|
||||
);
|
||||
CEAppStarter.shutdownServer();
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -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<String, Object> configuration = new LinkedHashMap<>();
|
||||
Map<String, Object> variables = new LinkedHashMap<>();
|
||||
|
||||
+5
-3
@@ -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<String, Object> authInfo = CEServerTestSuite.authenticateTestUser(client);
|
||||
client = CEAppStarter.createClient();
|
||||
Map<String, Object> authInfo = CEAppStarter.authenticateTestUser(client);
|
||||
Assert.assertEquals(SMAuthStatus.SUCCESS.name(), JSONUtils.getString(authInfo, "authStatus"));
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -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," +
|
||||
|
||||
Reference in New Issue
Block a user