0
私は基本的なSpringBootアプリを持っています。 Spring Initializer、組み込みTomcat、Thymeleafテンプレートエンジン、およびパッケージを実行可能なJARファイルとして使用しています。SpringBoot:許可付きWebMvcTest
私はこのテストを持っている:
@RunWith(SpringRunner.class)
@WebAppConfiguration
@WebMvcTest
public class MockMvcTests {
// Pull in the application context created by @ContextConfiguration
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@MockBean
private I18NService i18NService;
@MockBean
private EmailService emailService;
@MockBean
private PasswordResetTokenService passwordResetTokenService;
@MockBean
private UserService userService;
@MockBean
private CompanyService companyService;
@MockBean
private UserSecurityService userSecurityService;
@Before
public void setup() {
// Setup MockMVC to use our Spring Configuration
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}
/**
*
* @throws Exception
* If anything fails.
*/
@Test
public void getDeviceEventsTest() throws Exception {
this.mockMvc
.perform(get("/deviceevent/list") //
.accept(MediaType.parseMediaType("text/html;charset=UTF-8")))
.andExpect(status().isOk()) //
.andExpect(model().size(1)); //
}
しかし、私はこの例外に
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#authorization.expression('hasRole(''ROLE_ADMIN'')')" (tdk/common/menu:62)
を持ってテストを実行するには、許可を回避する方法はありますか?
認証ヘッダーの追加はどうですか?ヘッダー( "認証"、 "あなたの認証タイプのヘッダー値")) '.perform(get("/deviceevent/list " –