【发布时间】:2022-10-24 04:01:02
【问题描述】:
在我的应用程序 Java - Spring Boot - Hibernate - Liquibase 在正常运行检查版本正常工作,我在更新过程中使用错误的版本参数得到预期的错误。 但是在 Junit 测试更新中,无论版本参数如何
应该向我在 Liquibase 中的创建表中添加一些内容吗?
@Version
private int version;
===================
@Test
void shouldNotUpdateDoctor_wrongVersion() throws Exception {
UpdateDoctorCommand updateDoctorCommand
= new UpdateDoctorCommand("test4update",LocalDate.of(1980, 5, 12),
LocalDate.of(2020, 11, 10), 16000, true, 2,3);
String requestJson = objectMapper.writeValueAsString(updateDoctorCommand);
postman.perform(MockMvcRequestBuilders.put("/api/v1/clinic/doctors/33")
.contentType(MediaType.APPLICATION_JSON)
.content(requestJson))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$").value("ROW_UPDATED_IN_ANOTHER_TRANSACTION"));
postman.perform(MockMvcRequestBuilders.get("/api/v1/clinic/doctors/33"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.name").value("notUpdated"))
.andExpect(jsonPath("$.version").value("5"));
}
=====
java.lang.AssertionError: Status expected:<400> but was:<200>
Expected :400
Actual :200
【问题讨论】:
标签: java spring-boot unit-testing junit liquibase