Skip to content

Commit 84424d8

Browse files
authored
Updates due to spring-boot auto-configuration changes in v2.7+ (#65)
* updated due to spring-boot autoconfiguration changes in version 2.7 https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.7-Release-Notes#changes-to-auto-configuration
1 parent e6aa4db commit 84424d8

File tree

11 files changed

+49
-54
lines changed

11 files changed

+49
-54
lines changed

.github/test-app/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>2.4.4</version>
8+
<version>2.7.10</version>
99
<relativePath/>
1010
</parent>
1111
<groupId>io.github.kilmajster</groupId>
1212
<artifactId>test-app</artifactId>
13-
<version>0.0.1</version>
13+
<version>0.0.2</version>
1414
<name>test-app</name>
1515
<description>Dummy app for tests</description>
1616
<properties>

.github/test-app/src/main/java/io/github/kilmajster/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.springframework.web.bind.annotation.RestController;
77

88
@RestController
9-
@SpringBootApplication(scanBasePackages = "io.github.kilmajster")
9+
@SpringBootApplication
1010
public class App {
1111
public static void main(String... args) { SpringApplication.run(App.class, args); }
1212

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ngrok.enabled=true
2+
ngrok.authToken=${NGROK_AUTH_TOKEN}

.github/test-app/src/test/java/io/github/kilmajster/AppTests.java

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,65 @@
33
import org.apache.commons.lang3.StringUtils;
44
import org.junit.jupiter.api.Test;
55
import org.junit.jupiter.api.extension.ExtendWith;
6-
import org.slf4j.Logger;
7-
import org.slf4j.LoggerFactory;
86
import org.springframework.boot.test.context.SpringBootTest;
97
import org.springframework.boot.test.system.CapturedOutput;
108
import org.springframework.boot.test.system.OutputCaptureExtension;
9+
import org.springframework.boot.test.web.server.LocalServerPort;
1110
import org.springframework.http.HttpStatus;
1211
import org.springframework.http.ResponseEntity;
1312
import org.springframework.web.client.RestTemplate;
1413

1514
import java.io.IOException;
1615
import java.net.URISyntaxException;
1716
import java.net.URL;
18-
import java.util.regex.Matcher;
19-
import java.util.regex.Pattern;
17+
import java.util.Arrays;
2018

2119
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.assertj.core.api.Assertions.fail;
2221

2322
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
2423
@ExtendWith(OutputCaptureExtension.class)
2524
class AppTests {
2625

27-
private final static Logger log = LoggerFactory.getLogger(AppTests.class);
28-
private static final int WAIT_FOR_STARTUP_SECONDS = 90;
29-
private static final String HTTPS_NGROK_TUNNEL_REGEX = "(https:\\/\\/)?(([^.]+)\\.)?ngrok\\.io";
26+
static final int WAIT_FOR_STARTUP_SECONDS = 90;
27+
28+
@LocalServerPort
29+
int serverPort;
3030

3131
@Test
32-
public void shouldStartNgrok(CapturedOutput output) throws IOException, URISyntaxException, InterruptedException {
33-
log.info("[ TEST ] Waiting for ngrok...");
32+
void should_start_ngrok_and_log_tunnel_details(CapturedOutput output) throws IOException, URISyntaxException, InterruptedException {
33+
System.out.println("[automation-test] Waiting for ngrok startup confirmation in output logs...");
34+
waitForNgrokStartConfirmationInLogs(output);
35+
final String ngrokHttpsTunnelUrl = extractNgrokHttpsTunnelUrlFromLogs(output);
36+
System.out.println("[automation-test] Ngrok tunnel is running between ::" + serverPort + " <-> " + ngrokHttpsTunnelUrl);
37+
38+
System.out.println("[automation-test] Executing GET request...");
39+
long timerStart = System.currentTimeMillis();
40+
final ResponseEntity<String> responseFromTunnel = new RestTemplate()
41+
.getForEntity(
42+
new URL(ngrokHttpsTunnelUrl).toURI(),
43+
String.class
44+
);
45+
long timerStop = System.currentTimeMillis();
46+
System.out.println("[automation-test] " + ngrokHttpsTunnelUrl + " responded in "
47+
+ (timerStop - timerStart) + "ms with\n\n" + responseFromTunnel + "\n");
48+
49+
assertThat(responseFromTunnel.getStatusCode()).isEqualTo(HttpStatus.OK);
50+
assertThat(responseFromTunnel.getBody()).isEqualTo("<h1>Hello World!</h1>");
51+
}
3452

35-
boolean ngrokStarted = false;
53+
private String extractNgrokHttpsTunnelUrlFromLogs(CapturedOutput output) {
54+
return Arrays.stream(StringUtils.split(output.toString(), " "))
55+
.filter(s -> s.startsWith("https://") && s.contains(".ngrok.io")).findFirst().get();
56+
}
3657

37-
Thread.sleep(1000);
58+
private void waitForNgrokStartConfirmationInLogs(CapturedOutput output) throws InterruptedException {
3859
for (int i = WAIT_FOR_STARTUP_SECONDS; i > 0; i--) {
3960
Thread.sleep(1000);
40-
if (output.toString().contains("Ngrok started successfully!")) {
41-
ngrokStarted = true;
42-
log.info("[ TEST ] Ngrok start detected!");
43-
break;
61+
if (output.toString().contains("Ngrok started successfully!") || output.toString().contains("Ngrok was already running!")) {
62+
return;
4463
}
4564
}
46-
47-
assertThat(ngrokStarted).isTrue();
48-
49-
Pattern pattern = Pattern.compile(HTTPS_NGROK_TUNNEL_REGEX);
50-
Matcher matcher = pattern.matcher(output.getOut());
51-
52-
assertThat(matcher.find()).isTrue();
53-
final String ngrokHttpsRemoteUrl = StringUtils.split(matcher.group(), "[")[1];
54-
log.info("[ TEST ] Captured ngrok tunnel url = [ {} ]", ngrokHttpsRemoteUrl);
55-
56-
ResponseEntity<String> responseFromTunnel = new RestTemplate().getForEntity(new URL(ngrokHttpsRemoteUrl).toURI(), String.class);
57-
58-
log.info("Response from [ {} ] = \n\n\n{}\n\n", ngrokHttpsRemoteUrl, responseFromTunnel.toString());
59-
60-
assertThat(responseFromTunnel.getStatusCode()).isEqualTo(HttpStatus.OK);
61-
assertThat(responseFromTunnel.getBody()).isEqualTo("<h1>Hello World!</h1>");
65+
fail("Ngrok not started!");
6266
}
63-
}
67+
}

.github/test-app/src/test/resources/application.properties

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/workflows/automation-test-macos.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ jobs:
2222
- name: Silent install main project
2323
run: mvn --batch-mode --no-transfer-progress install -Dmaven.test.skip=true
2424

25-
- name: Add ngrok auth token application.properties
26-
run: |
27-
printf ${{secrets.NGROK_AUTH_TOKEN_PROPERTY}} >> .github/test-app/src/test/resources/application.properties
28-
shell: bash
29-
3025
- name: Run automation tests with latest ngrok-spring-boot-starter version on test-app
3126
working-directory: ./.github/test-app/
27+
env:
28+
NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }}
3229
run: mvn --batch-mode --no-transfer-progress test
3330

3431

.github/workflows/automation-test-ubuntu.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ jobs:
2222
- name: Silent install main project
2323
run: mvn --batch-mode --no-transfer-progress install -Dmaven.test.skip=true
2424

25-
- name: Add ngrok auth token application.properties
26-
run: |
27-
printf ${{secrets.NGROK_AUTH_TOKEN_PROPERTY}} >> .github/test-app/src/test/resources/application.properties
28-
shell: bash
29-
3025
- name: Run automation tests with latest ngrok-spring-boot-starter version on test-app
3126
working-directory: ./.github/test-app/
27+
env:
28+
NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }}
3229
run: mvn --batch-mode --no-transfer-progress test

.github/workflows/automation-test-windows.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ jobs:
2222
- name: Silent install main project
2323
run: mvn --batch-mode --no-transfer-progress install -DskipTests
2424

25-
- name: Add ngrok auth token application.properties
26-
run: |
27-
printf ${{secrets.NGROK_AUTH_TOKEN_PROPERTY}} >> .github/test-app/src/test/resources/application.properties
28-
shell: bash
29-
3025
- name: Run automation tests with latest ngrok-spring-boot-starter version on test-app
3126
working-directory: ./.github/test-app/
27+
env:
28+
NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }}
3229
run: mvn --batch-mode --no-transfer-progress test

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<parent>
6060
<groupId>org.springframework.boot</groupId>
6161
<artifactId>spring-boot-starter-parent</artifactId>
62-
<version>2.6.6</version>
62+
<version>2.7.10</version>
6363
<relativePath/>
6464
</parent>
6565

src/main/resources/META-INF/spring.factories

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)