Java 使用Spring引导和安全性的集成测试
我们有一个Spring应用程序,使用Gradle构建,使用Spring Boot 1.2.5.RELEASE运行。我们使用Rest-Assured编写了一些初始集成测试,以针对我们的Rest端点进行测试。这是可行的,我们的应用程序的REST端点通过浏览器和Postman进行了适当的响应 然后,我们使用Spring安全性实现了OncePerRequestFilter和我们自己的AuthenticationProvider。我们的身份验证工作正常,浏览器和邮递员仍然收到适当的响应,但是我们的集成测试不再工作 通过一个测试,我们确实看到我们的控制器端点被调用并返回正确的输出,但超过这一点,我们会收到Java 使用Spring引导和安全性的集成测试,java,spring,spring-mvc,spring-security,Java,Spring,Spring Mvc,Spring Security,我们有一个Spring应用程序,使用Gradle构建,使用Spring Boot 1.2.5.RELEASE运行。我们使用Rest-Assured编写了一些初始集成测试,以针对我们的Rest端点进行测试。这是可行的,我们的应用程序的REST端点通过浏览器和Postman进行了适当的响应 然后,我们使用Spring安全性实现了OncePerRequestFilter和我们自己的AuthenticationProvider。我们的身份验证工作正常,浏览器和邮递员仍然收到适当的响应,但是我们的集成测试
org.springframework.web.util.NestedServletException的错误(带有null stacktrack):处理程序处理失败;嵌套异常为java.lang.AbstractMethodError
我们通过使用Spring Security初始化集成测试取得了进展,我们尝试放弃了Rest-Assured,只使用MockMvc,我们尝试返回到Rest-Assured并使用MockMvc初始化。到目前为止运气不好
下面是我们的初始化代码,注释掉的部分可以放心,当前的实现直接使用MockMvc
任何帮助都将不胜感激
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = IamExtensionApplication.class)
@WebIntegrationTest
public class OurIntegrationTest {
private MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;
// @Autowired
// private FilterChainProxy filterChainProxy;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).
apply(springSecurity()).
// addFilters(filterChainProxy).
build();
// RestAssuredMockMvc.mockMvc(mockMvc);
}
@Test
public void our_test() {
try {
ResultActions resp = amockMvc.perform(post("/our/endpoint").param("test", "test_value"));
} catch (Exception e) {
e.printStackTrace();
}
// MockMvcResponse resp = given()
// .param("test", "test_value")
// .when()
// .post("/our/endpoint");
}
我们尝试了这些配置的几种变体,但我们最终尝试了一种有效的配置(我们在任何地方都没有找到文档),那就是将我们的filterChainProxy作为参数传递给springSecurity()函数 希望这能帮助别人