Skip to content

Commit

Permalink
Fixing SleuthLogMessagesTest by initializing SystemStubs correctly us…
Browse files Browse the repository at this point in the history
…ing the JUnit5 extension via `@ExtendWith(SystemStubsExtension.class)`. Also we don't need to add the system-stubs-core dependency, since system-stubs-jupiter gets that transitively for us.
  • Loading branch information
jonashackt committed Jan 7, 2021
1 parent f96894e commit 57020a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
8 changes: 1 addition & 7 deletions cxf-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>system-stubs-core</artifactId>
<version>${system-stubs-jupiter.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>system-stubs-jupiter</artifactId>
Expand All @@ -157,6 +150,7 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
</plugin>
<!-- Used for testing purposes. -->
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import de.codecentric.namespace.weatherservice.WeatherException;
import de.codecentric.namespace.weatherservice.WeatherService;
import de.codecentric.namespace.weatherservice.general.GetCityForecastByZIP;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.Resource;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
import uk.org.webcompere.systemstubs.stream.SystemOut;

import java.io.IOException;
Expand All @@ -23,6 +23,7 @@
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertTrue;

@ExtendWith(SystemStubsExtension.class)
@SpringBootTest(
classes = TestApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
Expand All @@ -42,25 +43,20 @@ public class SleuthLogMessagesTest {
public void sleuth_meta_data_should_be_print_out() throws Exception {
callSoapService();

String log = systemOut.getLines().toString();

assertTrue(isSleuthLogLineSomewhereIn(log));
assertTrue(isSleuthLogLineSomewhereIn(systemOut.getText()));
}

private boolean isSleuthLogLineSomewhereIn(String log) {
Pattern sleuth_log_line_pattern = Pattern.compile("(INFO \\[,\\w+,\\w+,.*: Returning a forecast.)");
Pattern sleuth_log_line_pattern = Pattern.compile("(INFO \\[,\\w+,\\w+.*: Returning a forecast.)");
Matcher loglineMatcher = sleuth_log_line_pattern.matcher(log);
return loglineMatcher.find();
}

@Disabled
@Test public void
call_time_should_be_print_out() throws Exception {
callSoapService();

String log = systemOut.getLines().toString();

assertThat(log, containsString("Call time"));
assertThat(systemOut.getText(), containsString("Call time"));
}

private void callSoapService() throws de.codecentric.cxf.common.BootStarterCxfException, IOException, WeatherException {
Expand Down

0 comments on commit 57020a2

Please sign in to comment.