CB-2313 remove dependency from ee test suite

This commit is contained in:
yagudin10
2022-08-03 12:27:25 +03:00
parent d60c1cadac
commit 6f39d89fd7
4 changed files with 67 additions and 31 deletions
@@ -0,0 +1,56 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-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.
*/
package io.cloudbeaver.utils;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import java.io.File;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
public class WebTestUtils {
public static String readScriptTemplate(String templateName, Path scriptsPath) throws Exception {
Path templatePath = new File(String.valueOf(scriptsPath), templateName).toPath();
return Files.readString(templatePath);
}
public static Map<String, Object> doPost(String apiUrl, String input, HttpClient client) throws Exception {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(apiUrl))
.POST(HttpRequest.BodyPublishers.ofString(input))
.header("Content-Type", "application/json")
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
return new GsonBuilder().create().fromJson(
response.body(),
new TypeToken<Map<String, Object>>() {
}.getType()
);
}
}
@@ -104,28 +104,6 @@ public class AllTests {
return client;
}
public static Map<String, Object> doPost(String input, HttpClient client) throws Exception {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(GQL_API_URL))
.POST(HttpRequest.BodyPublishers.ofString(input))
.header("Content-Type", "application/json")
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
return new GsonBuilder().create().fromJson(
response.body(),
new TypeToken<Map<String, Object>>() {
}.getType()
);
}
public static String readScriptTemplate(String templateName, Path scriptsPath) throws Exception {
Path templatePath = new File(String.valueOf(scriptsPath), templateName).toPath();
return Files.readString(templatePath);
}
public static Path getScriptsPath() {
return scriptsPath;
}
@@ -1,5 +1,6 @@
package io.cloudbeaver.test.platform;
import io.cloudbeaver.utils.WebTestUtils;
import org.jkiss.dbeaver.model.auth.SMAuthStatus;
import org.jkiss.dbeaver.model.data.json.JSONUtils;
import org.jkiss.utils.CommonUtils;
@@ -22,9 +23,9 @@ public class AuthenticationTest {
Assert.assertEquals(SMAuthStatus.SUCCESS.name(), JSONUtils.getString(authInfo, "authStatus"));
}
public static Map<String, Object> authenticateUser(HttpClient client, Path scriptsPath) throws Exception {
String input = AllTests.readScriptTemplate(GQL_TEMPLATE_AUTH_LOGIN, scriptsPath);
Map<String, Object> map = AllTests.doPost(input, client);
private Map<String, Object> authenticateUser(HttpClient client, Path scriptsPath) throws Exception {
String input = WebTestUtils.readScriptTemplate(GQL_TEMPLATE_AUTH_LOGIN, scriptsPath);
Map<String, Object> map = WebTestUtils.doPost(AllTests.GQL_API_URL, input, client);
Map<String, Object> data = JSONUtils.getObjectOrNull(map, "data");
if (data != null) {
return JSONUtils.getObjectOrNull(data, "authInfo");
@@ -17,6 +17,7 @@
package io.cloudbeaver.test.platform;
import io.cloudbeaver.utils.WebTestUtils;
import org.jkiss.dbeaver.model.data.json.JSONUtils;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.utils.GeneralUtils;
@@ -64,8 +65,8 @@ public class PlatformTest {
}
private List<Map<String, Object>> getUserConnections(HttpClient client) throws Exception {
String input = AllTests.readScriptTemplate(GQL_TEMPLATE_USER_CONNECTIONS, AllTests.getScriptsPath());
Map<String, Object> map = AllTests.doPost(input, client);
String input = WebTestUtils.readScriptTemplate(GQL_TEMPLATE_USER_CONNECTIONS, AllTests.getScriptsPath());
Map<String, Object> map = WebTestUtils.doPost(AllTests.GQL_API_URL, input, client);
Map<String, Object> data = JSONUtils.getObjectOrNull(map, "data");
if (data != null) {
return JSONUtils.getObjectList(data, "userConnections");
@@ -74,8 +75,8 @@ public class PlatformTest {
}
private Map<String, Object> createConnection(HttpClient client) throws Exception {
String input = AllTests.readScriptTemplate(GQL_TEMPLATE_CREATE_CONNECTION, AllTests.getScriptsPath());
Map<String, Object> map = AllTests.doPost(input, client);
String input = WebTestUtils.readScriptTemplate(GQL_TEMPLATE_CREATE_CONNECTION, AllTests.getScriptsPath());
Map<String, Object> map = WebTestUtils.doPost(AllTests.GQL_API_URL, input, client);
Map<String, Object> data = JSONUtils.getObjectOrNull(map, "data");
if (data != null) {
return JSONUtils.getObjectOrNull(data, "createConnection");
@@ -84,9 +85,9 @@ public class PlatformTest {
}
private boolean deleteConnection(HttpClient client, String connectionId) throws Exception {
String input = AllTests.readScriptTemplate(GQL_TEMPLATE_DELETE_CONNECTION, AllTests.getScriptsPath())
String input = WebTestUtils.readScriptTemplate(GQL_TEMPLATE_DELETE_CONNECTION, AllTests.getScriptsPath())
.replace("${connectionId}", connectionId);
Map<String, Object> map = AllTests.doPost(input, client);
Map<String, Object> map = WebTestUtils.doPost(AllTests.GQL_API_URL, input, client);
Map<String, Object> data = JSONUtils.getObjectOrNull(map, "data");
if (data != null) {
return JSONUtils.getBoolean(data, "deleteConnection");