Skip to content

Commit 3b8ebce

Browse files
WeltraumschafManuelNeuer
authored andcommitted
#36 Extract method with network side effect, so we can mock this out in the tests
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
1 parent 9dfb617 commit 3b8ebce

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/main/java/io/securecodebox/persistence/defectdojo/service/DefaultImportScanService.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,22 @@ public String getFilename() {
119119
body.add("file", contentsAsResource);
120120

121121
final var payload = new HttpEntity<MultiValueMap<String, Object>>(body, headers);
122-
123-
final var restTemplate = this.createRestTemplate();
124-
return restTemplate.exchange(
125-
generateApiUrl(endpoint),
126-
HttpMethod.POST,
127-
payload,
128-
ImportScanResponse.class)
129-
.getBody();
122+
return exchangeRequest(endpoint, payload);
130123
} catch (HttpClientErrorException e) {
131124
throw new DefectDojoPersistenceException("Failed to attach findings to engagement.");
132125
}
133126
}
134127

128+
ImportScanResponse exchangeRequest(String endpoint, HttpEntity<?> payload) {
129+
final var restTemplate = this.createRestTemplate();
130+
return restTemplate.exchange(
131+
generateApiUrl(endpoint),
132+
HttpMethod.POST,
133+
payload,
134+
ImportScanResponse.class)
135+
.getBody();
136+
}
137+
135138
String generateApiUrl(final String endpoint) {
136139
return String.format("%s/api/v2/%s/", getDefectDojoUrl(), endpoint);
137140
}

0 commit comments

Comments
 (0)