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