小编Ole*_* K.的帖子

当 MockRestServiceServer 设置为 ExpectedCount.manyTimes() 时,预计不会有进一步的请求

我的 spring-integration 应用程序有以下测试类,该应用程序成功通过单独启动

@SpringBootTest(classes = {BackupTestDefinition.class})
@ActiveProfiles({"test", "dev"})
@RunWith(SpringRunner.class)
public class BackupServiceTest {
    @Value(value = "${ne.endpoint}")
    private String ne;
    @Autowired
    private RestTemplate restTemplate;    
    private MockRestServiceServer mockServer;

    @Before
    public void setup() {
        mockServer = MockRestServiceServer.bindTo(restTemplate).build(new UnorderedRequestExpectationManager());
        mockServer.expect(ExpectedCount.manyTimes(), requestTo(UriComponentsBuilder.fromHttpUrl(ne).build().toUri())).andExpect(method(HttpMethod.POST)).andRespond(withSuccess());
    }

    @Test
    public void testNotificationProcessing() throws IOException, InterruptedException, InitializationException, ExecutionException {
        //some testing code
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我有另一个测试,它具有相同端点的其他设置 (ExpectedCount.times(1)) 并且具有不同的 TestDefinition。所以在这个测试套件中缓存了几个上下文。当我一起启动它们时,我收到以下异常

at org.springframework.test.web.client.AbstractRequestExpectationManager.createUnexpectedRequestError(AbstractRequestExpectationManager.java:141)
at org.springframework.test.web.client.UnorderedRequestExpectationManager.validateRequestInternal(UnorderedRequestExpectationManager.java:49)
at org.springframework.test.web.client.AbstractRequestExpectationManager.validateRequest(AbstractRequestExpectationManager.java:76)
at org.springframework.test.web.client.MockRestServiceServer$MockClientHttpRequestFactory$1.executeInternal(MockRestServiceServer.java:289)
at org.springframework.mock.http.client.MockClientHttpRequest.execute(MockClientHttpRequest.java:94)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:659)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:620)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:538)
Caused by: java.lang.AssertionError: No further requests expected: …
Run Code Online (Sandbox Code Playgroud)

spring spring-integration spring-boot spring-boot-test

5
推荐指数
1
解决办法
1万
查看次数

logback-classic 版本 1.2.9 中的 ContextInitializer 不支持 Groovy 配置文件

更新到 spring-boot-starter-parent 2.6.2,我的应用程序由于以下错误而无法启动

Unexpected filename extension of file [file:logback.groovy]. Should be either .groovy or .xml。查看上述类的源代码,发现以下内容:

        final String urlString = url.toString();
        if (urlString.endsWith("xml")) {
            JoranConfigurator configurator = new JoranConfigurator();
            configurator.setContext(loggerContext);
            configurator.doConfigure(url);
        } else {
            throw new LogbackException("Unexpected filename extension of file [" + url.toString() + "]. Should be either .groovy or .xml");
        }
Run Code Online (Sandbox Code Playgroud)

那么看起来在最新版本中他们刚刚删除了 groovy 支持?除了回到Excel配置之外还有什么解决办法吗?谢谢

groovy spring-boot

4
推荐指数
1
解决办法
2773
查看次数