Search in sources :

Example 6 with MockRepositoryImportException

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");
        }
    }
}
Also used : Resource(io.github.microcks.domain.Resource) Service(io.github.microcks.domain.Service) IOException(java.io.IOException) Operation(io.github.microcks.domain.Operation) MockRepositoryImportException(io.github.microcks.util.MockRepositoryImportException) Test(org.junit.Test)

Example 7 with MockRepositoryImportException

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"));
}
Also used : IOException(java.io.IOException) MockRepositoryImportException(io.github.microcks.util.MockRepositoryImportException) ReferenceResolver(io.github.microcks.util.ReferenceResolver) Test(org.junit.Test)

Example 8 with MockRepositoryImportException

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"));
}
Also used : IOException(java.io.IOException) MockRepositoryImportException(io.github.microcks.util.MockRepositoryImportException) ReferenceResolver(io.github.microcks.util.ReferenceResolver) Test(org.junit.Test)

Example 9 with MockRepositoryImportException

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;
}
Also used : Service(io.github.microcks.domain.Service) MockRepositoryImportException(io.github.microcks.util.MockRepositoryImportException)

Example 10 with MockRepositoryImportException

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;
}
Also used : WsdlMockService(com.eviware.soapui.impl.wsdl.mock.WsdlMockService) WsdlInterface(com.eviware.soapui.impl.wsdl.WsdlInterface) WsdlMockService(com.eviware.soapui.impl.wsdl.mock.WsdlMockService) RestMockService(com.eviware.soapui.impl.rest.mock.RestMockService) MockService(com.eviware.soapui.model.mock.MockService) MockRepositoryImportException(io.github.microcks.util.MockRepositoryImportException)

Aggregations

MockRepositoryImportException (io.github.microcks.util.MockRepositoryImportException)23 Service (io.github.microcks.domain.Service)16 IOException (java.io.IOException)12 Test (org.junit.Test)12 Resource (io.github.microcks.domain.Resource)8 File (java.io.File)7 ReferenceResolver (io.github.microcks.util.ReferenceResolver)5 Operation (io.github.microcks.domain.Operation)4 Request (io.github.microcks.domain.Request)3 Response (io.github.microcks.domain.Response)3 ArrayList (java.util.ArrayList)3 RestMockService (com.eviware.soapui.impl.rest.mock.RestMockService)2 WsdlMockService (com.eviware.soapui.impl.wsdl.mock.WsdlMockService)2 MockService (com.eviware.soapui.model.mock.MockService)2 Metadata (io.github.microcks.domain.Metadata)2 ArtifactInfo (io.github.microcks.service.ArtifactInfo)2 ServiceService (io.github.microcks.service.ServiceService)2 HTTPDownloader (io.github.microcks.util.HTTPDownloader)2 MockRepositoryImporter (io.github.microcks.util.MockRepositoryImporter)2 ResponseEntity (org.springframework.http.ResponseEntity)2