cancel
Showing results for 
Search instead for 
Did you mean: 

OpenUI5 Mockserver configuration

Former Member
0 Kudos

Hi,

Can anyone please explain how to config mock server in SAPUI5 and how to set rootUri.

What exactly rootUri pointing to?

Thanks.

Accepted Solutions (0)

Answers (1)

Answers (1)

hhllcks
Explorer
0 Kudos

The rootUri is an artificial URI you can choose how you like. The important thing is that you point your oData model to that URI once the mockserver is running.

I always use the URI of the real service on the gateway. That way I can use the same model in my code.

Let me give you an example:

// assuming that your real service has the URI /sap/opu/odata/sap/my_service
// DO NOT forget the trailing slash!
sServiceUri = "/sap/opu/odata/sap/my_service/"

// in your component.js you have to detect that you are running local (or any other condition for starting the mockserver)
if(location.hostname === "localhost" || location.hostname === "127.0.0.1"){
   mockserver.init(sServiceUri);
}

// in your mockserver.js you have to initialize the mockserver
this.oMockServer = new MockServer({
                rootUri: sServiceUri
}); 
MockServer.config({
   autoRespond: true,
   autoRespondAfter: 100
});
// get path to your metadata.xml and mockdata folder
var sPath = jQuery.sap.getModulePath("com.your.app.id.localService");

this.oMockServer.simulate(sPath + "/metadata.xml", sPath + "/mockdata/");
this.oMockServer.start();

// now you can create your model the same way you did it with a real service, e.g.
this._oModel = new sap.ui.model.odata.v2.ODataModel(sServiceUri);