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 import com.gyf.csams.* import com.gyf.csams.module.AssociationFaculty import com.gyf.csams.module.ClientType import com.gyf.csams.module.UserRegVo import io.ktor.config.* import io.ktor.http.* import io.ktor.server.testing.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.SqlExpressionBuilder.neq import org.jetbrains.exposed.sql.alias import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.innerJoin import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.transactions.transaction import java.io.File import java.time.LocalDateTime import java.time.format.DateTimeFormatter import java.util.* import kotlin.test.Test import kotlin.test.assertEquals class ApplicationTest { @Test fun testRoot() { withTestApplication({ module() }) { 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 initApp(test: TestApplicationEngine.() -> R):R{ // withTestApplication(test: TestApplicationEngine.() -> R): R return withTestApplication({ (environment.config as MapApplicationConfig).apply { // Set here the properties put("ktor.deployment.mysql.jdbcUrl", "jdbc:mysql://localhost:3306/csams?serverTimezone=Asia/Shanghai") 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", "assets") } MySQL() }, test) } @Test fun testInsertUser(){ initApp{ val c= AccountService.register(UserRegVo(studentId = "6666", name = "hahaha")) println("$c") } } @Test fun testUpdateComment(){ initApp { // updateComment(Users,UserTokens) transaction { val s= MainService.getAllLeaveMessage() Gson().toJson(s) } } } @Test fun testEntryId() { initApp { transaction { val nextAudit = AuditLeggings.alias("nextAudit") Activities.innerJoin(AuditLeggings) .innerJoin(nextAudit, { AuditLeggings.nextAudit }, { nextAudit[AuditLeggings.id] }) .innerJoin(Users) .slice(listOf(Activities.id)) .select {Users.id eq 1 and (nextAudit[AuditLeggings.result] neq true)} .firstOrNull() ?.let { it -> ActivityService.getCheckVo(id = it[Activities.id]) }.let { println(it) } } } } @Test fun checkFileHead(){ val format=File("E:\\JetBrains\\IdeaProjects\\CsamsServer\\build\\classes\\kotlin\\main\\upload\\1621964313158").getFormat() println(format.format) } @Test fun testLowerCase(){ println(ClientType.Foreground.name.lowercase(Locale.getDefault())) } @Test fun test(){ println("12345678".substring(IntRange(4,5))) } @Test fun testMap(){ println(arrayOf(1,2,3).mapNotNull { if(it==2) it*2 else null }) } @Test fun testAudit(){ initApp { transaction { Notification.all().sortedByDescending { it.createTime }.forEach { println(it.createTime) } } } } @Test fun testLocalDateTime(){ val c= LocalDateTime.parse("2020-01-01 07:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")).toLong() println(c) println(Date(c)) val d=c.toLocalDateTime() println(d) println(d.toLong()) } @Test fun testFaulty(){ AssociationFaculty.values().map { it.name.length }.maxOrNull().let { println(it) } } @Test fun testStringFormat(){ println(LocalDateTime.now()) } /** * 文档生成 */ @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() // ignoreTableName.add("test_user") // ignoreTableName.add("test_group") //忽略表前缀 // val ignorePrefix = ArrayList() // ignorePrefix.add("test_") //忽略表后缀 // val ignoreSuffix = ArrayList() // 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() } } }