Class WireMockJavaDslScanner

java.lang.Object
com.arc_e_tect.gradle.mirage.scan.WireMockJavaDslScanner

public class WireMockJavaDslScanner extends Object
Scans Java source files for WireMock's fluent Java stub-registration DSL, e.g.:

 stubFor(get(urlEqualTo("/orders/1")).willReturn(aResponse().withStatus(200)));
 

Unlike WireMockStubScanner, which reads static *.json stub mapping files, this scanner finds stubs registered programmatically at test run time - evidence WireMockStubScanner cannot "see" since no mapping file for it exists on disk. Matches by simple method name only, the same way ControllerScanner and RestDocsScanner match by simple annotation/method name, so this scanner needs neither WireMock nor Spring on its own classpath.

Recognises any call to a method named stubFor(...) with exactly one argument - regardless of its scope, so both the statically-imported stubFor(...) and an instance call like wireMockServer.stubFor(...) are matched - whose argument is a fluent chain built from one of WireMock's verb builders (get/post/put/ delete/patch/head/options/trace) applied to one of its URL matchers (urlEqualTo/urlPathEqualTo/urlMatching/ urlPathMatching/urlPathTemplate) with a literal string argument. Any other builder calls chained in between - .willReturn(...), .atPriority(...), .inScenario(...), etc. - are walked through transparently, since they are chained directly onto the verb builder call.

A stubFor(...) call whose argument isn't shaped this way - e.g. the mapping builder was assembled in a local variable first, the URL matcher argument is not a string literal, or the matcher is a dynamic one like anyUrl() - is silently skipped, the same way WireMockStubScanner skips a stub file missing a recognised method/URL field.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new WireMockJavaDslScanner.
  • Method Summary

    Modifier and Type
    Method
    Description
    List<com.arc_e_tect.gradle.detector.core.model.Endpoint>
    scan(File rootDir)
    Scans every .java file under rootDir, recursively, for stubFor(...) calls shaped as described in the class documentation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WireMockJavaDslScanner

      public WireMockJavaDslScanner()
      Creates a new WireMockJavaDslScanner.
  • Method Details

    • scan

      public List<com.arc_e_tect.gradle.detector.core.model.Endpoint> scan(File rootDir) throws IOException
      Scans every .java file under rootDir, recursively, for stubFor(...) calls shaped as described in the class documentation.
      Parameters:
      rootDir - directory to search; may not exist, in which case an empty list is returned
      Returns:
      one Endpoint per recognised stubFor(...) call found
      Throws:
      IOException - if a source file cannot be read