我正在开发一个jhipster应用程序,并且我试图向我的应用程序的每个用户仅显示他创建的实体:我将此代码添加到?
PianoResourceIntTest.java:
@Test
@Transactional
public void getAllPianos() throws Exception {
// Initialize the database
restPianoMockMvc = MockMvcBuilders.webAppContextSetup(context).apply(springSecurity()).build();
// pianoRepository.saveAndFlush(piano);
piano.setUser(userRepository.findOneByLogin("user").get());
pianoRepository.saveAndFlush(piano);
// Get all the pianos
//restPianoMockMvc.perform(get("/api/pianos?sort=id,desc").with(user("user")))
restPianoMockMvc.perform(get("/api/pianos?sort=id,desc").with(user("user"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.[*].id").value(hasItem(piano.getId().intValue())))
.andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME.toString())))
.andExpect(jsonPath("$.[*].date").value(hasItem(DEFAULT_DATE.toString())));
}但是我得到了两个错误:
Cannot resolve the method SpringSecurity
Cannot resolve the symbol user我不知道如何处理这个问题,以及如何解决这个问题。
发布于 2016-03-20 04:55:07
我认为这些错误是编译错误,而不是运行时错误。
user()是类SecurityMockMvcRequestPostProcessors中的一个静态方法,因此需要向其添加一个静态导入。
类SecurityMockMvcConfigurers中的静态方法springSecurity()也是如此
检查Spring Security doc about Spring MVC test integration
https://stackoverflow.com/questions/36101643
复制相似问题