-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1455 from miahemu/dev
Some typos and unit tests.
- Loading branch information
Showing
17 changed files
with
1,041 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...t2db-server-start/src/test/java/ai/chat2db/server/start/test/core/ConsoleServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package ai.chat2db.server.start.test.core; | ||
|
||
import ai.chat2db.server.domain.api.param.ConsoleCloseParam; | ||
import ai.chat2db.server.domain.api.param.ConsoleConnectParam; | ||
import ai.chat2db.server.domain.api.service.ConsoleService; | ||
import ai.chat2db.server.start.test.TestApplication; | ||
import ai.chat2db.server.start.test.dialect.DialectProperties; | ||
import ai.chat2db.server.start.test.dialect.TestUtils; | ||
import ai.chat2db.server.tools.base.wrapper.result.ActionResult; | ||
import ai.chat2db.spi.sql.Chat2DBContext; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class ConsoleServiceTest extends TestApplication { | ||
|
||
@Autowired | ||
private ConsoleService consoleService; | ||
|
||
@Autowired | ||
private List<DialectProperties> dialectPropertiesList; | ||
|
||
@Test | ||
public void testCreateAndCloseConsole() { | ||
// MYSQL ORACLE POSTGRESQL | ||
for (DialectProperties dialectProperties : dialectPropertiesList) { | ||
Long dataSourceId = TestUtils.nextLong(); | ||
Long consoleId = TestUtils.nextLong(); | ||
TestUtils.buildContext(dialectProperties, dataSourceId, consoleId); | ||
|
||
// creat | ||
ConsoleConnectParam consoleCreateParam = new ConsoleConnectParam(); | ||
consoleCreateParam.setDataSourceId(dataSourceId); | ||
consoleCreateParam.setConsoleId(consoleId); | ||
consoleCreateParam.setDatabaseName(dialectProperties.getDatabaseName()); | ||
ActionResult console = consoleService.createConsole(consoleCreateParam); | ||
assertNotNull(console); | ||
|
||
// close | ||
ConsoleCloseParam consoleCloseParam = new ConsoleCloseParam(); | ||
consoleCloseParam.setDataSourceId(dataSourceId); | ||
consoleCloseParam.setConsoleId(consoleId); | ||
consoleService.closeConsole(consoleCloseParam); | ||
Chat2DBContext.removeContext(); | ||
} | ||
} | ||
|
||
|
||
} |
130 changes: 130 additions & 0 deletions
130
...db-server-start/src/test/java/ai/chat2db/server/start/test/core/DashboardServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package ai.chat2db.server.start.test.core; | ||
|
||
import ai.chat2db.server.domain.api.model.Dashboard; | ||
import ai.chat2db.server.domain.api.param.dashboard.DashboardCreateParam; | ||
import ai.chat2db.server.domain.api.param.dashboard.DashboardPageQueryParam; | ||
import ai.chat2db.server.domain.api.param.dashboard.DashboardQueryParam; | ||
import ai.chat2db.server.domain.api.param.dashboard.DashboardUpdateParam; | ||
import ai.chat2db.server.domain.api.service.DashboardService; | ||
import ai.chat2db.server.domain.repository.Dbutils; | ||
import ai.chat2db.server.start.test.TestApplication; | ||
import ai.chat2db.server.tools.base.enums.YesOrNoEnum; | ||
import ai.chat2db.server.tools.base.wrapper.result.ActionResult; | ||
import ai.chat2db.server.tools.base.wrapper.result.DataResult; | ||
import ai.chat2db.server.tools.base.wrapper.result.PageResult; | ||
import ai.chat2db.server.tools.common.model.Context; | ||
import ai.chat2db.server.tools.common.model.LoginUser; | ||
import ai.chat2db.server.tools.common.util.ContextUtils; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.ArrayList; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class DashboardServiceTest extends TestApplication { | ||
|
||
@Autowired | ||
private DashboardService dashboardService; | ||
|
||
@Test | ||
public void testCreateWithPermission() { | ||
userLoginIdentity(false, 9L); | ||
// userLoginIdentity(true, 11L); | ||
|
||
DashboardCreateParam dashboardCreateParam = new DashboardCreateParam(); | ||
dashboardCreateParam.setName("chat2db"); | ||
dashboardCreateParam.setSchema("test"); | ||
dashboardCreateParam.setDescription("This is a test!"); | ||
dashboardCreateParam.setDeleted(YesOrNoEnum.NO.getLetter()); | ||
dashboardCreateParam.setUserId(5L); | ||
dashboardCreateParam.setChartIds(new ArrayList<Long>()); | ||
|
||
DataResult<Long> withPermission = dashboardService.createWithPermission(dashboardCreateParam); | ||
assertNotNull(withPermission); | ||
} | ||
|
||
@Test | ||
public void testUpdateWithPermission() { | ||
// Note: Only administrators can edit this. | ||
userLoginIdentity(true, 9L); | ||
|
||
DashboardUpdateParam dashboardUpdateParam = new DashboardUpdateParam(); | ||
dashboardUpdateParam.setId(1L); | ||
dashboardUpdateParam.setName("chat2db"); | ||
dashboardUpdateParam.setSchema("test"); | ||
dashboardUpdateParam.setDescription("This is a test!"); | ||
dashboardUpdateParam.setDeleted(YesOrNoEnum.NO.getLetter()); | ||
dashboardUpdateParam.setUserId(5L); | ||
dashboardUpdateParam.setChartIds(new ArrayList<Long>()); | ||
|
||
ActionResult actionResult = dashboardService.updateWithPermission(dashboardUpdateParam); | ||
assertNotNull(actionResult); | ||
|
||
} | ||
|
||
@Test | ||
public void testFind() { | ||
userLoginIdentity(false, 4L); | ||
// userLoginIdentity(true, 2L); | ||
|
||
DataResult<Dashboard> find = dashboardService.find(2L); | ||
assertNotNull(find.getData()); | ||
} | ||
|
||
@Test | ||
public void testQueryExistent() { | ||
userLoginIdentity(false, 8L); | ||
|
||
DashboardQueryParam param = new DashboardQueryParam(); | ||
param.setId(5L); | ||
param.setUserId(9L); | ||
|
||
DataResult<Dashboard> existent = dashboardService.queryExistent(param); | ||
DataResult<Dashboard> dashboardDataResult = dashboardService.queryExistent(5L); | ||
assertNotNull(existent.getData()); | ||
assertNotNull(dashboardDataResult.getData()); | ||
assertEquals(existent, dashboardDataResult); | ||
} | ||
|
||
@Test | ||
public void testDeleteWithPermission() { | ||
userLoginIdentity(false, 7L); | ||
// userLoginIdentity(true, 4L); | ||
|
||
DataResult<Dashboard> dashboardDataResult = dashboardService.find(4L); | ||
if (dashboardDataResult.getData() != null) { | ||
ActionResult actionResult = dashboardService.deleteWithPermission(dashboardDataResult.getData().getId()); | ||
assertNotNull(actionResult); | ||
} | ||
|
||
} | ||
|
||
@Test | ||
public void testQueryPage() { | ||
userLoginIdentity(false, 12L); | ||
|
||
DashboardPageQueryParam param = new DashboardPageQueryParam(); | ||
param.setUserId(5L); | ||
param.setSearchKey("chat"); | ||
|
||
PageResult<Dashboard> queryPage = dashboardService.queryPage(param); | ||
assertNotNull(queryPage.getData()); | ||
} | ||
|
||
|
||
/** | ||
* Save the current user identity (administrator or normal user) and user ID to the context and database session for subsequent use. | ||
* | ||
* @param isAdmin | ||
* @param userId | ||
*/ | ||
private static void userLoginIdentity(boolean isAdmin, Long userId) { | ||
Context context = Context.builder().loginUser( | ||
LoginUser.builder().admin(isAdmin).id(userId).build() | ||
).build(); | ||
ContextUtils.setContext(context); | ||
Dbutils.setSession(); | ||
} | ||
} |
Oops, something went wrong.