use of io.github.microcks.util.MockRepositoryImportException in project microcks by microcks.
the class GraphQLImporterTest method testSimpleGraphQLImport.
@Test
public void testSimpleGraphQLImport() {
GraphQLImporter importer = null;
try {
importer = new GraphQLImporter("target/test-classes/io/github/microcks/util/graphql/films.graphql");
} catch (IOException ioe) {
fail("Exception should not be thrown");
}
// Check that basic service properties are there.
List<Service> services = null;
try {
services = importer.getServiceDefinitions();
} catch (MockRepositoryImportException e) {
fail("Service definition import should not fail");
}
assertEquals(1, services.size());
Service service = services.get(0);
assertEquals("Movie Graph API", service.getName());
assertEquals(ServiceType.GRAPHQL, service.getType());
assertEquals("1.0", service.getVersion());
// Check that resources have been parsed, correctly renamed, etc...
List<Resource> resources = null;
try {
resources = importer.getResourceDefinitions(service);
} catch (MockRepositoryImportException mrie) {
fail("Resource definition import should not fail");
}
assertEquals(1, resources.size());
Resource resource = resources.get(0);
assertEquals(ResourceType.GRAPHQL_SCHEMA, resource.getType());
assertEquals("Movie Graph API-1.0.graphql", resource.getName());
// Check that operations and input/output have been found.
assertEquals(4, service.getOperations().size());
for (Operation operation : service.getOperations()) {
if ("allFilms".equals(operation.getName())) {
assertEquals("QUERY", operation.getMethod());
assertEquals("FilmsConnection", operation.getOutputName());
assertNull(operation.getDispatcher());
} else if ("film".equals(operation.getName())) {
assertEquals("QUERY", operation.getMethod());
assertEquals("Film", operation.getOutputName());
assertEquals("String", operation.getInputName());
assertEquals(DispatchStyles.QUERY_ARGS, operation.getDispatcher());
assertEquals("id", operation.getDispatcherRules());
} else if ("addStar".equals(operation.getName())) {
assertEquals("MUTATION", operation.getMethod());
assertEquals("Film", operation.getOutputName());
assertEquals("String", operation.getInputName());
assertEquals(DispatchStyles.QUERY_ARGS, operation.getDispatcher());
assertEquals("filmId", operation.getDispatcherRules());
} else if ("addReview".equals(operation.getName())) {
assertEquals("MUTATION", operation.getMethod());
assertEquals("Film", operation.getOutputName());
assertEquals("String, Review", operation.getInputName());
assertNull(operation.getDispatcher());
} else {
fail("Unknown operation");
}
}
}
use of io.github.microcks.util.MockRepositoryImportException in project microcks by microcks.
the class OpenAPIImporterTest method testExternalAbsoluteReferenceOpenAPIImport.
@Test
public void testExternalAbsoluteReferenceOpenAPIImport() {
OpenAPIImporter importer = null;
ReferenceResolver resolver = new ReferenceResolver("https://raw.githubusercontent.com/microcks/microcks/1.5.x/webapp/src/test/resources/io/github/microcks/util/openapi/", null, true);
try {
importer = new OpenAPIImporter("target/test-classes/io/github/microcks/util/openapi/weather-forecast-openapi-absolute-ref.yaml", resolver);
} catch (IOException ioe) {
ioe.printStackTrace();
fail("Exception should not be thrown");
}
// Check that basic service properties are there.
List<Service> services = null;
try {
services = importer.getServiceDefinitions();
} catch (MockRepositoryImportException e) {
fail("Exception should not be thrown");
}
assertEquals(1, services.size());
Service service = services.get(0);
assertEquals("WeatherForecast API", service.getName());
Assert.assertEquals(ServiceType.REST, service.getType());
assertEquals("1.0.0", service.getVersion());
List<Resource> resources = importer.getResourceDefinitions(service);
assertEquals(2, resources.size());
Resource openAPISpec = resources.get(0);
assertEquals("WeatherForecast API-1.0.0.yaml", openAPISpec.getName());
assertEquals(ResourceType.OPEN_API_SPEC, openAPISpec.getType());
assertFalse(openAPISpec.getContent().contains("./WeatherForecast API-1.0.0-weather-forecast-schema.yaml"));
Resource refSchema = resources.get(1);
assertEquals("WeatherForecast API-1.0.0-weather-forecast-schema.yaml", refSchema.getName());
assertEquals(ResourceType.JSON_SCHEMA, refSchema.getType());
assertEquals("https://raw.githubusercontent.com/microcks/microcks/1.5.x/webapp/src/test/resources/io/github/microcks/util/openapi/weather-forecast-schema.yaml", refSchema.getPath());
assertNotNull(refSchema.getContent());
assertTrue(refSchema.getContent().contains("A weather forecast for a requested region"));
}
use of io.github.microcks.util.MockRepositoryImportException in project microcks by microcks.
the class OpenAPIImporterTest method testExternalRelativeReferenceOpenAPIImport.
@Test
public void testExternalRelativeReferenceOpenAPIImport() {
OpenAPIImporter importer = null;
ReferenceResolver resolver = new ReferenceResolver("https://raw.githubusercontent.com/microcks/microcks/1.5.x/webapp/src/test/resources/io/github/microcks/util/openapi/weather-forecast-openapi-relative-ref.yaml", null, true);
try {
importer = new OpenAPIImporter("target/test-classes/io/github/microcks/util/openapi/weather-forecast-openapi-relative-ref.yaml", resolver);
} catch (IOException ioe) {
ioe.printStackTrace();
fail("Exception should not be thrown");
}
// Check that basic service properties are there.
List<Service> services = null;
try {
services = importer.getServiceDefinitions();
} catch (MockRepositoryImportException e) {
fail("Exception should not be thrown");
}
assertEquals(1, services.size());
Service service = services.get(0);
assertEquals("WeatherForecast API", service.getName());
Assert.assertEquals(ServiceType.REST, service.getType());
assertEquals("1.0.0", service.getVersion());
List<Resource> resources = importer.getResourceDefinitions(service);
assertEquals(2, resources.size());
Resource openAPISpec = resources.get(0);
assertEquals("WeatherForecast API-1.0.0.yaml", openAPISpec.getName());
assertEquals(ResourceType.OPEN_API_SPEC, openAPISpec.getType());
assertTrue(openAPISpec.getContent().contains("./WeatherForecast+API-1.0.0-weather-forecast-schema.yaml"));
Resource refSchema = resources.get(1);
assertEquals("WeatherForecast API-1.0.0-weather-forecast-schema.yaml", refSchema.getName());
assertEquals(ResourceType.JSON_SCHEMA, refSchema.getType());
assertEquals("./weather-forecast-schema.yaml", refSchema.getPath());
assertNotNull(refSchema.getContent());
assertTrue(refSchema.getContent().contains("A weather forecast for a requested region"));
}
use of io.github.microcks.util.MockRepositoryImportException in project microcks by microcks.
the class PostmanCollectionImporter method getServiceDefinitions.
@Override
public List<Service> getServiceDefinitions() throws MockRepositoryImportException {
List<Service> result = new ArrayList<>();
// Build a new service.
Service service = new Service();
// Collection V2 as an info node.
if (collection.has("info")) {
isV2Collection = true;
fillServiceDefinition(service);
} else {
throw new MockRepositoryImportException("Only Postman v2 Collection are supported.");
}
// Then build its operations.
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;
}
use of io.github.microcks.util.MockRepositoryImportException in project microcks by microcks.
the class SoapUIProjectImporter method getSoapServiceDefinitions.
/**
* Get the definitions of Soap Services from mock services.
*/
private List<Service> getSoapServiceDefinitions(List<WsdlMockService> mockServices) throws MockRepositoryImportException {
List<Service> result = new ArrayList<>();
for (WsdlMockService wms : mockServices) {
// First assume it's a Soap one.
Service service = new Service();
service.setName(wms.getName());
service.setType(ServiceType.SOAP_HTTP);
// Ensure we've got only one interface and extract its namespace.
WsdlInterface[] wi = wms.getMockedInterfaces();
if (wi == null || wi.length > 1) {
// TODO Throw a typed exception here...
}
service.setXmlNS(wi[0].getBindingName().getNamespaceURI());
// Extract version from custom properties.
String version = wms.getPropertyValue(SERVICE_VERSION_PROPERTY);
if (version == null) {
log.error("Version property is missing in Project properties");
throw new MockRepositoryImportException("Version property is missing in Project properties");
}
service.setVersion(version);
// Then build its operations.
service.setOperations(extractOperations(wms, wi[0]));
result.add(service);
}
return result;
}
Aggregations