12
12
import static org .assertj .core .api .Assertions .assertThat ;
13
13
14
14
import java .io .IOException ;
15
+ import java .net .URI ;
16
+ import java .net .URISyntaxException ;
17
+ import java .util .List ;
15
18
16
- import org .eclipse .openvsx .json .ExtensionJson ;
17
- import org .eclipse .openvsx .json .NamespaceJson ;
18
- import org .eclipse .openvsx .json .ResultJson ;
19
- import org .eclipse .openvsx .json .SearchResultJson ;
19
+ import com .fasterxml .jackson .databind .JsonNode ;
20
+ import com .fasterxml .jackson .databind .node .NullNode ;
21
+ import org .eclipse .openvsx .json .*;
20
22
import org .junit .jupiter .api .Test ;
21
23
import org .springframework .beans .factory .annotation .Autowired ;
22
24
import org .springframework .boot .test .context .SpringBootTest ;
@@ -47,50 +49,162 @@ private String apiCall(String path) {
47
49
public void testPublishExtension () throws Exception {
48
50
testService .createUser ();
49
51
createNamespace ();
52
+ getNamespaceMetadata ("/api/editorconfig" );
53
+ getNamespaceMetadata ("/api/editorconfig/details" );
54
+ duplicateNamespaceLowercase ();
55
+ verifyToken ();
50
56
publishExtension ();
51
57
52
58
// Wait a bit until the publish extension background job has finished
53
59
Thread .sleep (15000 );
54
- getExtensionMetadata ();
60
+
61
+ getExtensionMetadata ("/api/editorconfig/editorconfig" );
62
+ getExtensionMetadata ("/api/editorconfig/editorconfig/0.16.6" );
63
+ getExtensionMetadata ("/api/editorconfig/editorconfig/latest" );
64
+ getExtensionMetadata ("/api/editorconfig/editorconfig/universal" );
65
+ getExtensionMetadata ("/api/editorconfig/editorconfig/universal/0.16.6" );
66
+ getExtensionMetadata ("/api/editorconfig/editorconfig/universal/latest" );
67
+
68
+ getVersionsMetadata ("editorconfig" , "editorconfig" , null );
69
+ getVersionsMetadata ("editorconfig" , "editorconfig" , "universal" );
70
+
71
+ getVersionReferencesMetadata ("/api/editorconfig/editorconfig/version-references" );
72
+ getVersionReferencesMetadata ("/api/editorconfig/editorconfig/universal/version-references" );
73
+
74
+ getReviews ();
75
+
76
+ getFile ("/api/editorconfig/editorconfig/latest/file/download" );
77
+ getFile ("/api/editorconfig/editorconfig/universal/latest/file/download" );
78
+ getFile ("/api/editorconfig/editorconfig/0.16.6/file/download" );
79
+ getFile ("/api/editorconfig/editorconfig/universal/0.16.6/file/download" );
80
+ getFile ("/api/editorconfig/editorconfig/latest/file/editorconfig.editorconfig-0.16.6.vsix" );
81
+ getFile ("/api/editorconfig/editorconfig/universal/latest/file/editorconfig.editorconfig-0.16.6.vsix" );
82
+ getFile ("/api/editorconfig/editorconfig/0.16.6/file/editorconfig.editorconfig-0.16.6.vsix" );
83
+ getFile ("/api/editorconfig/editorconfig/universal/0.16.6/file/editorconfig.editorconfig-0.16.6.vsix" );
84
+ getFile ("/vscode/asset/editorconfig/editorconfig/0.16.6/Microsoft.VisualStudio.Services.VSIXPackage" );
85
+ getFile ("/vscode/asset/editorconfig/editorconfig/0.16.6/Microsoft.VisualStudio.Services.VSIXPackage?targetPlatform=universal" );
86
+ getFile ("/vscode/unpkg/editorconfig/editorconfig/0.16.6" );
87
+ getFile ("/vscode/unpkg/editorconfig/editorconfig/0.16.6/extension.vsixmanifest" );
88
+
89
+ getVscodeDownloadLink ();
55
90
56
91
// Wait a bit until the new entry has landed in the search index
57
92
Thread .sleep (2000 );
58
93
searchExtension ();
94
+ publishDuplicateExtensionLowercase ();
59
95
}
60
96
61
97
private void createNamespace () {
62
98
var requestBody = new NamespaceJson ();
63
- requestBody .name = "Equinusocio " ;
99
+ requestBody .name = "EditorConfig " ;
64
100
var response = restTemplate .postForEntity (apiCall ("/api/-/namespace/create?token={token}" ), requestBody ,
65
101
ResultJson .class , "test_token" );
66
102
assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .CREATED );
67
103
assertThat (response .getBody ().error ).isNull ();
68
104
assertThat (response .getBody ().success ).isEqualTo ("Created namespace " + requestBody .name );
69
105
}
70
106
107
+ private void duplicateNamespaceLowercase () {
108
+ var requestBody = new NamespaceJson ();
109
+ requestBody .name = "editorconfig" ;
110
+ var response = restTemplate .postForEntity (apiCall ("/api/-/namespace/create?token={token}" ), requestBody ,
111
+ ResultJson .class , "test_token" );
112
+ assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .BAD_REQUEST );
113
+ assertThat (response .getBody ().success ).isNull ();
114
+ assertThat (response .getBody ().error ).isEqualTo ("Namespace already exists: EditorConfig" );
115
+ }
116
+
117
+ private void getNamespaceMetadata (String path ) {
118
+ var response = restTemplate .getForEntity (apiCall (path ), JsonNode .class );
119
+ assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .OK );
120
+ var json = response .getBody ();
121
+ assertThat (json .get ("error" )).isNull ();
122
+ assertThat (json .get ("name" ).asText ()).isEqualTo ("EditorConfig" );
123
+ }
124
+
125
+ private void verifyToken () {
126
+ var response = restTemplate .getForEntity (apiCall ("/api/editorconfig/verify-pat?token=test_token" ), ResultJson .class );
127
+ assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .OK );
128
+ var json = response .getBody ();
129
+ assertThat (json .error ).isNull ();
130
+ assertThat (json .success ).isEqualTo ("Valid token" );
131
+ }
132
+
71
133
private void publishExtension () throws IOException {
72
- try (var stream = getClass ().getResourceAsStream ("vsc-material-theme .vsix" )) {
134
+ try (var stream = getClass ().getResourceAsStream ("EditorConfig.EditorConfig-0.16.6 .vsix" )) {
73
135
var bytes = stream .readAllBytes ();
74
136
var response = restTemplate .postForEntity (apiCall ("/api/-/publish?token={token}" ),
75
137
bytes , ExtensionJson .class , "test_token" );
76
138
assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .CREATED );
77
139
assertThat (response .getBody ().error ).isNull ();
78
- assertThat (response .getBody ().name ).isEqualTo ("vsc-material-theme " );
140
+ assertThat (response .getBody ().name ).isEqualTo ("EditorConfig " );
79
141
}
80
142
}
81
143
82
- private void getExtensionMetadata () {
83
- var response = restTemplate .getForEntity (apiCall ("/api/Equinusocio/vsc-material-theme" ), ExtensionJson .class );
144
+ private void publishDuplicateExtensionLowercase () throws IOException {
145
+ try (var stream = getClass ().getResourceAsStream ("editorconfig.editorconfig-0.16.6-2.vsix" )) {
146
+ var bytes = stream .readAllBytes ();
147
+ var response = restTemplate .postForEntity (apiCall ("/api/-/publish?token={token}" ),
148
+ bytes , ExtensionJson .class , "test_token" );
149
+ assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .BAD_REQUEST );
150
+ assertThat (response .getBody ().error ).isEqualTo ("Extension editorconfig.editorconfig 0.16.6 is already published." );
151
+ }
152
+ }
153
+
154
+ private void getExtensionMetadata (String url ) {
155
+ var response = restTemplate .getForEntity (apiCall (url ), ExtensionJson .class );
156
+ assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .OK );
157
+ assertThat (response .getBody ().description ).isEqualTo ("EditorConfig Support for Visual Studio Code" );
158
+ }
159
+
160
+ private void getVersionsMetadata (String namespace , String extension , String target ) {
161
+ var path = "/api/" + namespace + "/" + extension ;
162
+ if (target != null ) {
163
+ path += "/" + target ;
164
+ }
165
+
166
+ var response = restTemplate .getForEntity (apiCall (path + "/versions" ), VersionsJson .class );
167
+ assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .OK );
168
+ assertThat (response .getBody ().versions .size ()).isEqualTo (1 );
169
+
170
+ var version = "0.16.6" ;
171
+ var versionPath = path + "/" + version ;
172
+ assertThat (response .getBody ().versions .get (version )).isEqualTo (apiCall (versionPath ));
173
+ }
174
+
175
+ private void getVersionReferencesMetadata (String path ) {
176
+ var response = restTemplate .getForEntity (apiCall (path ), VersionReferencesJson .class );
177
+ assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .OK );
178
+ assertThat (response .getBody ().versions .size ()).isEqualTo (1 );
179
+ assertThat (response .getBody ().versions .get (0 ).version ).isEqualTo ("0.16.6" );
180
+ }
181
+
182
+ private void getFile (String path ) {
183
+ var response = restTemplate .getForEntity (apiCall (path ), byte [].class );
184
+ assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .OK );
185
+ assertThat (response .getBody ()).isNotEmpty ();
186
+ }
187
+
188
+ private void getReviews () {
189
+ var response = restTemplate .getForEntity (apiCall ("/api/editorconfig/editorconfig/reviews" ), ReviewListJson .class );
84
190
assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .OK );
85
- assertThat (response .getBody ().description ).isEqualTo ("The most epic theme now for Visual Studio Code" );
191
+ assertThat (response .getBody ().error ).isNull ();
192
+ assertThat (response .getBody ().reviews .size ()).isEqualTo (0 );
86
193
}
87
194
88
195
private void searchExtension () {
89
- var response = restTemplate .getForEntity (apiCall ("/api/-/search?query=material " ), SearchResultJson .class );
196
+ var response = restTemplate .getForEntity (apiCall ("/api/-/search?query=editorconfig " ), SearchResultJson .class );
90
197
assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .OK );
91
198
assertThat (response .getBody ().extensions .size ()).isEqualTo (1 );
92
199
assertThat (response .getBody ().extensions .get (0 ).description )
93
- .isEqualTo ("The most epic theme now for Visual Studio Code" );
200
+ .isEqualTo ("EditorConfig Support for Visual Studio Code" );
201
+ }
202
+
203
+ public void getVscodeDownloadLink () throws URISyntaxException {
204
+ var path = "/vscode/gallery/publishers/editorconfig/vsextensions/editorconfig/0.16.6/vspackage" ;
205
+ var response = restTemplate .getForEntity (apiCall (path ), String .class );
206
+ assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .FOUND );
207
+ var expectedPath = "/vscode/asset/editorconfig/editorconfig/0.16.6/Microsoft.VisualStudio.Services.VSIXPackage" ;
208
+ assertThat (response .getHeaders ().getLocation ()).isEqualTo (new URI (apiCall (expectedPath )));
94
209
}
95
-
96
210
}
0 commit comments