21
21
import java .util .Collections ;
22
22
import java .util .Map ;
23
23
24
+ import com .fasterxml .jackson .core .JsonProcessingException ;
25
+ import com .fasterxml .jackson .databind .ObjectMapper ;
24
26
import org .junit .Test ;
25
27
import org .junit .runner .RunWith ;
26
28
import org .mockito .Mockito ;
@@ -177,7 +179,7 @@ public void containerImageMetadataResolverWithActiveSSL() throws URISyntaxExcept
177
179
eq (HttpMethod .GET ), any (), eq (Map .class ));
178
180
// Get Blobs
179
181
verify (containerRestTemplate ).exchange (eq (new URI ("https://demo.goharbor.io/v2/test/image/blobs/test_digest" )),
180
- eq (HttpMethod .GET ), any (), eq (String .class ));
182
+ eq (HttpMethod .GET ), any (), eq (Map .class ));
181
183
}
182
184
183
185
@ Test
@@ -199,7 +201,7 @@ public void containerImageMetadataResolverWithDisabledSSL() throws URISyntaxExce
199
201
eq (HttpMethod .GET ), any (), eq (Map .class ));
200
202
// Get Blobs
201
203
verify (noSslVerificationContainerRestTemplate ).exchange (eq (new URI ("https://demo.repository.io/v2/disabledssl/image/blobs/test_digest" )),
202
- eq (HttpMethod .GET ), any (), eq (String .class ));
204
+ eq (HttpMethod .GET ), any (), eq (Map .class ));
203
205
}
204
206
205
207
@ ImportAutoConfiguration ({ ContainerRegistryAutoConfiguration .class , ApplicationConfigurationMetadataResolverAutoConfiguration .class })
@@ -221,7 +223,7 @@ public ContainerImageRestTemplateFactory containerImageRestTemplateFactory(
221
223
}
222
224
223
225
@ Bean (name = "noSslVerificationContainerRestTemplate" )
224
- RestTemplate noSslVerificationContainerRestTemplate () throws URISyntaxException {
226
+ RestTemplate noSslVerificationContainerRestTemplate () throws URISyntaxException , JsonProcessingException {
225
227
RestTemplate restTemplate = Mockito .mock (RestTemplate .class );
226
228
227
229
// demo.repository.io
@@ -249,8 +251,8 @@ RestTemplate noSslVerificationContainerRestTemplate() throws URISyntaxException
249
251
when (restTemplate
250
252
.exchange (
251
253
eq (new URI ("https://demo.repository.io/v2/disabledssl/image/blobs/test_digest" )),
252
- eq (HttpMethod .GET ), any (), eq (String .class )))
253
- .thenReturn (new ResponseEntity <>("{ \" config \" : { \" Labels \" : { \" foo \" : \" bar \" } } }" , HttpStatus .OK ));
254
+ eq (HttpMethod .GET ), any (), eq (Map .class )))
255
+ .thenReturn (new ResponseEntity <>(blobValue () , HttpStatus .OK ));
254
256
255
257
// demo.goharbor.io
256
258
HttpHeaders authenticateHeader2 = new HttpHeaders ();
@@ -265,7 +267,7 @@ RestTemplate noSslVerificationContainerRestTemplate() throws URISyntaxException
265
267
}
266
268
267
269
@ Bean (name = "containerRestTemplate" )
268
- RestTemplate containerRestTemplate () throws URISyntaxException {
270
+ RestTemplate containerRestTemplate () throws URISyntaxException , JsonProcessingException {
269
271
RestTemplate restTemplate = Mockito .mock (RestTemplate .class );
270
272
271
273
when (restTemplate
@@ -283,14 +285,14 @@ RestTemplate containerRestTemplate() throws URISyntaxException {
283
285
when (restTemplate
284
286
.exchange (
285
287
eq (new URI ("https://demo.goharbor.io/v2/test/image/blobs/test_digest" )),
286
- eq (HttpMethod .GET ), any (), eq (String .class )))
287
- .thenReturn (new ResponseEntity <>("{ \" config \" : { \" Labels \" : { \" foo \" : \" bar \" } } }" , HttpStatus .OK ));
288
+ eq (HttpMethod .GET ), any (), eq (Map .class )))
289
+ .thenReturn (new ResponseEntity <>(blobValue () , HttpStatus .OK ));
288
290
289
291
return restTemplate ;
290
292
}
291
293
292
294
@ Bean (name = "containerRestTemplateWithHttpProxy" )
293
- RestTemplate containerRestTemplateWithHttpProxy () throws URISyntaxException {
295
+ RestTemplate containerRestTemplateWithHttpProxy () throws URISyntaxException , JsonProcessingException {
294
296
RestTemplate restTemplate = Mockito .mock (RestTemplate .class );
295
297
296
298
when (restTemplate
@@ -308,14 +310,14 @@ RestTemplate containerRestTemplateWithHttpProxy() throws URISyntaxException {
308
310
when (restTemplate
309
311
.exchange (
310
312
eq (new URI ("https://demo2.goharbor.io/v2/test/image/blobs/test_digest" )),
311
- eq (HttpMethod .GET ), any (), eq (String .class )))
312
- .thenReturn (new ResponseEntity <>("{ \" config \" : { \" Labels \" : { \" foo \" : \" bar \" } } }" , HttpStatus .OK ));
313
+ eq (HttpMethod .GET ), any (), eq (Map .class )))
314
+ .thenReturn (new ResponseEntity <>(blobValue () , HttpStatus .OK ));
313
315
314
316
return restTemplate ;
315
317
}
316
318
317
319
@ Bean (name = "noSslVerificationContainerRestTemplateWithHttpProxy" )
318
- RestTemplate noSslVerificationContainerRestTemplateWithHttpProxy () throws URISyntaxException {
320
+ RestTemplate noSslVerificationContainerRestTemplateWithHttpProxy () throws URISyntaxException , JsonProcessingException {
319
321
RestTemplate restTemplate = Mockito .mock (RestTemplate .class );
320
322
321
323
// demo.repository.io
@@ -343,8 +345,8 @@ RestTemplate noSslVerificationContainerRestTemplateWithHttpProxy() throws URISyn
343
345
when (restTemplate
344
346
.exchange (
345
347
eq (new URI ("https://demo2.repository.io/v2/disabledssl/image/blobs/test_digest" )),
346
- eq (HttpMethod .GET ), any (), eq (String .class )))
347
- .thenReturn (new ResponseEntity <>("{ \" config \" : { \" Labels \" : { \" foo \" : \" bar \" } } }" , HttpStatus .OK ));
348
+ eq (HttpMethod .GET ), any (), eq (Map .class )))
349
+ .thenReturn (new ResponseEntity <>(blobValue () , HttpStatus .OK ));
348
350
349
351
// demo.goharbor.io
350
352
HttpHeaders authenticateHeader2 = new HttpHeaders ();
@@ -357,5 +359,10 @@ RestTemplate noSslVerificationContainerRestTemplateWithHttpProxy() throws URISyn
357
359
358
360
return restTemplate ;
359
361
}
362
+
363
+ public Map blobValue () throws JsonProcessingException {
364
+ return new ObjectMapper ().readValue ("{\" config\" : {\" Labels\" : {\" foo\" : \" bar\" } } }" , Map .class );
365
+ }
366
+
360
367
}
361
368
}
0 commit comments