var oMockServer = new sap.ui.core.util.MockServer({ // full namespace access for better readability
rootUri: "/my/odata/SRV" // e.g. see manifest.json: sap.app.dataSources.mainService.uri
})
oMockServer.simulate("sap/ui/demo/todo/test/metadata.xml"); // local metadata.xml
oMockServer.start();
index.html, all OData-requests will then be intercepted and answered by the mockserver, causing no more network activity.sap.ui.getCore().attachInit(function() {
sap.ui.require([
"sap/ui/core/ComponentContainer",
"sap/ui/core/util/MockServer"
], function(ComponentContainer, MockServer) {
var oMockServer = new MockServer({
rootUri: "/my/odata/SRV"
})
oMockServer.simulate("/test/metadata.xml");
oMockServer.start();
new ComponentContainer({
name: "sap.ui.demo.todo",
settings: {
id: "todo"
},
manifest: true
}).placeAt("root");
});
});
sap-ui-mockserver as URL GET parameter, the mockserver can be activated (and switches the entire application to using an OData-based model).
sap.ui.core.util.MockServer is extended as sap.ui.demo.todo.test.MockServer and reads its' configuration from manifest.json directly.metadata.xml is expected in /webapp/test/metadata.xml.sap-ui-mockserver-debug=true enables verbose logging: for all HTTP access methods (GET, POST, PUT, DELETE, UPDATE), the request state is logged to console
sap-ui-mockserver-delay=<ms> instructs the mockserver to wait <ms> milliseconds before sending a response. Very useful to simulate network latency or slow backends!oMockServer.simulate(sMetadataUrl, {
bGenerateMissingMockData: true
})
oMockServer.simulate(sMetadataUrl, {
sMockdataBaseUrl: "./test/mockdata", // dir holding static data
bGenerateMissingMockData: true
})
<entityset>.json corresponding to the entity set name from metadata.xml,sMockdataBaseUrl directory:webapp/test/
└── mockdata
└── todos.json
JSON format[
{
"guid": "67e2793d-f4d4-4d79-9fc8-f753b80728ba",
"title": "Start this app with the mockserver",
"completed": true
},
{
"guid": "67e2793d-f4d4-4d79-9fc8-f753b80728bb",
"title": "Learn OpenUI5",
"completed": false
}
]

CRUD) on the static dataset!console:
Edm.DateTime keys in OData entities! Only possible workaround is to locally refactor them to be Edm.String 😞// in /webapp/test/integration/opaTests.qunit.html
if (oUriParameters.get("sap-ui-mockserver")) {
_global.mockserver = true;
_global.mockserverParameters = oUriParameters;
}
todo are written so that the entire application is started and stopped in every test, we need to do the same with the mockserver:// in every webapp/test/integration/*Journey.js
QUnit.module(<modulename>, {
beforeEach: function () {
if (_global.mockserver) {
this.oMockserver = MockServer.init(_global.mockserverParameters);
}
},
afterEach: function () {
if (this.oMockserver) {
this.oMockserver.shutdown();
}
}
});
*Journey.js, so detecting them in QUnit.module-beforeEach doesn't work.metadata.xml only!metadata.xml as a "contract" to both frontend- and backend-development? "Frontend" can use UI5's mockserver to simulate the backend, "Backend" knows what to implement based on the service design.metadata.xml-contract than having to go through a "Backend" development cycle.You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 33 | |
| 33 | |
| 30 | |
| 28 | |
| 26 | |
| 26 | |
| 20 | |
| 15 | |
| 11 | |
| 11 |