@PostMapping(value = "/artifact/download")
   public ResponseEntity<String> importArtifact(@RequestParam(value = "url", required = true) String url,
         @RequestParam(value = "mainArtifact", defaultValue = "true") boolean mainArtifact,
         @RequestParam(value = "secretName", required = false) String secretName) {
      if (!url.isEmpty()) {
         List<Service> services = null;

         Secret secret = null;
         if (secretName != null) {
            secret = secretRepository.findByName(secretName).stream().findFirst().orElse(null);
            log.debug("Secret {} was requested. Have we found it? {}", secretName, (secret != null));
         }

         try {
            // Download remote to local file before import.
            HTTPDownloader.FileAndHeaders fileAndHeaders = HTTPDownloader.handleHTTPDownloadToFileAndHeaders(url,
                  secret, true);
            File localFile = fileAndHeaders.getLocalFile();

            // Now try importing services.
            services = serviceService.importServiceDefinition(localFile,
                  new ReferenceResolver(url, secret, true,
                        RelativeReferenceURLBuilderFactory
                              .getRelativeReferenceURLBuilder(fileAndHeaders.getResponseHeaders())),
                  new ArtifactInfo(url, mainArtifact));
         } catch (IOException ioe) {
            log.error("Exception while retrieving remote item " + url, ioe);
            return new ResponseEntity<>("Exception while retrieving remote item", HttpStatus.INTERNAL_SERVER_ERROR);
         } catch (MockRepositoryImportException mrie) {
            return new ResponseEntity<>(mrie.getMessage(), HttpStatus.BAD_REQUEST);
         }
         if (services != null && !services.isEmpty()) {
            return new ResponseEntity<>(
                  "{\"name\": \"" + services.get(0).getName() + ":" + services.get(0).getVersion() + "\"}",
                  HttpStatus.CREATED);
         }
      }
      return new ResponseEntity<>(HttpStatus.NO_CONTENT);
   }
@Test
   void shouldReturnBadRequest() throws MockRepositoryImportException {
      // arrange
      String apiPastry = "https://raw.githubusercontent.com/microcks/microcks/master/samples/APIPastry-openapi.yaml";

      Mockito.when(serviceService.importServiceDefinition(Mockito.any(File.class), Mockito.any(ReferenceResolver.class),
            Mockito.any(ArtifactInfo.class))).thenThrow(new MockRepositoryImportException("Intentional error"));

      // act
      ResponseEntity<String> responseEntity = sut.importArtifact(apiPastry, false, null);

      // assert
      SoftAssertions.assertSoftly(softly -> {
         softly.assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
         softly.assertThat(responseEntity.getBody()).contains("Intentional error");
      });
   }