Professional Documents
Culture Documents
Mockserver
Mockserver
define([
"sap/ui/core/util/MockServer",
"sap/ui/model/json/JSONModel",
"sap/base/util/UriParameters",
"sap/base/Log"
], function (MockServer, JSONModel, UriParameters, Log) {
"use strict";
// var oMockServer,
// _sAppPath = "project/",
// _sJsonFilesPath = _sAppPath + "localService/mockdata";
// var oMockServerInterface = {
var _sAppPath = "sap/ui/demo/nav/",
_sJsonFilesPath = _sAppPath + "localService/mockdata";
return {
/**
* Initializes the mock server asynchronously.
* You can configure the delay with the URL parameter "serverDelay".
* The local mock data in this folder is returned instead of the real data
for testing.
* @protected
* @param {object} [oOptionsParameter] init parameters for the mockserver
* @returns{Promise} a promise that is resolved when the mock server has
been started
*/
// init: function (oOptionsParameter) {
// var oOptions = oOptionsParameter || {};
init: function () {
oManifestModel.attachRequestCompleted(function () {
var oUriParameters = new UriParameters(window.location.href),
// parse manifest for local metatadata URI
sJsonFilesUrl = sap.ui.require.toUrl(_sJsonFilesPath),
oMainDataSource =
oManifestModel.getProperty("/sap.app/dataSources/mainService"),
sMetadataUrl = sap.ui.require.toUrl(_sAppPath +
oMainDataSource.settings.localUri),
// ensure there is a trailing slash
sMockServerUrl = oMainDataSource.uri && new
URI(oMainDataSource.uri).absoluteTo(sap.ui.require.toUrl(_sAppPath)).toString();
oManifestModel.attachRequestFailed(function () {
var sError = "Failed to load application manifest";
Log.error(sError);
fnReject(new Error(sError));
});
});
},
/**
* @public returns the mockserver of the app, should be used in integration
tests
* @returns {sap.ui.core.util.MockServer} the mockserver instance
*/
getMockServer: function () {
return oMockServer;
}
};
return oMockServerInterface;
});