Class GrpcService

java.lang.Object
io.keploy.service.GrpcService

public class GrpcService extends Object
This is a service class. This is the class where Java-sdk communicates with Keploy server to record/store tests and to perform testing.
  • Field Details

  • Constructor Details

    • GrpcService

      public GrpcService()
      Initialising GRPC server ang Keploy instance
  • Method Details

    • CaptureTestCases

      public static void CaptureTestCases(String reqBody, Map<String,String> params, Service.HttpResp httpResp, String protocolType, Map<String,List<MultipartContent>> formData)
      Modifies all the test cases and mocks that are present into the format which GRPC accepts and send request to GRPC to save tests and mocks that are recorded
      Parameters:
      reqBody - - http request body recorded from the filter
      params - - http query params recorded from the filter
      httpResp - - http response body recorded from the filter
      protocolType - - http protocolType recorded from the filter
      formData - - http form data
    • Capture

      public static void Capture(Service.TestCaseReq.Builder testCaseReqBuilder, Map<String,List<MultipartContent>> formData, Service.HttpReq.Builder httpReqBuilder)
      This method runs in threads asynchronously and sends request to Server to capture tests and mocks
      Parameters:
      testCaseReqBuilder - - test case object builder
      formData - - form data from http request
      httpReqBuilder - - http request builder
    • put

      public static void put(Service.TestCaseReq testCaseReq)
      This method sends the testcases to the server
      Parameters:
      testCaseReq - - test case object
    • isValidTestCaseToBeRecorded

      public static boolean isValidTestCaseToBeRecorded(Service.TestCaseReq testCaseReq)
      Is valid test case to be recorded boolean. This method is used to check if the test case should be recorded or discarded.
      Parameters:
      testCaseReq - the test case req object which contains all the information about the test case
      Returns:
      the boolean value which indicates if the test case should be recorded or discarded
    • doesFollowAcceptanceRegex

      public static boolean doesFollowAcceptanceRegex(Service.TestCaseReq testCaseReq)
      Does follow acceptance regex boolean. This method is used to check if the test case url and header matches the acceptance regex.
      Parameters:
      testCaseReq - the test case req object which contains all the information about the test case
      Returns:
      the boolean value which indicates if the test case url and header matches the acceptance regex
    • doesFollowRejectionRegex

      public static boolean doesFollowRejectionRegex(Service.TestCaseReq testCaseReq)
      Does follow rejection regex boolean. This method is used to check if the test case url and header matches the rejection regex.
      Parameters:
      testCaseReq - the test case req object which contains all the information about the test case.
      Returns:
      the boolean value which indicates if the test case url and header matches the rejection regex
    • denoise

      public static void denoise(String id, Service.TestCaseReq testCaseReq)
      Denoising while recording test cases
      Parameters:
      id - - test case id
      testCaseReq - - test case object
    • simulate

      public static Service.HttpResp simulate(Service.TestCase testCase)
      This method runs each test on client application in test mode by setting mocks and data in context.
      Parameters:
      testCase - - test case object
      Returns:
      - response for the test
    • isSuccessfulResponse

      public static boolean isSuccessfulResponse(HttpURLConnection connection)
    • getSimulateResponseBody

      public static String getSimulateResponseBody(HttpURLConnection httpConn) throws IOException
      Throws:
      IOException
    • GetResp

      public static Service.HttpResp.Builder GetResp(String id)
    • Test

      public static void Test()
      Starts testing of the recorded test cases
    • start

      public static String start(String total)
      Provides the test run id
      Parameters:
      total - - total no of test cases
      Returns:
      - test run id
    • end

      public static void end(String id, boolean status)
      Send request to server that test run is done. So that post-processing will be done
      Parameters:
      id - - test run id
      status - - status of the test run
    • fetch

      public static List<Service.TestCase> fetch()
      Fetch all the test cases and mocks that are recorded
      Returns:
      - list if testcase objects
    • check

      public static boolean check(String testrunId, Service.TestCase tc)
      Starts the simulate for every test case and compared with the response recorded before
      Parameters:
      testrunId - - test run id
      tc - - test case object
      Returns:
      - Boolean whether pass or fail
    • saveFile

      public static String saveFile(String filePath, byte[] body)
    • determineFilePath

      public static String determineFilePath(String fileName)