You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
csamsserver/test/ApplicationTest.kt

153 lines
5.0 KiB

4 years ago
package com.gyf.csams
import cn.smallbun.screw.core.Configuration
import cn.smallbun.screw.core.engine.EngineConfig
import cn.smallbun.screw.core.engine.EngineFileType
import cn.smallbun.screw.core.engine.EngineTemplateType
import cn.smallbun.screw.core.execute.DocumentationExecute
import cn.smallbun.screw.core.process.ProcessConfig
import com.google.gson.Gson
4 years ago
import io.ktor.config.*
import io.ktor.http.*
import io.ktor.server.testing.*
import org.jetbrains.exposed.sql.transactions.transaction
import java.io.File
4 years ago
import kotlin.test.Test
import kotlin.test.assertEquals
4 years ago
class ApplicationTest {
@Test
fun testRoot() {
withTestApplication({ module(testing = true) }) {
handleRequest(HttpMethod.Get, "/").apply {
assertEquals(HttpStatusCode.OK, response.status())
assertEquals("HELLO WORLD!", response.content)
}
}
}
@Test
fun testRandom(){
val c= randomNum(8)
println(c)
val d= randomNum(6)
println(d)
}
@Test
fun testMd5(){
println("admin".md5())
}
fun <R> initApp(test: TestApplicationEngine.() -> R):R{
//<R> withTestApplication(test: TestApplicationEngine.() -> R): R
return withTestApplication({
4 years ago
(environment.config as MapApplicationConfig).apply {
// Set here the properties
put("ktor.deployment.mysql.jdbcUrl", "jdbc:mysql://localhost:3306/csams?serverTimezone=Asia/Shanghai")
4 years ago
put("ktor.deployment.mysql.driverClassName", "com.mysql.cj.jdbc.Driver")
put("ktor.deployment.mysql.username", "root")
put("ktor.deployment.mysql.password", "123456")
put("ktor.deployment.leaveMessage.maxSize", "20")
put("ktor.deployment.filePath", "upload")
4 years ago
}
MySQL(testing = true)
}, test)
}
@Test
fun testInsertUser(){
initApp{
val c=AccountService.register(UserVo(studentId = "6666",name = "hahaha"))
4 years ago
println(c)
}
}
@Test
fun testUpdateComment(){
initApp {
// updateComment(Users,UserTokens)
transaction {
val s= MainService.getAllLeaveMessage()
Gson().toJson(s)
}
}
}
@Test
fun testEntryId() {
initApp {
transaction {
val c=updateComment(UserTokens)
println(c)
}
}
}
@Test
fun checkFileHead(){
val format=File("E:\\JetBrains\\IdeaProjects\\CsamsServer\\build\\classes\\kotlin\\main\\upload\\1621964313158").getFormat()
println(format.format)
}
/**
* 文档生成
*/
@Test
fun documentGeneration() {
initApp {
val fileName="数据库设计文档"
val dir="${System.getenv("UserProfile")}\\Desktop"
//生成配置
val engineConfig = EngineConfig.builder()
//生成文件路径
.fileOutputDir(dir)
//打开目录
.openOutputDir(true)
//文件类型
.fileType(EngineFileType.WORD)
//生成模板实现
.produceType(EngineTemplateType.freemarker)
//自定义文件名称
.fileName(fileName).build()
println("数据库文档输出路径${engineConfig.fileOutputDir}")
//忽略表
// val ignoreTableName = ArrayList<String>()
// ignoreTableName.add("test_user")
// ignoreTableName.add("test_group")
//忽略表前缀
// val ignorePrefix = ArrayList<String>()
// ignorePrefix.add("test_")
//忽略表后缀
// val ignoreSuffix = ArrayList<String>()
// ignoreSuffix.add("_test")
val processConfig = ProcessConfig.builder() //指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过忽略表配置
//根据名称指定表生成
.designatedTableName(ArrayList()) //根据表前缀生成
.designatedTablePrefix(ArrayList()) //根据表后缀生成
.designatedTableSuffix(ArrayList()) //忽略表名
// .ignoreTableName(ignoreTableName) //忽略表前缀
// .ignoreTablePrefix(ignorePrefix) //忽略表后缀
// .ignoreTableSuffix(ignoreSuffix)
.build()
//配置
val config: Configuration = Configuration.builder() //版本
.version("1.0.0") //描述
.description("${fileName}生成") //数据源
.dataSource(MySQL.getInstance(null).dataSource) //生成配置
.engineConfig(engineConfig) //生成配置
.produceConfig(processConfig)
.build()
//执行生成
DocumentationExecute(config).execute()
}
}
4 years ago
}