Class ApiTestRenderer

java.lang.Object
com.shaft.capture.generate.api.ApiTestRenderer

public final class ApiTestRenderer extends Object
Renders a compiling SHAFT.API TestNG class from recorded, classified, and correlated API transactions. Mirrors com.shaft.capture.generate.CaptureGenerator's validate->analyze->render staging, scoped to API transactions rather than UI events.

One SHAFT.API field is rendered per origin (scheme://host[:port]); headers common to every transaction of an origin are hoisted into @BeforeClass as session-level headers, and any sensitive header (a secret-ref:<ENV_NAME> token from com.shaft.capture.network.SecretHeaderReplacer) is replayed via a generated requiredEnvironment(String) helper rather than ever being written to source as a literal.

Correlation (see TransactionCorrelator) only ever chains values within the same rendered @Test method -- a variable extracted in one method is not visible from another, so correlation is computed and applied per origin group (one SCENARIO method), never across origins or across PER_REQUEST methods.

  • Method Details

    • render

      public static RenderedApiTest render(String packageName, String className, List<ApiTransaction> transactions, ApiCodegenStyle style, ApiValidationDepth depth)
      Renders one API test class from a set of already-filtered, renderable transactions.
      Parameters:
      packageName - generated class package
      className - generated class name
      transactions - renderable transactions (already filtered to XHR/FETCH-like requests with a real response) in recorded order
      style - how transactions are grouped into test methods
      depth - how thoroughly each response is validated
      Returns:
      generated source, any test-data artifacts (schema/golden files) it references, and any transaction IDs skipped because SHAFT.API has no builder for their HTTP method
    • render

      public static RenderedApiTest render(String packageName, String className, List<ApiTransaction> transactions, ApiCodegenStyle style, ApiValidationDepth depth, Map<Long, List<String>> uiActionsBySequence, Set<String> pinnedJsonPaths)
      Renders one API test class, as render(String, String, List, ApiCodegenStyle, ApiValidationDepth, Map), additionally accepting an explicit set of response JSON paths to force-assert as ApiValidationDepth.BUSINESS business assertions even when their leaf is classified VOLATILE or CORRELATED (issue #3530 pinned-path render gate). A SENSITIVE leaf or a blank-value leaf is never asserted, regardless of pinning.
      Parameters:
      packageName - generated class package
      className - generated class name
      transactions - renderable transactions in recorded order
      style - how transactions are grouped into test methods
      depth - how thoroughly each response is validated
      uiActionsBySequence - for ApiCodegenStyle.HYBRID_UI_API only: see render(String, String, List, ApiCodegenStyle, ApiValidationDepth, Map)
      pinnedJsonPaths - response JSON paths (e.g. $.status) to force-include as business assertions at BUSINESS depth; ignored at every other depth. null is treated as empty.
      Returns:
      generated source, any test-data artifacts it references, and any transaction IDs skipped because SHAFT.API has no builder for their HTTP method
    • render

      public static RenderedApiTest render(String packageName, String className, List<ApiTransaction> transactions, ApiCodegenStyle style, ApiValidationDepth depth, Map<Long, List<String>> uiActionsBySequence)
      Renders one API test class, as render(String, String, List, ApiCodegenStyle, ApiValidationDepth), additionally accepting pre-rendered UI action source lines for ApiCodegenStyle.HYBRID_UI_API.
      Parameters:
      packageName - generated class package
      className - generated class name
      transactions - renderable transactions in recorded order
      style - how transactions are grouped into test methods
      depth - how thoroughly each response is validated
      uiActionsBySequence - for ApiCodegenStyle.HYBRID_UI_API only: caller-supplied UI action source lines (e.g. driver.element().click(...);) keyed by the capture-session sequence number they were recorded at. Ignored by every other style. May be empty, in which case the hybrid method still renders deterministically -- it degrades to API-only assertions with no interleaved UI lines.
      Returns:
      generated source, any test-data artifacts it references, and any transaction IDs skipped because SHAFT.API has no builder for their HTTP method