org.springframework.boot.test.system.CapturedOutput Java Examples
The following examples show how to use
org.springframework.boot.test.system.CapturedOutput.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AsymmetricEncryptionNotAvailableTest.java From spring-cloud-config-aws-kms with Apache License 2.0 | 6 votes |
@Test void testAsymmetricEncryptionIsNotAvailable(CapturedOutput output) { doThrow(InvalidKeyUsageException.class).when(mockKms).encrypt(any(EncryptRequest.class)); try { // Asymmetric algorithm is not available, because an outdated AWS SDK is used. The textEncryptor will // print a warning and fall back to symmetric algorithm. // Trying to use an asymmetric key with the symmetric algorithm will lead to an exception. textEncryptor.encrypt(PLAINTEXT); failBecauseExceptionWasNotThrown(InvalidKeyUsageException.class); } catch (InvalidKeyUsageException ignored) { assertThat(output).contains(VERSION_HINT); final EncryptRequest expectedRequest = new EncryptRequest() .withKeyId("an-asymmetric-key") .withPlaintext(ByteBuffer.wrap(PLAINTEXT.getBytes())); verify(mockKms).encrypt(eq(expectedRequest)); } }
Example #2
Source File: AsymmetricEncryptionNotAvailableTest.java From spring-cloud-config-aws-kms with Apache License 2.0 | 6 votes |
@Test void testAsymmetricDecryptionIsNotAvailable(CapturedOutput output) { doThrow(InvalidCiphertextException.class).when(mockKms).decrypt(any(DecryptRequest.class)); try { // Asymmetric algorithm is not available, because an outdated AWS SDK is used. The textEncryptor will // print a warning and fall back to symmetric algorithm. // Trying to use an asymmetric key with the symmetric algorithm will lead to an exception. textEncryptor.decrypt(CIPHERTEXT); failBecauseExceptionWasNotThrown(InvalidCiphertextException.class); } catch (InvalidCiphertextException ignored) { assertThat(output).contains(VERSION_HINT); final DecryptRequest expectedRequest = new DecryptRequest() .withCiphertextBlob(ByteBuffer.wrap(Base64.getDecoder().decode(CIPHERTEXT.getBytes()))); verify(mockKms).decrypt(eq(expectedRequest)); } }
Example #3
Source File: TraceFilterWebIntegrationTests.java From spring-cloud-sleuth with Apache License 2.0 | 6 votes |
@Test public void exception_logging_span_handler_logs_synchronous_exceptions( CapturedOutput capture) { try { new RestTemplate().getForObject("http://localhost:" + port() + "/", String.class); BDDAssertions.fail("should fail due to runtime exception"); } catch (Exception e) { } then(this.currentTraceContext.get()).isNull(); MutableSpan fromFirstTraceFilterFlow = spanHandler.takeRemoteSpanWithErrorMessage( Kind.SERVER, "Request processing failed; nested exception is java.lang.RuntimeException: Throwing exception"); then(fromFirstTraceFilterFlow.tags()).containsEntry("http.method", "GET") .containsEntry("mvc.controller.class", "BasicErrorController"); // Trace IDs in logs: issue#714 String hex = fromFirstTraceFilterFlow.traceId(); thenLogsForExceptionLoggingFilterContainTracingInformation(capture, hex); }
Example #4
Source File: FlatMapTests.java From spring-cloud-sleuth with Apache License 2.0 | 6 votes |
@Test public void should_work_with_flat_maps_with_on_last_operator_instrumentation( CapturedOutput capture) { // given ConfigurableApplicationContext context = new SpringApplicationBuilder( FlatMapTests.TestConfiguration.class, Issue866Configuration.class) .web(WebApplicationType.REACTIVE) .properties("server.port=0", "spring.jmx.enabled=false", "spring.sleuth.reactor.decorate-on-each=false", "spring.application.name=TraceWebFlux2Tests", "security.basic.enabled=false", "management.security.enabled=false") .run(); assertReactorTracing(context, capture); try { System.setProperty("spring.sleuth.reactor.decorate-on-each", "true"); // trigger context refreshed context.getBean(ContextRefresher.class).refresh(); assertReactorTracing(context, capture); } finally { System.clearProperty("spring.sleuth.reactor.decorate-on-each"); } }
Example #5
Source File: SampleFeignApplicationTests.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
@Test public void should_not_pass_dash_as_default_service_name( CapturedOutput outputCapture) { log.info("HELLO"); BDDAssertions.then(outputCapture.toString()).doesNotContain("INFO [-,,,]"); }
Example #6
Source File: TraceAutoConfigurationWithDisabledSleuthTests.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
@Test public void shouldNotContainAnyTracingInfoInTheLogs(CapturedOutput capture) { log.info("hello"); // prove bootstrap-disabled.yml loaded assertThat(applicationName).isEqualTo("foo"); // spring.application.name is put in the log format by // TraceEnvironmentPostProcessor // checking for the service name here ensures this isn't accidentally loaded BDDAssertions.then(capture.toString()).doesNotContain("[foo"); }
Example #7
Source File: TraceFilterWebIntegrationTests.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
private void thenLogsForExceptionLoggingFilterContainTracingInformation( CapturedOutput capture, String hex) { String[] split = capture.toString().split("\n"); List<String> list = Arrays.stream(split) .filter(s -> s.contains("Uncaught exception thrown")) .filter(s -> s.contains(hex + "," + hex + "]")) .collect(Collectors.toList()); then(list).isNotEmpty(); }
Example #8
Source File: FlatMapTests.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
@Test public void should_work_with_flat_maps(CapturedOutput capture) { // given ConfigurableApplicationContext context = new SpringApplicationBuilder( FlatMapTests.TestConfiguration.class, Issue866Configuration.class) .web(WebApplicationType.REACTIVE) .properties("server.port=0", "spring.jmx.enabled=false", "spring.application.name=TraceWebFluxTests", "security.basic.enabled=false", "management.security.enabled=false") .run(); assertReactorTracing(context, capture); }
Example #9
Source File: RscTest.java From rsc with Apache License 2.0 | 4 votes |
@Test void test(CapturedOutput capture) throws Exception { Rsc.main(new String[]{}); assertThat(capture.toString()).isNotEmpty(); }
Example #10
Source File: SleuthKafkaStreamsConfigurationIntegrationTests.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
@AfterEach void afterEach(CapturedOutput output) { assertThat(output).doesNotContain( "is not eligible for getting processed by all BeanPostProcessors"); }
Example #11
Source File: FlatMapTests.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
private void assertReactorTracing(ConfigurableApplicationContext context, CapturedOutput capture) { TestSpanHandler spans = context.getBean(TestSpanHandler.class); int port = context.getBean(Environment.class).getProperty("local.server.port", Integer.class); RequestSender sender = context.getBean(RequestSender.class); TestConfiguration config = context.getBean(TestConfiguration.class); FactoryUser factoryUser = context.getBean(FactoryUser.class); sender.port = port; spans.clear(); Awaitility.await().untilAsserted(() -> { // when LOGGER.info("Start"); spans.clear(); String firstTraceId = flatMapTraceId(spans, callFlatMap(port).block()); // then LOGGER.info("Checking first trace id"); thenAllWebClientCallsHaveSameTraceId(firstTraceId, sender); thenSpanInFooHasSameTraceId(firstTraceId, config); spans.clear(); LOGGER.info("All web client calls have same trace id"); // when LOGGER.info("Second trace start"); String secondTraceId = flatMapTraceId(spans, callFlatMap(port).block()); // then then(firstTraceId).as("Id will not be reused between calls") .isNotEqualTo(secondTraceId); LOGGER.info("Id was not reused between calls"); thenSpanInFooHasSameTraceId(secondTraceId, config); LOGGER.info("Span in Foo has same trace id"); // and List<String> requestUri = Arrays.stream(capture.toString().split("\n")) .filter(s -> s.contains("Received a request to uri")) .map(s -> s.split(",")[1]).collect(Collectors.toList()); LOGGER.info( "TracingFilter should not have any trace when receiving a request " + requestUri); then(requestUri).as( "TracingFilter should not have any trace when receiving a request") .containsOnly(""); // and #866 then(factoryUser.wasSchedulerWrapped).isTrue(); LOGGER.info("Factory was wrapped"); }); }