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.
 
 
 
qqbot/src/test/kotlin/com/pqh/qqbot/QqbotApplicationTests.kt

94 lines
3.1 KiB

package com.pqh.qqbot
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.web.client.TestRestTemplate
import org.springframework.boot.test.web.client.getForEntity
import org.springframework.http.HttpMethod
import org.springframework.http.MediaType
import org.springframework.http.RequestEntity.get
import org.springframework.http.RequestEntity.post
import org.springframework.http.ResponseEntity.status
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
import org.springframework.test.web.servlet.result.MockMvcResultHandlers
import org.springframework.util.ResourceUtils
import java.io.File
import java.net.URI
import java.nio.charset.StandardCharsets
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class QqbotApplicationTests(@Autowired val restTemplate: TestRestTemplate) {
private val logger: Logger = LoggerFactory.getLogger(QqbotApplicationTests::class.java)
@Test
fun `Assert blog page title, content and status code`() {
logger.info(">> Assert blog page title, content and status code")
val entity = restTemplate.getForEntity<String>("/fuck")
logger.info(entity.body)
}
@Autowired
lateinit var message: MessageRepository
@Autowired
lateinit var sub: MessageSubRepository
@Autowired
lateinit var testBot:TestQQBot
@Value("#{environment['qq_config']}")
lateinit var sss: String
@Test
fun `mongo test`() {
val m = MySqlMessage(senderId = 1213, time = System.currentTimeMillis().toInt(), botId = 123)
val entity = message.save(m)
logger.info(entity.id)
}
@Test
fun `@value`() = runBlocking {
val file = ResourceUtils.getFile("${ResourceUtils.CLASSPATH_URL_PREFIX}qq.json")
logger.info(file.readText(StandardCharsets.UTF_8))
file.deleteOnExit()
}
@Value("\${qq-image}")
lateinit var staticLocations: String
@Test
fun testPath(){
val filepath = File(staticLocations, "test")
println(filepath.absolutePath)
}
@Test
fun testLog(){
logger.info("日志log")
}
}
@WebMvcTest
class TestMVC(@Autowired val mockMvc: MockMvc) {
@Test
fun testRunBot() {
//val qqId:Long,val adminQQId: Long,val pwd:String,val forward:Long
mockMvc.perform(MockMvcRequestBuilders.request(HttpMethod.POST, "/runBot")
.param("qqId","222")
.param("adminQQId","333")
.param("forward","4444")
.param("pwd", "666")).andDo(MockMvcResultHandlers.print())
}
}