MockLayer vs WireMock for SAP OData Testing

Ovidiu12 min read

WireMock Is the Right Tool — for REST APIs

WireMock is battle-tested: over a decade of development, a Docker image, JUnit integration, .NET and Python libraries, and a cloud-hosted option. For mocking REST and JSON APIs, it covers request matching, response templating, fault injection, and request verification.

SAP OData is not a standard REST API.

SAP OData has protocol-level requirements that generic HTTP mocks don't handle — envelopes, date encoding, CSRF tokens, navigation properties. Our CI/CD guide covers each of these in detail. WireMock treats OData as plain HTTP, which means every protocol-specific behavior becomes your responsibility to hand-code in stub files or record from a live system.

This post compares WireMock and MockLayer specifically for SAP OData mocking in backend integration tests. Both tools have different design goals. The question is which one removes more friction when the API you're mocking follows the OData protocol and describes itself via EDMX.

The Core Difference: Stubs vs. Metadata

WireMock works by matching incoming requests to pre-defined stubs. You write a JSON mapping that says "when this URL pattern arrives, return this response body." The response body is a file you author by hand or capture from a real system.

MockLayer works by reading the EDMX metadata that every SAP OData service exposes at its $metadata endpoint. It parses entity types, property definitions, data types, and navigation relationships — then generates responses on the fly. No stub files. No response bodies to maintain.

This distinction matters most when the SAP schema changes. With WireMock, every affected stub needs an edit or a new recording. With MockLayer, the next metadata refresh picks up the change if MockLayer can reach SAP; offline, you upload one new EDMX file.

What a WireMock SAP OData Stub Looks Like

This WireMock stub for a single entity set uses two files.

1. A stub mapping (mappings/business-partners.json):

{
  "request": {
    "method": "GET",
    "urlPathPattern": "/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner.*"
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "bodyFileName": "business-partners.json"
  }
}

2. A response body (__files/business-partners.json):

{
  "d": {
    "results": [
      {
        "__metadata": {
          "uri": "https://host/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('1000001')",
          "type": "API_BUSINESS_PARTNER.A_BusinessPartnerType"
        },
        "BusinessPartner": "1000001",
        "BusinessPartnerFullName": "Acme Corp",
        "BusinessPartnerCategory": "2",
        "CreationDate": "/Date(1672531200000)/",
        "to_BusinessPartnerAddress": { "__deferred": { "uri": "..." } }
      }
    ]
  }
}

That's one entity with four properties and one navigation property. The actual A_BusinessPartnerType in API_BUSINESS_PARTNER has 69 properties and 26 navigation properties, so a body with five complete entities runs to hundreds of lines. The service defines 65 entity types in total.

A test suite that covers several entity sets needs a stub for each of them and for each $expand path it uses, plus stubs for $metadata and the CSRF token fetch if the client requests them. The $expand problem is combinatorial: to_BusinessPartnerAddress needs one stub, to_BusinessPartnerAddress,to_BusinessPartnerContact needs another, and each expanded path requires its own nested response body with the correct entity type structure.

Nothing in WireMock enforces that your hand-coded response bodies match the EDMX schema. Add a field to the $metadata stub but forget to update a response body — your mock is self-contradictory and your tests pass against data that SAP would never return.

Earlier Reports of the Same Gap

The OData question has been raised with the WireMock.Net maintainers. WireMock.Net issue #556 ("Support OData", opened in 2020) asked for built-in OData query support: stub a single response and have WireMock.Net filter the results by the OData query options. The maintainer replied that "OData is just a specification" and that WireMock.Net can stub any request and response. The issue was later labelled wontfix and closed as not planned (2025). In practice, every OData query variation is yours to stub.

A 2020 blog post on the SAP Community about integration tests with SAP Cloud SDK 2.x says the SDK "does not provide such an easy method to mock the OData call", so the author used WireMock and defined the stub in the Java test code.

SAP also published a mock server example with the sample code for the book Extending SAP S/4HANA, which covers the SAP S/4HANA Cloud SDK: a Node.js server that mimics the business partner API "to a limited extent", built from an EDMX file you download and edit by hand. Its documentation says it is "by no means a complete OData service compliant with the OData v2 specification." The repository was archived on 29 November 2023.

A Maintenance Scenario: Three New Fields

Setup happens once; maintenance repeats with every schema change. Here is a hypothetical example.

Suppose an SAP upgrade adds three properties to A_BusinessPartnerType: LastChangeDateTime (Edm.DateTimeOffset), ResponsibleCompanyCode (Edm.String, length 4), and BusinessPartnerIsNotReleased (Edm.Boolean).

What changes in WireMock:

Every stub response file that returns A_BusinessPartner entities needs updating. If you have five stubs covering different query patterns (list, single entity, expanded with addresses, expanded with contacts, filtered by category), that is five response body files. In each file, every entity object needs the three new properties, with values in the JSON format that SAP uses for each type: a timestamp, a 4-character company code, and a boolean.

If you also maintain a $metadata stub, the EDMX XML needs the three new <Property> elements added to the A_BusinessPartnerType definition. Miss it, and the mock contradicts itself: the data contains properties that its own EDMX does not declare.

Miss one response body file and that stub returns entities without the new fields, so no test exercises your handling of them.

If SAP is reachable, WireMock's record and snapshot features can capture new stubs from live traffic instead. The captured data is whatever the shared system holds at that moment.

What changes in MockLayer:

Re-export the EDMX from SAP (one GET $metadata call) and upload it, or replace the file your CI job uploads. If MockLayer can reach SAP, it fetches $metadata again once the configurable TTL expires (default 24 hours). From then on, generated responses include the three new properties, with values generated for their EDM types.

Adding a new entity set (e.g., A_BusinessPartnerContact):

  • WireMock: author or record a new stub, with the correct OData envelope and entity structure, looking up property names and types in the EDMX
  • MockLayer: query it — the entity already exists in the EDMX

Adding $expand to an existing query:

  • WireMock: create a new stub for the expanded variant, or update the existing response body with manually nested entities matching the target entity type's schema
  • MockLayer: add $expand=to_BusinessPartnerContact to the URL

Where WireMock Wins

WireMock does things MockLayer does not do. These are real strengths, not token concessions.

Error simulation. WireMock can return specific HTTP status codes, inject faults, and simulate latency. A fault injection stub for testing retry logic against SAP:

{
  "request": {
    "method": "GET",
    "urlPathPattern": "/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner.*"
  },
  "response": {
    "fault": "CONNECTION_RESET_BY_PEER"
  }
}

WireMock supports four fault types: EMPTY_RESPONSE, MALFORMED_RESPONSE_CHUNK, RANDOM_DATA_THEN_CLOSE, and CONNECTION_RESET_BY_PEER. It also supports fixed delays, random delays (lognormal and uniform distributions), and chunked dribble delays for testing timeout behavior. MockLayer has no option to return SAP error responses, delays, or connection faults. If your code needs to handle a 503 from SAP or a connection reset during a network timeout, WireMock is the tool.

Request verification. WireMock records every request in an in-memory journal. You can verify that specific endpoints were called with specific parameters, headers, and request bodies:

verify(exactly(1), getRequestedFor(
    urlPathEqualTo("/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner"))
    .withQueryParam("$top", equalTo("5"))
    .withHeader("Accept", containing("application/json")));

This catches bugs where your code sends requests to wrong paths, omits query parameters, or sends incorrect headers. MockLayer has no request journal or verification API.

Stateful sequences. WireMock scenarios let you simulate state transitions across requests. A POST-then-GET sequence where the created resource becomes queryable:

{
  "scenarioName": "CreateBusinessPartner",
  "requiredScenarioState": "Started",
  "newScenarioState": "PartnerCreated",
  "request": {
    "method": "POST",
    "urlPath": "/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner"
  },
  "response": {
    "status": 201,
    "bodyFileName": "created-partner.json"
  }
}

MockLayer is stateless by design. Each request generates fresh data. POST followed by GET will not return the same entity.

Non-OData endpoints. If your application calls SAP REST APIs, function imports, or third-party services alongside standard OData entity sets, WireMock handles all of them. MockLayer only handles SAP OData paths (/sap/opu/odata/ and /sap/opu/odata4/).

Specific response values. If a test needs a specific business partner with exact field values across multiple properties, WireMock gives full control over every byte. MockLayer respects $filter constraints — $filter=BusinessPartnerCategory eq '2' produces entities with that exact value — but you cannot control fields outside the filter expression.

Where MockLayer Wins

MockLayer does things WireMock does not do out of the box:

EDMX-driven generation. Give it a service's EDMX and it generates responses for every entity set in the service — including entity sets you haven't written stubs for. One EDMX file covers all 65 entity types in API_BUSINESS_PARTNER. For the full pipeline setup (GitHub Actions YAML, test code in four languages), see our CI/CD guide.

OData response format built in. V2 and V4 envelopes, __metadata objects, /Date(...)/ encoding, $inlinecount — generated, not hand-coded.

Multi-level $expand. $expand=to_BusinessPartnerAddress/to_EmailAddress resolves two levels of navigation properties — entities nested within entities, built from the target entity types in the EDMX. In WireMock, this requires deeply nested JSON that you author or record.

Schema sync from EDMX. Three-tier caching (memory, disk, SAP source) with configurable TTL. With SAP access, schema changes arrive on the next refresh; offline, you upload one new EDMX file.

CSRF token handling. The x-csrf-token: fetch handshake works out of the box.

Filter-aware generation. $filter=BusinessPartnerCategory eq '2' produces entities where that property contains exactly '2'. Supported operators: eq, ne, gt, ge, lt, le, startswith, endswith, contains, and or (picks from provided values). Unconstrained properties are generated from the schema with property-name heuristics — fields named *Email* get email addresses, *PostalCode* gets postal codes, decimals named *Price* or *Amount* get monetary amounts.

MockLayer's responses differ from SAP's in some details, such as __metadata.type naming, navigation properties you do not expand, and the JSON type of decimals. The CI/CD guide lists them under "What This Doesn't Solve".

Comparison

WireMockMockLayer
TypeGeneral HTTP mockSAP OData mock
EDMX awarenessNoneParses and generates from EDMX
OData envelopeHand-coded or recordedGenerated (V2 and V4)
$expandSeparate stub per combinationMulti-level, from EDMX associations
CSRF tokensManual stub implementationBuilt-in
Error simulationYes (status codes, delays, faults)No
Request verificationYes (call count, body, params)No
Stateful scenariosYesNo (stateless by design)
Specific response valuesFull controlGenerated from EDMX types; $filter values honored
Non-OData endpointsYesNo
CI/CD friendlyYes (Docker, standalone JAR)Yes (standalone binary)
LicenseOpen source (Apache 2.0)Commercial; one key per running instance
Language supportAny (HTTP)Any (HTTP)

When to Use Which

Use WireMock when:

  • You need to test error handling and retry logic against SAP failures
  • Your tests require specific, deterministic data values across multiple properties
  • You're mocking non-OData SAP endpoints alongside OData
  • You need to verify that specific requests were sent with correct parameters
  • You already have a WireMock infrastructure and only mock 2-3 SAP entity types

Use MockLayer when:

  • You integrate with SAP services that have many entity types
  • Your tests exercise $expand, $filter, $top, and other OData query options
  • Schema changes from SAP support packages are a recurring maintenance burden
  • You want CI/CD tests that run without stub file maintenance
  • Your team works in .NET, Java, Python, or Node.js (not UI5)

Use both when:

  • MockLayer handles the happy-path OData contract testing — "does my code correctly deserialize what SAP sends back?"
  • WireMock handles error paths — "does my code survive a 503, a timeout, or a connection reset from SAP?"
  • MockLayer covers the 65 entity types in API_BUSINESS_PARTNER with zero stub files; WireMock covers the three error scenarios that need specific fault injection

They serve different purposes. The overlap is the happy-path OData mocking, and that's where the EDMX-driven approach eliminates stub file maintenance.

What About Other SAP Mock Options?

Three SAP tools address OData mocking. Each was built for an SAP development workflow, not as a language-neutral mock server for non-SAP backends.

The UI5 MockServer (sap.ui.core.util.MockServer, part of SAPUI5 and OpenUI5) is a client-side mock that intercepts XMLHttpRequest calls in the browser via Sinon.js. It reads EDMX and serves OData V2 data, from JSON files or generated — but only inside the UI5 runtime. It cannot serve HTTP responses to a .NET, Java, or Python backend. OData V4 support was explicitly declined: an OpenUI5 maintainer stated that OpenUI5 "will not provide an additional mockserver implementation for OData V4" and closed the feature request with a pointer to the SAP Fiori mockserver.

The SAP Fiori mockserver (@sap-ux/fe-mockserver-core) is a Node.js middleware built for SAP Fiori elements development. It reads a local metadata file and serves OData V2 or V4 mock data from files in a folder, or generates it (generateMockData). It is normally used through @sap-ux/ui5-middleware-fe-mockserver, a UI5 Tooling middleware. The core package's README says it is "not meant to be consumed directly", although it can run inside a standard Express or http.Router application.

SAP CAP (capire: inner-loop development) mocks imported remote services. cds import converts the service's EDMX into a CDS model. CAP then mocks the service in-process (cds watch), or runs it as a separate OData V4 service (cds mock). Mock data comes from CSV files loaded into an in-memory database. This requires a CAP project, the cds command-line tools (an npm package), and the Node.js or Java CAP runtime.

All three were built for SAP's own workflows (UI5, Fiori elements, CAP). A backend team outside that ecosystem can run the Fiori mockserver or a CAP mock, but only by adding a Node.js toolchain and SAP-specific project configuration.

For a comparison of five general mocking approaches, see How to Mock SAP OData Services in Your CI/CD Pipeline. For MockLayer's current limitations (stateless design, no $batch, response details that differ from SAP), that post covers them in the "What This Doesn't Solve" section.


MockLayer is a standalone binary for Windows, Linux, and macOS. If your team uses WireMock today and spends time maintaining SAP OData stubs, a free 5-day trial lets you test the EDMX-driven approach against your own metadata.

Documentation | Pricing

WireMock is a trademark of its respective owner. MockLayer is an independent product, not affiliated with, sponsored or endorsed by the WireMock project. SAP trademarks: see the notice at the bottom of the page.