MockRepositoryImporterFactory { public static MockRepositoryImporter getMockRepositoryImporter(File mockRepository) throws IOException { MockRepositoryImporter importer = null; String line = null; BufferedReader reader = Files.newBufferedReader(mockRepository.toPath(), Charset.forName("UTF-8")); while ((line = reader.readLine()) != null) { line = line.trim(); if (line.startsWith("\"_postman_id\":")) { log.info("Found a _postman_id in file so assuming it's a Postman Collection to import"); importer = new PostmanCollectionImporter(mockRepository.getPath()); break; } else if (line.startsWith("<?xml")) { log.info("Found an XML pragma in file so assuming it's a SoapUI Project to import"); importer = new SoapUIProjectImporter(mockRepository.getPath()); break; } else if (line.startsWith("openapi: 3") || line.startsWith("openapi: '3") || line.startsWith("openapi: \"3") || line.startsWith("\"openapi\": \"3") || line.startsWith("'openapi': '3")) { log.info("Found an openapi: 3 pragma in file so assuming it's an OpenAPI spec to import"); importer = new OpenAPIImporter(mockRepository.getPath()); break; } else if (line.startsWith("asyncapi: 2") || line.startsWith("asyncapi: '2") || line.startsWith("asyncapi: \"2") || line.startsWith("\"asyncapi\": \"2") || line.startsWith("'asyncapi': '2")) { log.info("Found an asyncapi: 2 pragma in file so assuming it's an OpenAPI spec to import"); importer = new AsyncAPIImporter(mockRepository.getPath()); break; } else if (line.startsWith("\"swagger\":") || line.startsWith("swagger:")) { log.warn("Swagger v2 format is not supported as it does not allow full examples specification, raising an exception"); throw new IOException("Swagger v2 format is not supported as it does not allow full examples specification"); } } reader.close(); if (importer == null) { log.info("Have not found any explicit marker so applying the default SoapUI Project importer..."); importer = new SoapUIProjectImporter(mockRepository.getPath()); } return importer; }  static MockRepositoryImporter getMockRepositoryImporter(File mockRepository);  }
@Test public void testGetMockRepositoryImporter() { File soapUIProject = new File("../samples/HelloService-soapui-project.xml"); MockRepositoryImporter importer = null; try { importer = MockRepositoryImporterFactory.getMockRepositoryImporter(soapUIProject); } catch (Throwable t) { fail("Getting importer should not fail !"); } assertTrue(importer instanceof SoapUIProjectImporter); File postmanCollection = new File("../samples/PetstoreAPI-collection.json"); importer = null; try { importer = MockRepositoryImporterFactory.getMockRepositoryImporter(postmanCollection); } catch (Throwable t) { fail("Getting importer should not fail !"); } assertTrue(importer instanceof PostmanCollectionImporter); importer = null; File openAPISpec = new File("target/test-classes/io/github/microcks/util/openapi/cars-openapi.yaml"); try { importer = MockRepositoryImporterFactory.getMockRepositoryImporter(openAPISpec); } catch (Throwable t) { fail("Getting importer should not fail !"); } assertTrue(importer instanceof OpenAPIImporter); openAPISpec = new File("target/test-classes/io/github/microcks/util/openapi/cars-openapi.json"); importer = null; try { importer = MockRepositoryImporterFactory.getMockRepositoryImporter(openAPISpec); } catch (Throwable t) { fail("Getting importer should not fail !"); } assertTrue(importer instanceof OpenAPIImporter); File asyncAPISpec = new File("target/test-classes/io/github/microcks/util/asyncapi/user-signedup-asyncapi.yaml"); importer = null; try { importer = MockRepositoryImporterFactory.getMockRepositoryImporter(asyncAPISpec); } catch (Throwable t) { fail("Getting importer should not fail !"); } assertTrue(importer instanceof AsyncAPIImporter); }