Search in sources :

Example 16 with MockRepositoryImportException

use of io.github.microcks.util.MockRepositoryImportException in project microcks by microcks.

the class ProtobufImporterTest method testProtobufWithRemoteDependenciesImport.

@Test
public void testProtobufWithRemoteDependenciesImport() {
    ProtobufImporter importer = null;
    try {
        importer = new ProtobufImporter("target/test-classes/io/github/microcks/util/grpc/remote/goodbye-v1.proto", new ReferenceResolver("https://raw.githubusercontent.com/microcks/microcks/1.5.x/webapp/src/test/resources/io/github/microcks/util/grpc/base.proto", null, true));
    } 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("GoodbyeService", service.getName());
    assertEquals(ServiceType.GRPC, service.getType());
    assertEquals("v1", service.getVersion());
    assertEquals("io.github.microcks.grpc.goodbye.v1", service.getXmlNS());
    // 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(3, resources.size());
    for (Resource resource : resources) {
        assertNotNull(resource.getContent());
        if (ResourceType.PROTOBUF_SCHEMA.equals(resource.getType())) {
            assertTrue("GoodbyeService-v1.proto".equals(resource.getName()) || "GoodbyeService-v1-shared~1uuid.proto".equals(resource.getName()));
        } else if (ResourceType.PROTOBUF_DESCRIPTOR.equals(resource.getType())) {
            assertEquals("GoodbyeService-v1.pbb", resource.getName());
            System.err.println("base64: " + resource.getContent());
            try {
                // Check Protobuf Descriptor.
                byte[] decodedBinaryPB = Base64.getDecoder().decode(resource.getContent().getBytes("UTF-8"));
                DescriptorProtos.FileDescriptorSet fds = DescriptorProtos.FileDescriptorSet.parseFrom(decodedBinaryPB);
                assertEquals(2, fds.getFileCount());
                assertEquals("shared/uuid.proto", fds.getFile(0).getName());
                assertEquals("goodbye-v1.proto", fds.getFile(1).getName());
            } catch (Exception e) {
                fail("Protobuf file descriptor is not correct");
            }
        } else {
            fail("Resource has not the expected type");
        }
    }
}
Also used : Resource(io.github.microcks.domain.Resource) Service(io.github.microcks.domain.Service) IOException(java.io.IOException) MockRepositoryImportException(io.github.microcks.util.MockRepositoryImportException) ReferenceResolver(io.github.microcks.util.ReferenceResolver) IOException(java.io.IOException) MockRepositoryImportException(io.github.microcks.util.MockRepositoryImportException) Test(org.junit.Test)

Example 17 with MockRepositoryImportException

use of io.github.microcks.util.MockRepositoryImportException in project microcks by microcks.

the class ProtobufImporterTest method testSimpleProtobufImport.

@Test
public void testSimpleProtobufImport() {
    ProtobufImporter importer = null;
    try {
        importer = new ProtobufImporter("target/test-classes/io/github/microcks/util/grpc/hello-v1.proto", null);
    } 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("HelloService", service.getName());
    assertEquals(ServiceType.GRPC, service.getType());
    assertEquals("v1", service.getVersion());
    assertEquals("io.github.microcks.grpc.hello.v1", service.getXmlNS());
    // 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(2, resources.size());
    for (Resource resource : resources) {
        assertNotNull(resource.getContent());
        if (ResourceType.PROTOBUF_SCHEMA.equals(resource.getType())) {
            assertEquals("HelloService-v1.proto", resource.getName());
        } else if (ResourceType.PROTOBUF_DESCRIPTOR.equals(resource.getType())) {
            assertEquals("HelloService-v1.pbb", resource.getName());
        } else {
            fail("Resource has not the expected type");
        }
    }
    // Check that operations and input/output have been found.
    assertEquals(1, service.getOperations().size());
    Operation operation = service.getOperations().get(0);
    assertEquals("greeting", operation.getName());
    assertEquals(".io.github.microcks.grpc.hello.v1.HelloRequest", operation.getInputName());
    assertEquals(".io.github.microcks.grpc.hello.v1.HelloResponse", operation.getOutputName());
}
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 18 with MockRepositoryImportException

use of io.github.microcks.util.MockRepositoryImportException in project microcks by microcks.

the class MetadataImporterTest method testAPIMetadataImport.

@Test
public void testAPIMetadataImport() {
    MetadataImporter importer = null;
    try {
        importer = new MetadataImporter("target/test-classes/io/github/microcks/util/metadata/hello-grpc-v1-metadata.yml");
    } 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("HelloService", service.getName());
    assertEquals("v1", service.getVersion());
    assertEquals(3, service.getMetadata().getLabels().size());
    assertEquals("greeting", service.getMetadata().getLabels().get("domain"));
    assertEquals("stable", service.getMetadata().getLabels().get("status"));
    assertEquals("Team A", service.getMetadata().getLabels().get("team"));
    assertEquals(1, service.getOperations().size());
    Operation operation = service.getOperations().get(0);
    assertEquals("POST /greeting", operation.getName());
    assertEquals(Long.valueOf(100), operation.getDefaultDelay());
    assertEquals(DispatchStyles.JSON_BODY, operation.getDispatcher());
    assertNotNull(operation.getDispatcherRules());
}
Also used : 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 19 with MockRepositoryImportException

use of io.github.microcks.util.MockRepositoryImportException in project microcks by microcks.

the class SoapUIProjectImporterTest method testHelloAPIProjectImport.

@Test
public void testHelloAPIProjectImport() {
    MockRepositoryImporter importer = null;
    try {
        importer = MockRepositoryImporterFactory.getMockRepositoryImporter(new java.io.File("target/test-classes/io/github/microcks/util/soapui/HelloAPI-soapui-project.xml"), null);
    } catch (Exception e) {
        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());
}
Also used : MockRepositoryImporter(io.github.microcks.util.MockRepositoryImporter) MockRepositoryImportException(io.github.microcks.util.MockRepositoryImportException) MockRepositoryImportException(io.github.microcks.util.MockRepositoryImportException) Test(org.junit.Test)

Example 20 with MockRepositoryImportException

use of io.github.microcks.util.MockRepositoryImportException in project microcks by microcks.

the class JobService method doImportJob.

/**
 * Realize the import of a repository defined into an import job.
 * @param job The job containing information onto the repository.
 */
public void doImportJob(ImportJob job) {
    log.info("Starting import for job '{}'", job.getName());
    // Retrieve associated secret if any.
    Secret jobSecret = null;
    if (job.getSecretRef() != null) {
        log.debug("Retrieving secret {} for job {}", job.getSecretRef().getName(), job.getName());
        jobSecret = secretRepository.findById(job.getSecretRef().getSecretId()).orElse(null);
    }
    // Reinitialize service references and import errors before new import.
    job.setServiceRefs(null);
    job.setLastImportError(null);
    List<Service> services = null;
    try {
        services = serviceService.importServiceDefinition(job.getRepositoryUrl(), jobSecret, job.isRepositoryDisableSSLValidation(), job.isMainArtifact());
    } catch (MockRepositoryImportException mrie) {
        log.warn("MockRepositoryImportException while importing job '{}' : {}", job.getName(), mrie.getMessage());
        job.setLastImportError(mrie.getMessage());
    }
    // Add service references if any.
    if (services != null) {
        for (Service service : services) {
            job.addServiceRef(new ServiceRef(service.getId(), service.getName(), service.getVersion()));
        }
    }
    job.setLastImportDate(new Date());
    jobRepository.save(job);
    log.info("Import of job '{}' done", job.getName());
}
Also used : Secret(io.github.microcks.domain.Secret) Service(io.github.microcks.domain.Service) MockRepositoryImportException(io.github.microcks.util.MockRepositoryImportException) ServiceRef(io.github.microcks.domain.ServiceRef) Date(java.util.Date)

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