Show TOC

Mock Server: Frequently Asked QuestionsLocate this document in the navigation structure

List of FAQs

#1: Is the mock server a real server?

No. The mock server runs on the client and only uses the server terminology of 'start' and 'stop'. It does not require a network connection since there is no actual server involved.

#2: What require() is needed?

The mock server needs the following require statement:"sap.ui.core.util.MockServer"); 
#3: Can we use one mock server instance to mock multiple OData services?

No. Each OData service needs its own mock server. Create one MockServer instance per service.

#4: How to obtain metadata xml?

Call the metadata of the service in a browser and save it into a file.

#5: How to obtain mock data? What options do I have for mock data?

You can let the mock server generate random mock data automatically based on services metadata. For this, provide only the path to the metadata file and omit the second parameter of the simulate function as follows:

// url to the service metadata document 
        var sMetadataUrl = "testdata/rmtsampleflight/metadata.xml"; 

You can provide your own mock data in .json files, which can either be created manually or saved from an OData service response. Mock data in JSON format can be generated from an OData service by adding the $format=json parameter to the URL. Save the browser response which is called <entity type name>.json, for example Flight.json and put it into the model folder. Add the path to the simulate function:

// url to the service metadata document 
        var sMetadataUrl = "testdata/rmtsampleflight/metadata.xml";
        // base url which contains the mockdata
        var sMockdataBaseUrl = "testdata/rmtsampleflight/";
        oMockServer.simulate(sMetadataUrl, sMockdataBaseUrl);

You can specify a path to .json mock data and let the mock server generate data for the rest of the service entities:

var sMetadataUrl = "testdata/rmtsampleflight/metadata.xml"// url to the service metadata document
        var sMockdataBaseUrl = "testdata/rmtsampleflight/"// base url which contains the mockdata
            oMockServer.simulate(sMetadataUrl, {
                'sMockdataBaseUrl' : sMockdataBaseUrl,
                'bGenerateMissingMockData' : true
#6: I'm using the OData model and I get the following error in the console: The following problem occurred: no handler for data

The OData model uses JSON to fetch the data:

var oModel = new sap.ui.model.odata.ODataModel(sUri, true);
#7: What do I put in the rootUri?

Verify that you use the exact same URI prefix in the request as in the rootUri you define for the mock server. If a root URI is set, all request path URIs are prefixed with this root URI. The root URI has to be relative and requires a trailing '/'. It also needs to match the URI set in OData/JSON models or simple XHR calls in order for the mock server to intercept them.

The code snippet shows an example:

var sUri = "/mock/";
var oMockServer = new sap.ui.core.util.MockServer({
    rootUri : sUri
var oModel = new sap.ui.model.odata.ODataModel(sUri, true);
#8: Can the mock server be used for more than for OData service simulation?

Yes. The mock server can be used to help you fake server response on any given API and stub all AJAX access to resources such as OData service, metadata, annotation files (XML), other JSON or *.properties files.

#9: Is OData navigation supported?

The mock server supports navigation via association also if no referential constraint is defined. However,the result of the navigation is the entire collection of the navigation, or the first entry of the collection according to the association multiplicity. So, if you wantor needs the navigation to return "correct" results according to keys, define a respective referential constraint.


Due to a limitation of the mock server, you can not use the same association to describe a two-way navigation. If the navigation shall work for both directions, you need to define an appropriate association for each direction.

#10: How can I use the mock server in a QUnit?

You can set up the mock server in the setup function; example:

var _oMockServer = undefined;
        module("OData data provider", {
            setup : function() {
                this._oMockServer = new{ rootUri: "/model/"});
            teardown : function() {