Search in sources :

Example 26 with Service

use of io.github.microcks.domain.Service in project microcks by microcks.

the class ServiceRepositoryTest method testFindOne.

@Test
public void testFindOne() {
    Service service = repository.findById(serviceId).orElse(null);
    assertNotNull(service);
    assertEquals("MyService-hello", service.getName());
    assertEquals("1.1", service.getVersion());
}
Also used : Service(io.github.microcks.domain.Service) Test(org.junit.Test)

Example 27 with Service

use of io.github.microcks.domain.Service in project microcks by microcks.

the class TestResultRepositoryTest method setUp.

@Before
public void setUp() {
    // Create a service...
    Service service = new Service();
    service.setName("HelloWorld");
    service.setVersion("1.0");
    serviceRepository.save(service);
    // Create a bunch of test results for this service.
    TestResult testResult = new TestResult();
    testResult.setInProgress(false);
    testResult.setRunnerType(TestRunnerType.HTTP);
    testResult.setTestNumber(1L);
    testResult.setServiceId(service.getId());
    testResult.setTestedEndpoint("http://localhost:8088/HelloWorld");
    repository.save(testResult);
    // ... another one.
    testResult = new TestResult();
    testResult.setInProgress(false);
    testResult.setRunnerType(TestRunnerType.HTTP);
    testResult.setTestNumber(2L);
    testResult.setServiceId(service.getId());
    testResult.setTestedEndpoint("http://localhost:8088/HelloWorld");
    repository.save(testResult);
    serviceId = service.getId();
}
Also used : Service(io.github.microcks.domain.Service) TestResult(io.github.microcks.domain.TestResult) Before(org.junit.Before)

Example 28 with Service

use of io.github.microcks.domain.Service in project microcks by microcks.

the class ServiceServiceTest method testImportServiceDefinitionMainAndSecondary.

@Test
public void testImportServiceDefinitionMainAndSecondary() {
    List<Service> services = null;
    try {
        File artifactFile = new File("target/test-classes/io/github/microcks/service/weather-forecast-raw-openapi.yaml");
        services = service.importServiceDefinition(artifactFile, null, new ArtifactInfo("weather-forecast-raw-openapi.yaml", true));
    } catch (MockRepositoryImportException mrie) {
        mrie.printStackTrace();
        fail("No MockRepositoryImportException should have be thrown");
    }
    assertNotNull(services);
    assertEquals(1, services.size());
    // Inspect Service own attributes.
    Service importedSvc = services.get(0);
    assertEquals("WeatherForecast API", importedSvc.getName());
    assertEquals("1.1.0", importedSvc.getVersion());
    assertEquals("weather-forecast-raw-openapi.yaml", importedSvc.getSourceArtifact());
    assertNotNull(importedSvc.getMetadata());
    assertEquals(1, importedSvc.getOperations().size());
    assertNull(importedSvc.getOperations().get(0).getResourcePaths());
    // Inspect and check resources.
    List<Resource> resources = resourceRepository.findByServiceId(importedSvc.getId());
    assertEquals(1, resources.size());
    Resource resource = resources.get(0);
    assertEquals("WeatherForecast API-1.1.0.yaml", resource.getName());
    assertEquals("weather-forecast-raw-openapi.yaml", resource.getSourceArtifact());
    // Inspect and check requests.
    List<Request> requests = requestRepository.findByOperationId(IdBuilder.buildOperationId(importedSvc, importedSvc.getOperations().get(0)));
    assertEquals(0, requests.size());
    // Inspect and check responses.
    List<Response> responses = responseRepository.findByOperationId(IdBuilder.buildOperationId(importedSvc, importedSvc.getOperations().get(0)));
    assertEquals(0, responses.size());
    try {
        File artifactFile = new File("target/test-classes/io/github/microcks/service/weather-forecast-postman.json");
        services = service.importServiceDefinition(artifactFile, null, new ArtifactInfo("weather-forecast-postman.json", false));
    } catch (MockRepositoryImportException mrie) {
        mrie.printStackTrace();
        fail("No MockRepositoryImportException should have be thrown");
    }
    // Inspect Service own attributes.
    importedSvc = services.get(0);
    assertEquals("WeatherForecast API", importedSvc.getName());
    assertEquals("1.1.0", importedSvc.getVersion());
    assertEquals("weather-forecast-raw-openapi.yaml", importedSvc.getSourceArtifact());
    assertNotNull(importedSvc.getMetadata());
    assertEquals(1, importedSvc.getOperations().size());
    assertEquals(DispatchStyles.URI_ELEMENTS, importedSvc.getOperations().get(0).getDispatcher());
    assertEquals(5, importedSvc.getOperations().get(0).getResourcePaths().size());
    // Inspect and check resources.
    resources = resourceRepository.findByServiceId(importedSvc.getId());
    assertEquals(1, resources.size());
    resource = resources.get(0);
    assertEquals("WeatherForecast API-1.1.0.yaml", resource.getName());
    assertEquals("weather-forecast-raw-openapi.yaml", resource.getSourceArtifact());
    // Inspect and check requests.
    requests = requestRepository.findByOperationId(IdBuilder.buildOperationId(importedSvc, importedSvc.getOperations().get(0)));
    assertEquals(5, requests.size());
    for (Request request : requests) {
        assertEquals("weather-forecast-postman.json", request.getSourceArtifact());
    }
    // Inspect and check responses.
    responses = responseRepository.findByOperationId(IdBuilder.buildOperationId(importedSvc, importedSvc.getOperations().get(0)));
    assertEquals(5, requests.size());
    for (Response response : responses) {
        assertEquals("weather-forecast-postman.json", response.getSourceArtifact());
    }
}
Also used : Response(io.github.microcks.domain.Response) Resource(io.github.microcks.domain.Resource) Request(io.github.microcks.domain.Request) Service(io.github.microcks.domain.Service) File(java.io.File) MockRepositoryImportException(io.github.microcks.util.MockRepositoryImportException) Test(org.junit.Test)

Example 29 with Service

use of io.github.microcks.domain.Service in project microcks by microcks.

the class ProtobufImporterTest method testProtobufWithDependenciesImport.

@Test
public void testProtobufWithDependenciesImport() {
    ProtobufImporter importer = null;
    try {
        importer = new ProtobufImporter("target/test-classes/io/github/microcks/util/grpc/goodbye-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("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(2, resources.size());
    for (Resource resource : resources) {
        assertNotNull(resource.getContent());
        if (ResourceType.PROTOBUF_SCHEMA.equals(resource.getType())) {
            assertEquals("GoodbyeService-v1.proto", resource.getName());
        } else if (ResourceType.PROTOBUF_DESCRIPTOR.equals(resource.getType())) {
            assertEquals("GoodbyeService-v1.pbb", resource.getName());
            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) IOException(java.io.IOException) MockRepositoryImportException(io.github.microcks.util.MockRepositoryImportException) Test(org.junit.Test)

Example 30 with Service

use of io.github.microcks.domain.Service 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)

Aggregations

Service (io.github.microcks.domain.Service)42 MockRepositoryImportException (io.github.microcks.util.MockRepositoryImportException)18 Operation (io.github.microcks.domain.Operation)15 Test (org.junit.Test)15 Resource (io.github.microcks.domain.Resource)12 IOException (java.io.IOException)10 ResponseEntity (org.springframework.http.ResponseEntity)7 Response (io.github.microcks.domain.Response)6 File (java.io.File)6 ArrayList (java.util.ArrayList)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Exchange (io.github.microcks.domain.Exchange)4 Request (io.github.microcks.domain.Request)4 RequestResponsePair (io.github.microcks.domain.RequestResponsePair)4 UnidirectionalEvent (io.github.microcks.domain.UnidirectionalEvent)4 List (java.util.List)4 HttpHeaders (org.springframework.http.HttpHeaders)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Header (io.github.microcks.domain.Header)3 Metadata (io.github.microcks.domain.Metadata)3