PostmanCollectionImporter implements MockRepositoryImporter { @Override public List<Service> getServiceDefinitions() throws MockRepositoryImportException { List<Service> result = new ArrayList<>(); Service service = new Service(); if (collection.has("info")) { isV2Collection = true; fillServiceDefinition(service); } else { throw new MockRepositoryImportException("Only Postman v2 Collection are supported."); } try { service.setOperations(extractOperations()); } catch (Throwable t) { log.error("Runtime exception while extracting Operations for " + service.getName()); throw new MockRepositoryImportException("Runtime exception for " + service.getName() + ": " + t.getMessage()); } result.add(service); return result; } PostmanCollectionImporter(String collectionFilePath); @Override List<Service> getServiceDefinitions(); @Override List<Resource> getResourceDefinitions(Service service); @Override List<Exchange> getMessageDefinitions(Service service, Operation operation); static String buildOperationName(JsonNode operationNode, String folderName); static final String SERVICE_VERSION_PROPERTY; }
@Test public void testTestAPINoVersionImport() { PostmanCollectionImporter importer = null; try { importer = new PostmanCollectionImporter("target/test-classes/io/github/microcks/util/postman/Test API no version.postman_collection.json"); } catch (IOException ioe) { fail("Exception should not be thrown"); } boolean failure = false; List<Service> services = null; try { services = importer.getServiceDefinitions(); } catch (MockRepositoryImportException e) { failure = true; assertNotEquals(-1, e.getMessage().indexOf("Version property")); } assertTrue(failure); }