강의

멘토링

커뮤니티

Inflearn Community Q&A

shanepark's profile image
shanepark

asked

Spring Boot Web MVC developed with Kotlin

Validating REST Controller, Bean using JUnit

validSchedule 메서드가 검증을 안해주는 것 같습니다.

Written on

·

293

0

@AssertTrue(message = "Dateformat should be yyyy-MM-dd HH:mm:ss")
fun validSchedule(): Boolean {
return try {
LocalDateTime.parse(schedule, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
true
} catch (e: java.lang.Exception) {
false
}
}

todoDtoTest() 에서 this.schedule에 올바르지 않은 포맷을 넣었는데도 테스트를 통과 합니다.

 

이전 강의에서 배웠던 내용으로 

@field:StringFormatDateTime
// yyyy-MM-dd HH:mm:ss
var schedule: String? = null,

변경해서 검증을 하게끔 바꾸긴 했지만, DTO 내부의 AssertTrue를 통해 검증을 하려면 @field:NotBlank를 다른 걸로 변경 해야 하는건가요?

rest-apiMVCJUnitspring-boot

Answer

This question is waiting for answers
Be the first to answer!
shanepark's profile image
shanepark

asked

Ask a question