Search in sources :

Example 11 with Request

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());
    }
}
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 12 with Request

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;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Request(io.github.microcks.domain.Request) ArrayList(java.util.ArrayList)

Example 13 with Request

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);
}
Also used : Response(io.github.microcks.domain.Response) TestStepResult(io.github.microcks.domain.TestStepResult) TestReturn(io.github.microcks.domain.TestReturn) ArrayList(java.util.ArrayList) PageRequest(org.springframework.data.domain.PageRequest) Request(io.github.microcks.domain.Request)

Aggregations

Request (io.github.microcks.domain.Request)13 Response (io.github.microcks.domain.Response)8 ArrayList (java.util.ArrayList)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Resource (io.github.microcks.domain.Resource)4 Service (io.github.microcks.domain.Service)4 TestReturn (io.github.microcks.domain.TestReturn)4 MockRepositoryImportException (io.github.microcks.util.MockRepositoryImportException)4 IOException (java.io.IOException)4 Test (org.junit.Test)4 Header (io.github.microcks.domain.Header)3 File (java.io.File)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Operation (io.github.microcks.domain.Operation)2 Parameter (io.github.microcks.domain.Parameter)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 HashSet (java.util.HashSet)2 PageRequest (org.springframework.data.domain.PageRequest)2 ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)2