33import com .evolvedbinary .bblValidator .dto .ErrorResponse ;
44import com .evolvedbinary .bblValidator .dto .ValidationResponse ;
55import io .micronaut .context .annotation .Value ;
6- import io .micronaut .core .annotation .NonNull ;
76import io .micronaut .http .*;
87import io .micronaut .http .client .HttpClient ;
98import io .micronaut .http .client .annotation .Client ;
@@ -43,8 +42,10 @@ void uploadAndValidateCsv() throws IOException {
4342 final Path validCsvFile = Path .of (schemaTestDirectory , "concatPass.csv" );
4443 final String csvContent = Files .readString (validCsvFile );
4544
46- final HttpRequest <String > request = HttpRequest .POST ("/?schema-id=concat " , csvContent )
45+ final MutableHttpRequest <String > request = HttpRequest .POST ("/" , csvContent )
4746 .contentType (MediaType .TEXT_CSV );
47+ final MutableHttpParameters params = request .getParameters ();
48+ params .add ("schema-id" , "concat" );
4849
4950 final HttpResponse <ValidationResponse > response = client .toBlocking ().exchange (request , ValidationResponse .class );
5051
@@ -65,9 +66,11 @@ void uploadAndValidateCsv() throws IOException {
6566 void uploadAndValidateInvalidCsv () throws IOException {
6667 final Path invalidCsvFile = Path .of (schemaTestDirectory , "concatFail.csv" );
6768 final String csvContent = Files .readString (invalidCsvFile );
68-
69- final HttpRequest <String > request = HttpRequest .POST ("/?schema-id=concat " , csvContent )
69+
70+ final MutableHttpRequest <String > request = HttpRequest .POST ("/" , csvContent )
7071 .contentType (MediaType .TEXT_CSV );
72+ final MutableHttpParameters params = request .getParameters ();
73+ params .add ("schema-id" , "concat" );
7174
7275 final HttpResponse <ValidationResponse > response = client .toBlocking ().exchange (request , ValidationResponse .class );
7376
@@ -102,8 +105,11 @@ void uploadAndValidateCsvWithNonExistingSchema() throws IOException {
102105 final Path validCsvFile = Path .of (schemaTestDirectory , "concatPass.csv" );
103106 final String csvContent = Files .readString (validCsvFile );
104107
105- final HttpRequest <String > request = HttpRequest .POST ("/?schema-id=nonExistingSchema " , csvContent )
108+ final MutableHttpRequest <String > request = HttpRequest .POST ("/" , csvContent )
106109 .contentType (MediaType .TEXT_CSV );
110+ final MutableHttpParameters params = request .getParameters ();
111+ params .add ("schema-id" , "nonExistingSchema" );
112+
107113 // Http client consider any response outside the 2xx range as exception
108114 final HttpClientResponseException exception = assertThrows (HttpClientResponseException .class , () -> client .toBlocking ().exchange (request , String .class ));
109115
@@ -127,8 +133,11 @@ void uploadAndValidateCsvWithNonExistingSchema() throws IOException {
127133 void uploadAndValidateCsvWithoutContent () throws IOException {
128134 final String csvContent = "" ;
129135
130- final HttpRequest <String > request = HttpRequest .POST ("/?schema-id=concat " , csvContent )
136+ final MutableHttpRequest <String > request = HttpRequest .POST ("/" , csvContent )
131137 .contentType (MediaType .TEXT_CSV );
138+ final MutableHttpParameters params = request .getParameters ();
139+ params .add ("schema-id" , "concat" );
140+
132141 // Http client consider any response outside the 2xx range as exception
133142 final HttpClientResponseException exception = assertThrows (HttpClientResponseException .class , () -> client .toBlocking ().exchange (request , String .class ));
134143
@@ -157,7 +166,7 @@ void provideUrlAndValidateCsvFromForm() {
157166 "url" , url
158167 );
159168
160- final HttpRequest <? > request = HttpRequest .POST ("/" , formBody )
169+ final HttpRequest <Map < String , String > > request = HttpRequest .POST ("/" , formBody )
161170 .contentType (MediaType .APPLICATION_FORM_URLENCODED );
162171
163172 final HttpResponse <ValidationResponse > response = client .toBlocking ().exchange (request , ValidationResponse .class );
@@ -248,7 +257,10 @@ void provideUrlAndValidateInvalidCsvInQueryString() {
248257 final String url = "https://raw.githubusercontent.com/marmoure/bbl-validator/refs/heads/feature/vlidation/src/test/resources/schemas/concatFail.csv" ;
249258 final String schemaId = "concat" ;
250259
251- final HttpRequest <Void > request = HttpRequest .POST ("/?schema-id=" + schemaId + "&url=" + url , null );
260+ final MutableHttpRequest <Void > request = HttpRequest .POST ("/" , null );
261+ final MutableHttpParameters params = request .getParameters ();
262+ params .add ("schema-id" , schemaId );
263+ params .add ("url" , url );
252264
253265 final HttpResponse <ValidationResponse > response = client .toBlocking ().exchange (request , ValidationResponse .class );
254266
@@ -281,17 +293,45 @@ void provideUrlAndValidateInvalidCsvInQueryString() {
281293
282294 @ Test
283295 void provideNonResolvableUrlAndValidateCsvFromForm () {
284- //TODO split this test to 2
285- // one for 404
286- // one for wrong url format
296+ //TODO(YB) seek help
287297 final String url = "https://static.evolvedbinary.com/404.csv" ;
288298 final String schemaId = "concat" ;
289299 final Map <String , String > formBody = Map .of (
290300 "schemaId" , schemaId ,
291301 "url" , url
292302 );
293303
294- final HttpRequest <?> request = HttpRequest .POST ("/" , formBody )
304+ final HttpRequest <Map <String , String >> request = HttpRequest .POST ("/" , formBody )
305+ .contentType (MediaType .APPLICATION_FORM_URLENCODED );
306+
307+ final HttpClientResponseException exception = assertThrows (HttpClientResponseException .class , () -> client .toBlocking ().exchange (request , String .class ));
308+
309+ // assert the response status
310+ assertEquals (HttpStatus .BAD_REQUEST , exception .getStatus ());
311+
312+ // assert the X-BBLVALIDATOR-VERSION is present and it's returning the expected value.
313+ assertEquals (version , exception .getResponse ().getHeaders ().get (BBLVALIDATOR_VERSION_HEADER ));
314+
315+ // assert the response type
316+ assertEquals (Optional .of (MediaType .APPLICATION_JSON_TYPE ), exception .getResponse ().getContentType ());
317+
318+ // Get the error response
319+ final ErrorResponse errorBody = exception .getResponse ().getBody (ErrorResponse .class ).orElse (null );
320+ assertNotNull (errorBody );
321+ assertEquals (ErrorResponse .Code .NON_RESOLVABLE_URL , errorBody .getCode ());
322+ assertEquals ("Unable to resolve url : nothing" , errorBody .getDescription ());
323+ }
324+
325+ @ Test
326+ void provideInvalidUrlFormatAndValidateCsvFromForm () {
327+ final String url = "nothing" ;
328+ final String schemaId = "concat" ;
329+ final Map <String , String > formBody = Map .of (
330+ "schemaId" , schemaId ,
331+ "url" , url
332+ );
333+
334+ final HttpRequest <Map <String , String >> request = HttpRequest .POST ("/" , formBody )
295335 .contentType (MediaType .APPLICATION_FORM_URLENCODED );
296336
297337 final HttpClientResponseException exception = assertThrows (HttpClientResponseException .class , () -> client .toBlocking ().exchange (request , String .class ));
@@ -321,7 +361,7 @@ void provideNonCsvUrlAndValidateCsvFromForm() {
321361 "url" , url
322362 );
323363
324- final HttpRequest <? > request = HttpRequest .POST ("/" , formBody )
364+ final HttpRequest <Map < String , String > > request = HttpRequest .POST ("/" , formBody )
325365 .contentType (MediaType .APPLICATION_FORM_URLENCODED );
326366
327367 final HttpResponse <ValidationResponse > response = client .toBlocking ().exchange (request , ValidationResponse .class );
@@ -341,9 +381,37 @@ void provideNonCsvUrlAndValidateCsvFromForm() {
341381
342382 }
343383
384+ @ Test
385+ void provideInvalidUrlFormatAndValidateCsvInQueryString () {
386+ final String schemaId = "concat" ;
387+ final String url = "nothing" ;
388+
389+ final MutableHttpRequest <Void > request = HttpRequest .POST ("/" , null );
390+ final MutableHttpParameters params = request .getParameters ();
391+ params .add ("schema-id" , schemaId );
392+ params .add ("url" , url );
393+
394+ final HttpClientResponseException exception = assertThrows (HttpClientResponseException .class , () -> client .toBlocking ().exchange (request , String .class ));
395+
396+ // assert the response status
397+ assertEquals (HttpStatus .BAD_REQUEST , exception .getStatus ());
398+
399+ // assert the X-BBLVALIDATOR-VERSION is present and it's returning the expected value.
400+ assertEquals (version , exception .getResponse ().getHeaders ().get (BBLVALIDATOR_VERSION_HEADER ));
401+
402+ // assert the response type
403+ assertEquals (Optional .of (MediaType .APPLICATION_JSON_TYPE ), exception .getResponse ().getContentType ());
404+
405+ // Get the error response
406+ final ErrorResponse errorBody = exception .getResponse ().getBody (ErrorResponse .class ).orElse (null );
407+ assertNotNull (errorBody );
408+ assertEquals (ErrorResponse .Code .NON_RESOLVABLE_URL , errorBody .getCode ());
409+ assertEquals ("Unable to resolve url : nothing" , errorBody .getDescription ());
410+ }
411+
344412 @ Test
345413 void provideNonResolvableUrlAndValidateCsvInQueryString () {
346- //TODO split this into 2
414+ //TODO(YB)
347415 final HttpRequest <Void > request = HttpRequest .POST ("/?schema-id=concat&url=nothing" , null );
348416
349417 final HttpClientResponseException exception = assertThrows (HttpClientResponseException .class , () -> client .toBlocking ().exchange (request , String .class ));
0 commit comments