User.builder().userId("1").email("1@example.com").name("1").build()) ); // WHEN & THEN 実行と比較 var result = this.mockMvc.perform(MockMvcRequestBuilders.get(url)) .andExpect(MockMvcResultMatchers.status().isOk()) // HttpStatusだけ確認 // .andExpect(MockMvcResultMatchers.jsonPath("$.users[0].userId").value("1")) .andReturn(); // THEN responseの確認 JSONAssert.assertEquals(“{}”, result.getResponse().getContentAsString(), true); } Controllerのテスト
AuthUser user = new AuthUser(new User("user", "pass", Collections.emptyList()), new kirimaru.biz.domain.User()); Authentication authentication = new UsernamePasswordAuthenticationToken(user, user.getPassword(), user.getAuthorities()); TestSecurityContextHolder.setAuthentication(authentication); } Controllerのテスト:認証(APIと同じ)