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.
#!jsjQuery.sap.require("sap.ui.core.util.MockServer");
No. Each OData service needs its own mock server. Create one MockServer instance per service.
Call the metadata of the service in a browser and save it into a file.
#!js// url to the service metadata document var sMetadataUrl = "testdata/rmtsampleflight/metadata.xml"; oMockServer.simulate(sMetadataUrl);
#!js// 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);
#!jsvar 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 });
#!jsvar 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, 'aEntitySetsNames' : ["EntitySetName1", " EntitySetName2"] });
#!jsvar oModel = new sap.ui.model.odata.ODataModel(sUri, true);
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.
#!jsvar sUri = "/mock/"; var oMockServer = new sap.ui.core.util.MockServer({ rootUri : sUri }); var oModel = new sap.ui.model.odata.ODataModel(sUri, true);
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.
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.
#!jsvar _oMockServer = undefined; module("OData data provider", { setup : function() { jQuery.sap.require("sap.ui.app.MockServer"); this._oMockServer = new sap.ui.app.MockServer({ rootUri: "/model/"}); this._oMockServer.simulate("../../../../qunit/service/metadata.xml"); this._oMockServer.start(); }, teardown : function() { this._oMockServer.stop(); } });
Mock Server has APIs to provide more flexibility and control over its current request processing. During request processing, the callbacks are called before or after native handling of the Mock Server using the SAPUI5 eventing mechanism. You can add a callback in all requests of a specific HTTP method, for example in all get requests, but additionally also on a specific entity set name, for example, POST to SaleOrders).
#!js// add a callback in all requests of a specific http method oMockServer.attachAfter(sap.ui.core.util.MockServer.HTTPMETHOD.GET, fnCbPost);
#!js// on a specific entityset name oMockServer.attachAfter(sap.ui.core.util.MockServer.HTTPMETHOD.GET, fnCbPost, "CarrierCollection");
#!js// remove the callback oMockServer.detachAfter(sap.ui.core.util.MockServer.HTTPMETHOD.GET, fnCbPost);
#!jsthis.fireEvent(sap.ui.core.util.MockServer.HTTPMETHOD.GET + 'sEntityset' + ':before' , {oXhr: oXhr, sUrlParameters: sUrlParameters});
Start you app in mock mode. It is not possible to declare a mock server outside the app's context.