Computer scienceBackendSpring BootSpring Testing

Testing Spring Security

Theory

Wiring up

Report a typo

Look at the following test class and match the placeholder numbers with appropriate annotations:

Java
@1(SomeController.class)
class SomeControllerTest {

    @2
    private MockMvc mockMvc;


    @3
    @4(authorities = {"ROLE_ADMIN"})
    void test() throws Exception {

        var requestBuilder = MockMvcRequestBuilders.get("/resource");

        mockMvc.perform(requestBuilder)
                .andExpect(status().isOk());
    }
}
Kotlin
@1(SomeController::class)
@Import(SecurityConfig::class)
class SomeControllerTest(@2 private val mockMvc: MockMvc) {

    @3
    @4(authorities = ["ROLE_ADMIN"])
    @Throws(Exception::class)
    fun test() {
        val requestBuilder = MockMvcRequestBuilders.get("/resource")

        mockMvc.perform(requestBuilder)
            .andExpect(status().isOk())
    }
}
Match the items from left and right columns
@1
@2
@3
@4
@Autowired
@Test
@WithMockUser
@WebMvcTest
___

Create a free account to access the full topic