77import io .micronaut .http .client .HttpClient ;
88import io .micronaut .http .client .annotation .Client ;
99import io .micronaut .http .client .exceptions .HttpClientResponseException ;
10+ import io .micronaut .runtime .server .EmbeddedServer ;
1011import io .micronaut .test .extensions .junit5 .annotation .MicronautTest ;
1112import jakarta .inject .Inject ;
1213import org .junit .jupiter .api .Test ;
@@ -31,6 +32,9 @@ public class ValidateControllerTest {
3132 @ Client ("/validate" )
3233 HttpClient client ;
3334
35+ @ Inject
36+ EmbeddedServer server ;
37+
3438 @ Value ("${api.version}" )
3539 String version ;
3640
@@ -159,7 +163,7 @@ void uploadAndValidateCsvWithoutContent() throws IOException {
159163
160164 @ Test
161165 void provideUrlAndValidateCsvFromForm () {
162- final String url = "https://raw.githubusercontent.com/marmoure/bbl-validator/refs/heads/feature/vlidation/src/test/resources/schemas /concatPass.csv" ;
166+ final String url = server . getURL () + "/mock-data /concatPass.csv" ;
163167 final String schemaId = "concat" ;
164168 final Map <String , String > formBody = Map .of (
165169 "schemaId" , schemaId ,
@@ -187,7 +191,7 @@ void provideUrlAndValidateCsvFromForm() {
187191
188192 @ Test
189193 void provideUrlAndValidateInvalidCsvFromForm () {
190- final String url = "https://raw.githubusercontent.com/marmoure/bbl-validator/refs/heads/feature/vlidation/src/test/resources/schemas /concatFail.csv" ;
194+ final String url = server . getURL () + "/mock-data /concatFail.csv" ;
191195 final String schemaId = "concat" ;
192196 final Map <String , String > formBody = Map .of (
193197 "schemaId" , schemaId ,
@@ -229,7 +233,7 @@ void provideUrlAndValidateInvalidCsvFromForm() {
229233
230234 @ Test
231235 void provideUrlAndValidateCsvInQueryString () {
232- final String url = "https://raw.githubusercontent.com/marmoure/bbl-validator/refs/heads/feature/vlidation/src/test/resources/schemas /concatPass.csv" ;
236+ final String url = server . getURL () + "/mock-data /concatPass.csv" ;
233237 final String schemaId = "concat" ;
234238
235239 final MutableHttpRequest <Void > request = HttpRequest .POST ("/" , null );
@@ -254,7 +258,7 @@ void provideUrlAndValidateCsvInQueryString() {
254258
255259 @ Test
256260 void provideUrlAndValidateInvalidCsvInQueryString () {
257- final String url = "https://raw.githubusercontent.com/marmoure/bbl-validator/refs/heads/feature/vlidation/src/test/resources/schemas /concatFail.csv" ;
261+ final String url = server . getURL () + "/mock-data /concatFail.csv" ;
258262 final String schemaId = "concat" ;
259263
260264 final MutableHttpRequest <Void > request = HttpRequest .POST ("/" , null );
@@ -354,7 +358,7 @@ void provideInvalidUrlFormatAndValidateCsvFromForm() {
354358
355359 @ Test
356360 void provideNonCsvUrlAndValidateCsvFromForm () {
357- final String url = "https://picsum.photos/200/300 " ;
361+ final String url = "https://evolvedbinary.com/images/icons/ev-logo.svg " ;
358362 final String schemaId = "concat" ;
359363 final Map <String , String > formBody = Map .of (
360364 "schemaId" , schemaId ,
@@ -411,8 +415,14 @@ void provideInvalidUrlFormatAndValidateCsvInQueryString() {
411415
412416 @ Test
413417 void provideNonResolvableUrlAndValidateCsvInQueryString () {
414- //TODO(YB)
415- final HttpRequest <Void > request = HttpRequest .POST ("/?schema-id=concat&url=nothing" , null );
418+ //TODO(YB) seek help
419+ final String url = "https://static.evolvedbinary.com/404.csv" ;
420+ final String schemaId = "concat" ;
421+
422+ final MutableHttpRequest <Void > request = HttpRequest .POST ("/" , null );
423+ final MutableHttpParameters params = request .getParameters ();
424+ params .add ("schema-id" , schemaId );
425+ params .add ("url" , url );
416426
417427 final HttpClientResponseException exception = assertThrows (HttpClientResponseException .class , () -> client .toBlocking ().exchange (request , String .class ));
418428
@@ -434,7 +444,28 @@ void provideNonResolvableUrlAndValidateCsvInQueryString() {
434444
435445 @ Test
436446 void provideNonCsvUrlAndValidateCsvInQueryString () {
437- fail ("TODO implement" );
447+ final String url = "https://evolvedbinary.com/images/icons/ev-logo.svg" ;
448+ final String schemaId = "concat" ;
449+
450+ final MutableHttpRequest <Void > request = HttpRequest .POST ("/" , null );
451+ final MutableHttpParameters params = request .getParameters ();
452+ params .add ("schema-id" , schemaId );
453+ params .add ("url" , url );
454+
455+ final HttpResponse <ValidationResponse > response = client .toBlocking ().exchange (request , ValidationResponse .class );
456+
457+ assertEquals (HttpStatus .OK , response .getStatus ());
458+ assertEquals (Optional .of (MediaType .APPLICATION_JSON_TYPE ), response .getContentType ());
459+ assertEquals (version , response .getHeaders ().get (BBLVALIDATOR_VERSION_HEADER ));
460+
461+ assertTrue (response .getBody ().isPresent ());
462+
463+ final ValidationResponse validationResponse = response .getBody ().get ();
464+
465+ assertFalse (validationResponse .isValid ());
466+ assertFalse (validationResponse .getErrors ().isEmpty ());
467+
468+ assertTrue (validationResponse .getExecutionTimeMs () > -1 );
438469 }
439470
440471}
0 commit comments