Skip to content

Commit 0cd4901

Browse files
authored
Added full implementation of ngrok API (#60)
* Added fully implementation of ngrok client API * progress with the API * [skip ci] set next development version * [skip ci] set next development version * progress with api * more of ngrok API implementation * [v0.4.0] Ngrok API implementation * Merge branch 'main' of https://github.com/kilmajster/ngrok-spring-boot-starter into full_ngrok_api # Conflicts: # pom.xml # src/main/java/ngrok/NgrokRunner.java * bumped dependencies versions
1 parent 2848c1d commit 0cd4901

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@
7373
<maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>
7474
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
7575

76-
<commons-io.version>2.8.0</commons-io.version>
76+
<commons-io.version>2.11.0</commons-io.version>
7777
<commons-lang3.version>3.12.0</commons-lang3.version>
78+
<vavr.version>0.10.4</vavr.version>
7879

79-
<spring-cloud-contract-wiremock.version>3.0.2</spring-cloud-contract-wiremock.version>
80+
<spring-cloud-contract-wiremock.version>3.0.3</spring-cloud-contract-wiremock.version>
8081
</properties>
8182

8283
<dependencies>
@@ -107,7 +108,7 @@
107108
<dependency>
108109
<groupId>io.vavr</groupId>
109110
<artifactId>vavr</artifactId>
110-
<version>0.10.3</version>
111+
<version>${vavr.version}</version>
111112
</dependency>
112113

113114
<dependency>

src/main/java/ngrok/api/NgrokApiClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,28 +115,28 @@ public boolean stopTunnel(final String tunnelName) {
115115
* Returns a list of all HTTP requests captured for inspection. This will only return requests
116116
* that are still in memory (ngrok evicts captured requests when their memory usage exceeds inspect_db_size)
117117
*/
118-
public List<NgrokCapturedRequest> listCapturedRequests(final int limit, final String tunnelName) {
118+
public List<NgrokCapturedRequest> listCapturedRequests(final Integer limit, final String tunnelName) {
119119
return Try.of(() -> restTemplate
120120
.getForObject(UriComponentsBuilder.fromUriString(
121121
apiUrlOf(URI_NGROK_API_CAPTURED_REQUESTS))
122-
.queryParamIfPresent("limit", limit > 0 ? Optional.of(limit) : Optional.empty())
122+
.queryParamIfPresent("limit", Optional.ofNullable(limit))
123123
.queryParamIfPresent("tunnel_name", Optional.ofNullable(tunnelName))
124124
.toUriString(),
125125
NgrokCapturedRequestsList.class
126126
).getRequests()
127127
).getOrElse(Collections.emptyList());
128128
}
129129

130-
public List<NgrokCapturedRequest> listCapturedRequests(final int limit) {
130+
public List<NgrokCapturedRequest> listCapturedRequests(final Integer limit) {
131131
return listCapturedRequests(limit, null);
132132
}
133133

134134
public List<NgrokCapturedRequest> listCapturedRequests(final String tunnelName) {
135-
return listCapturedRequests(-1, tunnelName);
135+
return listCapturedRequests(null, tunnelName);
136136
}
137137

138138
public List<NgrokCapturedRequest> listCapturedRequests() {
139-
return listCapturedRequests(-1, null);
139+
return listCapturedRequests(null, null);
140140
}
141141

142142
/**

src/test/java/ngrok/api/NgrokApiClientIntegrationTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ngrok.api;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import ngrok.api.model.NgrokCapturedRequest;
45
import ngrok.api.model.NgrokTunnel;
56
import ngrok.api.rquest.NgrokStartTunnel;
67
import ngrok.configuration.NgrokConfiguration;
@@ -26,6 +27,8 @@
2627
import static ngrok.api.NgrokApiClient.*;
2728
import static org.assertj.core.api.Assertions.assertThat;
2829
import static org.assertj.core.api.Assertions.assertThatThrownBy;
30+
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
31+
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
2932

3033
@ActiveProfiles(TEST_NGROK_PROFILE)
3134
@AutoConfigureWireMock(port = 4040)
@@ -122,7 +125,7 @@ public void startTunnel_shouldStartNgrokTunnel() throws IOException {
122125
.willReturn(
123126
aResponse()
124127
.withStatus(HttpStatus.CREATED.value())
125-
.withHeader("Content-Type", "application/json")
128+
.withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
126129
.withBody(tunnelAsJson)));
127130

128131
// when
@@ -162,7 +165,7 @@ public void tunnelDetail_shouldReturnTunnelDetailsWhenTunnelExistsForGivenName()
162165
.willReturn(
163166
aResponse()
164167
.withStatus(HttpStatus.OK.value())
165-
.withHeader("Content-Type", "application/json")
168+
.withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
166169
.withBody(tunnelAsJson)));
167170

168171
// when
@@ -182,7 +185,7 @@ public void tunnelDetail_shouldThrowExceptionWhenTunnelNotExistsForGivenName() {
182185
.willReturn(
183186
aResponse()
184187
.withStatus(HttpStatus.NOT_FOUND.value())
185-
.withHeader("Content-Type", "application/json")));
188+
.withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)));
186189

187190
// when & then
188191
assertThatThrownBy(() -> ngrokApiClient.tunnelDetail(TEST_INVALID_TUNNEL_NAME))
@@ -221,6 +224,4 @@ public void stopTunnel_shouldReturnFalseWhenTunnelForGivenNameWasNotStopped() {
221224
// then
222225
assertThat(tunnelStopped).isFalse();
223226
}
224-
225-
226227
}

0 commit comments

Comments
 (0)