use of io.github.microcks.domain.Request 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.Request in project microcks by microcks.
the class TestRunnerService method cloneRequestsForTestCase.
/**
* Clone and prepare request for a test case usage.
*/
private List<Request> cloneRequestsForTestCase(List<Request> requests, String testCaseId) {
List<Request> result = new ArrayList<>();
for (Request request : requests) {
Request clone = new Request();
clone.setName(request.getName());
clone.setContent(request.getContent());
clone.setHeaders(request.getHeaders());
clone.setQueryParameters(request.getQueryParameters());
clone.setResponseId(request.getResponseId());
// Assign testCaseId.
clone.setTestCaseId(testCaseId);
result.add(clone);
}
return result;
}
use of io.github.microcks.domain.Request in project microcks by microcks.
the class TestRunnerService method updateTestCaseResultWithReturns.
/**
*/
private void updateTestCaseResultWithReturns(TestCaseResult testCaseResult, List<TestReturn> testReturns, String testCaseId) {
// Prepare a bunch of flag we're going to complete.
boolean successFlag = true;
long caseElapsedTime = 0;
List<Response> responses = new ArrayList<>();
List<Request> actualRequests = new ArrayList<>();
for (TestReturn testReturn : testReturns) {
// Deal with elapsed time and success flag.
caseElapsedTime += testReturn.getElapsedTime();
TestStepResult testStepResult = testReturn.buildTestStepResult();
if (!testStepResult.isSuccess()) {
successFlag = false;
}
// Extract, complete and store response and request.
testReturn.getResponse().setTestCaseId(testCaseId);
testReturn.getRequest().setTestCaseId(testCaseId);
responses.add(testReturn.getResponse());
actualRequests.add(testReturn.getRequest());
testCaseResult.getTestStepResults().add(testStepResult);
}
// Save the responses into repository to get their ids.
log.debug("Saving {} responses with testCaseId {}", responses.size(), testCaseId);
responseRepository.saveAll(responses);
// Associate responses to requests before saving requests.
for (int i = 0; i < actualRequests.size(); i++) {
actualRequests.get(i).setResponseId(responses.get(i).getId());
}
log.debug("Saving {} requests with testCaseId {}", responses.size(), testCaseId);
requestRepository.saveAll(actualRequests);
// We cannot consider as success if we have no TestStepResults associated...
if (testCaseResult.getTestStepResults().size() > 0) {
testCaseResult.setSuccess(successFlag);
}
testCaseResult.setElapsedTime(caseElapsedTime);
}
Aggregations