dimanche 29 octobre 2017

Could 'Spring RESTful' + 'Java Config' + 'Tests' be used without Spring MVC?

Can't make tests working with such a configuration.

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@WebAppConfiguration
@TestPropertySource(value="classpath:app-test.properties")
public class LoginTest {

    @Autowired
    private WebApplicationContext context;

    MockMvc mockMvc;

    @InjectMocks
    private AuthController authController;

    @Test
    public void testOk() throws Exception {
        MockitoAnnotations.initMocks(this);
        mockMvc = MockMvcBuilders
                    .webAppContextSetup(context)
                    .apply(springSecurity())
                    .build();
        mockMvc.perform(get("/api/auth")
            .with(httpBasic("u", "p")))
            .andExpect(status().isOk());
    }

}

Getting error:

java.lang.IllegalStateException: springSecurityFilterChain cannot be null. Ensure a Bean with the name springSecurityFilterChain implementing Filter is present or inject the Filter to be used.

Aucun commentaire:

Enregistrer un commentaire