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());
}
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();
}
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());
}
}
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");
}
}
}
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");
}
}
}
Aggregations