26
26
27
27
import com .fasterxml .jackson .core .JsonProcessingException ;
28
28
import com .fasterxml .jackson .databind .ObjectMapper ;
29
- import com .google .common .base .Strings ;
30
29
import com .google .common .collect .Lists ;
31
30
import com .google .common .io .CharStreams ;
32
31
50
49
import org .eclipse .openvsx .storage .GoogleCloudStorageService ;
51
50
import org .eclipse .openvsx .storage .StorageUtilService ;
52
51
import org .eclipse .openvsx .util .TargetPlatform ;
53
- import org .eclipse .openvsx .util .VersionUtil ;
54
52
import org .elasticsearch .search .aggregations .Aggregations ;
55
53
import org .junit .jupiter .api .Test ;
56
54
import org .mockito .Mockito ;
65
63
import org .springframework .data .elasticsearch .core .SearchHitsImpl ;
66
64
import org .springframework .data .elasticsearch .core .TotalHitsRelation ;
67
65
import org .springframework .data .util .Streamable ;
66
+ import org .springframework .http .HttpHeaders ;
68
67
import org .springframework .http .MediaType ;
69
68
import org .springframework .security .oauth2 .client .registration .ClientRegistrationRepository ;
70
69
import org .springframework .test .web .servlet .MockMvc ;
@@ -223,6 +222,7 @@ public void testAsset() throws Exception {
223
222
mockMvc .perform (get ("/vscode/asset/{namespace}/{extensionName}/{version}/{assetType}" ,
224
223
"redhat" , "vscode-yaml" , "0.5.2" , "Microsoft.VisualStudio.Code.Manifest" ))
225
224
.andExpect (status ().isOk ())
225
+ .andExpect (header ().string (HttpHeaders .CONTENT_TYPE , MediaType .APPLICATION_JSON_VALUE ))
226
226
.andExpect (content ().string ("{\" foo\" :\" bar\" }" ));
227
227
}
228
228
@@ -233,6 +233,7 @@ public void testAssetMacOSX() throws Exception {
233
233
mockMvc .perform (get ("/vscode/asset/{namespace}/{extensionName}/{version}/{assetType}?targetPlatform={target}" ,
234
234
"redhat" , "vscode-yaml" , "0.5.2" , "Microsoft.VisualStudio.Code.Manifest" , target ))
235
235
.andExpect (status ().isOk ())
236
+ .andExpect (header ().string (HttpHeaders .CONTENT_TYPE , MediaType .APPLICATION_JSON_VALUE ))
236
237
.andExpect (content ().string ("{\" foo\" :\" bar\" ,\" target\" :\" darwin-arm64\" }" ));
237
238
}
238
239
@@ -246,6 +247,15 @@ public void testAssetNotFound() throws Exception {
246
247
.andExpect (status ().isNotFound ());
247
248
}
248
249
250
+ @ Test
251
+ public void testAssetVsixPackage () throws Exception {
252
+ mockExtension ();
253
+ mockMvc .perform (get ("/vscode/asset/{namespace}/{extensionName}/{version}/{assetType}" ,
254
+ "redhat" , "vscode-yaml" , "0.5.2" , "Microsoft.VisualStudio.Services.VSIXPackage" ))
255
+ .andExpect (status ().isOk ())
256
+ .andExpect (header ().string (HttpHeaders .CONTENT_TYPE , "application/vsix" ));
257
+ }
258
+
249
259
@ Test
250
260
public void testGetItem () throws Exception {
251
261
mockMvc .perform (get ("/vscode/item?itemName={itemName}" , "redhat.vscode-yaml" ))
@@ -254,14 +264,55 @@ public void testGetItem() throws Exception {
254
264
}
255
265
256
266
@ Test
257
- public void testWebResourceAsset () throws Exception {
267
+ public void testPngWebResourceAsset () throws Exception {
258
268
mockExtension ();
259
269
mockMvc .perform (get ("/vscode/asset/{namespace}/{extensionName}/{version}/{assetType}" ,
260
270
"redhat" , "vscode-yaml" , "0.5.2" , "Microsoft.VisualStudio.Code.WebResources/extension/img/logo.png" ))
261
271
.andExpect (status ().isOk ())
272
+ .andExpect (header ().string (HttpHeaders .CONTENT_TYPE , MediaType .IMAGE_PNG_VALUE ))
262
273
.andExpect (content ().string ("logo.png" ));
263
274
}
264
275
276
+ @ Test
277
+ public void testCssWebResourceAsset () throws Exception {
278
+ mockExtension ();
279
+ mockMvc .perform (get ("/vscode/asset/{namespace}/{extensionName}/{version}/{assetType}" ,
280
+ "redhat" , "vscode-yaml" , "0.5.2" , "Microsoft.VisualStudio.Code.WebResources/extension/public/static/css/main.css" ))
281
+ .andExpect (status ().isOk ())
282
+ .andExpect (header ().string (HttpHeaders .CONTENT_TYPE , "text/css" ))
283
+ .andExpect (content ().string (".main { margin: 0 auto; }" ));
284
+ }
285
+
286
+ @ Test
287
+ public void testChunkCssWebResourceAsset () throws Exception {
288
+ mockExtension ();
289
+ mockMvc .perform (get ("/vscode/asset/{namespace}/{extensionName}/{version}/{assetType}" ,
290
+ "redhat" , "vscode-yaml" , "0.5.2" , "Microsoft.VisualStudio.Code.WebResources/extension/public/static/css/main.9cab4879.chunk.css" ))
291
+ .andExpect (status ().isOk ())
292
+ .andExpect (header ().string (HttpHeaders .CONTENT_TYPE , "text/css" ))
293
+ .andExpect (content ().string (".root { margin: 0 auto; }" ));
294
+ }
295
+
296
+ @ Test
297
+ public void testJsWebResourceAsset () throws Exception {
298
+ mockExtension ();
299
+ mockMvc .perform (get ("/vscode/asset/{namespace}/{extensionName}/{version}/{assetType}" ,
300
+ "redhat" , "vscode-yaml" , "0.5.2" , "Microsoft.VisualStudio.Code.WebResources/extension/public/static/js/main.js" ))
301
+ .andExpect (status ().isOk ())
302
+ .andExpect (header ().string (HttpHeaders .CONTENT_TYPE , "application/javascript" ))
303
+ .andExpect (content ().string ("() => { console.log('main'); }" ));
304
+ }
305
+
306
+ @ Test
307
+ public void testChunkJsWebResourceAsset () throws Exception {
308
+ mockExtension ();
309
+ mockMvc .perform (get ("/vscode/asset/{namespace}/{extensionName}/{version}/{assetType}" ,
310
+ "redhat" , "vscode-yaml" , "0.5.2" , "Microsoft.VisualStudio.Code.WebResources/extension/public/static/js/main.34d01954.chunk.js" ))
311
+ .andExpect (status ().isOk ())
312
+ .andExpect (header ().string (HttpHeaders .CONTENT_TYPE , "application/javascript" ))
313
+ .andExpect (content ().string ("() => { console.log('js'); }" ));
314
+ }
315
+
265
316
@ Test
266
317
public void testNotWebResourceAsset () throws Exception {
267
318
mockExtension ();
@@ -502,6 +553,7 @@ private ExtensionVersion mockExtension(String targetPlatform) throws JsonProcess
502
553
extension .setAverageRating (3.0 );
503
554
extension .setNamespace (namespace );
504
555
var extVersion = new ExtensionVersion ();
556
+ extVersion .setExtension (extension );
505
557
extension .getVersions ().add (extVersion );
506
558
extVersion .setTargetPlatform (targetPlatform );
507
559
extVersion .setVersion ("0.5.2" );
@@ -573,14 +625,46 @@ private ExtensionVersion mockExtension(String targetPlatform) throws JsonProcess
573
625
iconFile .setStorageType (FileResource .STORAGE_DB );
574
626
Mockito .when (repositories .findFileByType (extVersion , FileResource .ICON ))
575
627
.thenReturn (iconFile );
576
- var webResourceFile = new FileResource ();
577
- webResourceFile .setExtension (extVersion );
578
- webResourceFile .setName ("extension/img/logo.png" );
579
- webResourceFile .setType (FileResource .RESOURCE );
580
- webResourceFile .setStorageType (STORAGE_DB );
581
- webResourceFile .setContent ("logo.png" .getBytes ());
628
+ var pngWebResourceFile = new FileResource ();
629
+ pngWebResourceFile .setExtension (extVersion );
630
+ pngWebResourceFile .setName ("extension/img/logo.png" );
631
+ pngWebResourceFile .setType (FileResource .RESOURCE );
632
+ pngWebResourceFile .setStorageType (STORAGE_DB );
633
+ pngWebResourceFile .setContent ("logo.png" .getBytes ());
582
634
Mockito .when (repositories .findFileByTypeAndName (extVersion , FileResource .RESOURCE , "extension/img/logo.png" ))
583
- .thenReturn (webResourceFile );
635
+ .thenReturn (pngWebResourceFile );
636
+ var jsWebResourceFile = new FileResource ();
637
+ jsWebResourceFile .setExtension (extVersion );
638
+ jsWebResourceFile .setName ("extension/public/static/js/main.js" );
639
+ jsWebResourceFile .setType (FileResource .RESOURCE );
640
+ jsWebResourceFile .setStorageType (STORAGE_DB );
641
+ jsWebResourceFile .setContent ("() => { console.log('main'); }" .getBytes ());
642
+ Mockito .when (repositories .findFileByTypeAndName (extVersion , FileResource .RESOURCE , "extension/public/static/js/main.js" ))
643
+ .thenReturn (jsWebResourceFile );
644
+ var jsChunkWebResourceFile = new FileResource ();
645
+ jsChunkWebResourceFile .setExtension (extVersion );
646
+ jsChunkWebResourceFile .setName ("extension/public/static/js/main.34d01954.chunk.js" );
647
+ jsChunkWebResourceFile .setType (FileResource .RESOURCE );
648
+ jsChunkWebResourceFile .setStorageType (STORAGE_DB );
649
+ jsChunkWebResourceFile .setContent ("() => { console.log('js'); }" .getBytes ());
650
+ Mockito .when (repositories .findFileByTypeAndName (extVersion , FileResource .RESOURCE , "extension/public/static/js/main.34d01954.chunk.js" ))
651
+ .thenReturn (jsChunkWebResourceFile );
652
+ var cssWebResourceFile = new FileResource ();
653
+ cssWebResourceFile .setExtension (extVersion );
654
+ cssWebResourceFile .setName ("extension/public/static/css/main.css" );
655
+ cssWebResourceFile .setType (FileResource .RESOURCE );
656
+ cssWebResourceFile .setStorageType (STORAGE_DB );
657
+ cssWebResourceFile .setContent (".main { margin: 0 auto; }" .getBytes ());
658
+ Mockito .when (repositories .findFileByTypeAndName (extVersion , FileResource .RESOURCE , "extension/public/static/css/main.css" ))
659
+ .thenReturn (cssWebResourceFile );
660
+ var cssChunkWebResourceFile = new FileResource ();
661
+ cssChunkWebResourceFile .setExtension (extVersion );
662
+ cssChunkWebResourceFile .setName ("extension/public/static/css/main.9cab4879.chunk.css" );
663
+ cssChunkWebResourceFile .setType (FileResource .RESOURCE );
664
+ cssChunkWebResourceFile .setStorageType (STORAGE_DB );
665
+ cssChunkWebResourceFile .setContent (".root { margin: 0 auto; }" .getBytes ());
666
+ Mockito .when (repositories .findFileByTypeAndName (extVersion , FileResource .RESOURCE , "extension/public/static/css/main.9cab4879.chunk.css" ))
667
+ .thenReturn (cssChunkWebResourceFile );
584
668
Mockito .when (repositories .findFilesByType (extVersion , Arrays .asList (FileResource .MANIFEST , FileResource .README , FileResource .LICENSE , FileResource .ICON , FileResource .DOWNLOAD , FileResource .CHANGELOG )))
585
669
.thenReturn (Streamable .of (manifestFile , readmeFile , licenseFile , iconFile , extensionFile , changelogFile ));
586
670
return extVersion ;
0 commit comments