use of cn.taketoday.framework.test.system.CapturedOutput in project today-infrastructure by TAKETODAY.
the class ErrorPageFilterTests method responseCommittedWhenFromClientAbortException.
@Test
void responseCommittedWhenFromClientAbortException(CapturedOutput output) throws Exception {
this.filter.addErrorPages(new ErrorPage("/error"));
this.response.setCommitted(true);
this.chain = new TestFilterChain((request, response, chain) -> {
chain.call();
throw new ClientAbortException();
});
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.response.isCommitted()).isTrue();
assertThat(output).doesNotContain("Cannot forward");
}
use of cn.taketoday.framework.test.system.CapturedOutput in project today-infrastructure by TAKETODAY.
the class ApplicationTests method runnersAreCalledAfterStartedIsLoggedAndBeforeApplicationReadyEventIsPublished.
@Test
@SuppressWarnings("unchecked")
void runnersAreCalledAfterStartedIsLoggedAndBeforeApplicationReadyEventIsPublished(CapturedOutput output) throws Exception {
Application application = new Application(ExampleConfig.class);
ApplicationRunner applicationRunner = mock(ApplicationRunner.class);
CommandLineRunner commandLineRunner = mock(CommandLineRunner.class);
application.addInitializers((context) -> {
ConfigurableBeanFactory beanFactory = context.getBeanFactory();
beanFactory.registerSingleton("commandLineRunner", (CommandLineRunner) (args) -> {
assertThat(output).contains("Started");
commandLineRunner.run(args);
});
beanFactory.registerSingleton("applicationRunner", (ApplicationRunner) (args) -> {
assertThat(output).contains("Started");
applicationRunner.run(args);
});
});
application.setApplicationType(ApplicationType.NONE_WEB);
ApplicationListener<ApplicationReadyEvent> eventListener = mock(ApplicationListener.class);
application.addListeners(eventListener);
this.context = application.run();
InOrder applicationRunnerOrder = Mockito.inOrder(eventListener, applicationRunner);
applicationRunnerOrder.verify(applicationRunner).run(any(ApplicationArguments.class));
applicationRunnerOrder.verify(eventListener).onApplicationEvent(any(ApplicationReadyEvent.class));
InOrder commandLineRunnerOrder = Mockito.inOrder(eventListener, commandLineRunner);
commandLineRunnerOrder.verify(commandLineRunner).run();
commandLineRunnerOrder.verify(eventListener).onApplicationEvent(any(ApplicationReadyEvent.class));
}
use of cn.taketoday.framework.test.system.CapturedOutput in project today-framework by TAKETODAY.
the class ErrorPageFilterTests method responseCommittedWhenFromClientAbortException.
@Test
void responseCommittedWhenFromClientAbortException(CapturedOutput output) throws Exception {
this.filter.addErrorPages(new ErrorPage("/error"));
this.response.setCommitted(true);
this.chain = new TestFilterChain((request, response, chain) -> {
chain.call();
throw new ClientAbortException();
});
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.response.isCommitted()).isTrue();
assertThat(output).doesNotContain("Cannot forward");
}
use of cn.taketoday.framework.test.system.CapturedOutput in project today-framework by TAKETODAY.
the class ErrorPageFilterTests method errorMessageForRequestWithPathInfo.
@Test
void errorMessageForRequestWithPathInfo(CapturedOutput output) throws IOException, ServletException {
this.request.setServletPath("/test");
this.request.setPathInfo("/alpha");
this.filter.addErrorPages(new ErrorPage("/error"));
this.chain = new TestFilterChain((request, response, chain) -> {
chain.call();
throw new RuntimeException();
});
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(output).contains("request [/test/alpha]");
}
use of cn.taketoday.framework.test.system.CapturedOutput in project today-framework by TAKETODAY.
the class ErrorPageFilterTests method errorMessageForRequestWithoutPathInfo.
@Test
void errorMessageForRequestWithoutPathInfo(CapturedOutput output) throws IOException, ServletException {
this.request.setServletPath("/test");
this.filter.addErrorPages(new ErrorPage("/error"));
this.chain = new TestFilterChain((request, response, chain) -> {
chain.call();
throw new RuntimeException();
});
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(output).contains("request [/test]");
}
Aggregations