5
5
6
6
import com .fasterxml .jackson .core .JsonProcessingException ;
7
7
import io .securecodebox .persistence .defectdojo .model .Endpoint ;
8
- import org .junit .jupiter .api .Disabled ;
9
8
import org .junit .jupiter .api .Test ;
10
9
11
10
import java .io .IOException ;
22
21
* Tests for {@link EndpointService}
23
22
*/
24
23
final class EndpointServiceTest extends WireMockBaseTestCase {
24
+ private static final String RESPONSE_LIST_FIXTURE_JSON = "EndpointService_response_list_fixture.json" ;
25
25
private final EndpointService sut = new EndpointService (conf ());
26
26
private final Endpoint [] expectedFromSearch = new Endpoint []{
27
27
Endpoint .builder ()
@@ -62,7 +62,7 @@ final class EndpointServiceTest extends WireMockBaseTestCase {
62
62
63
63
@ Test
64
64
void search () throws URISyntaxException , IOException {
65
- final var response = readFixtureFile ("EndpointService_response_fixture.json" );
65
+ final var response = readFixtureFile (RESPONSE_LIST_FIXTURE_JSON );
66
66
stubFor (get (urlPathEqualTo ("/api/v2/endpoints/" ))
67
67
.withQueryParam ("limit" , equalTo ("100" ))
68
68
.withQueryParam ("offset" , equalTo ("0" ))
@@ -81,7 +81,7 @@ void search() throws URISyntaxException, IOException {
81
81
82
82
@ Test
83
83
void search_withQueryParams () throws URISyntaxException , IOException {
84
- final var response = readFixtureFile ("EndpointService_response_fixture.json" );
84
+ final var response = readFixtureFile (RESPONSE_LIST_FIXTURE_JSON );
85
85
stubFor (get (urlPathEqualTo ("/api/v2/endpoints/" ))
86
86
.withQueryParam ("limit" , equalTo ("100" ))
87
87
.withQueryParam ("offset" , equalTo ("0" ))
@@ -150,25 +150,17 @@ void get_byId() {
150
150
void searchUnique_withSearchObjectWhichReturnsEmptyResult () throws URISyntaxException , JsonProcessingException {
151
151
// Here we only test that the object properties are correctly mapped to get params,
152
152
// since the response parsing and binding is covered by the other tests.
153
- final var response = """
154
- {
155
- "count": 0,
156
- "next": null,
157
- "previous": null,
158
- "results": [],
159
- "prefetch": {}
160
- }
161
- """ ;
162
153
stubFor (get (urlPathEqualTo ("/api/v2/endpoints/" ))
163
154
.withQueryParam ("limit" , equalTo ("100" ))
164
- .withQueryParam ("product" , equalTo ("285" ))
165
- .withQueryParam ("id" , equalTo ("42" ))
166
155
.withQueryParam ("offset" , equalTo ("0" ))
156
+ .withQueryParam ("id" , equalTo ("42" ))
157
+ .withQueryParam ("product" , equalTo ("285" ))
158
+ // Defaults from model:
167
159
.withQueryParam ("port" , equalTo ("0" ))
168
160
.withQueryParam ("mitigated" , equalTo ("false" ))
169
161
.willReturn (ok ()
170
- .withHeaders (responseHeaders (response .length ()))
171
- .withBody (response )
162
+ .withHeaders (responseHeaders (EMPTY_SEARCH_RESULT_RESPONSE_FIXTURE .length ()))
163
+ .withBody (EMPTY_SEARCH_RESULT_RESPONSE_FIXTURE )
172
164
));
173
165
final var searchObject = Endpoint .builder ()
174
166
.id (42 )
@@ -184,23 +176,14 @@ void searchUnique_withSearchObjectWhichReturnsEmptyResult() throws URISyntaxExce
184
176
void searchUnique_withQueryParamsWhichReturnsEmptyResult () throws URISyntaxException , JsonProcessingException {
185
177
// Here we only test that the object properties are correctly mapped to get params,
186
178
// since the response parsing and binding is covered by the other tests.
187
- final var response = """
188
- {
189
- "count": 0,
190
- "next": null,
191
- "previous": null,
192
- "results": [],
193
- "prefetch": {}
194
- }
195
- """ ;
196
179
stubFor (get (urlPathEqualTo ("/api/v2/endpoints/" ))
197
180
.withQueryParam ("limit" , equalTo ("100" ))
198
181
.withQueryParam ("offset" , equalTo ("0" ))
199
182
.withQueryParam ("foo" , equalTo ("42" ))
200
183
.withQueryParam ("bar" , equalTo ("23" ))
201
184
.willReturn (ok ()
202
- .withHeaders (responseHeaders (response .length ()))
203
- .withBody (response )
185
+ .withHeaders (responseHeaders (EMPTY_SEARCH_RESULT_RESPONSE_FIXTURE .length ()))
186
+ .withBody (EMPTY_SEARCH_RESULT_RESPONSE_FIXTURE )
204
187
));
205
188
final var queryParams = new HashMap <String , Object >();
206
189
queryParams .put ("foo" , 42 );
0 commit comments