sap.ui.core.util.MockServer.extend(sClassName, oClassInfo?, FNMetaImpl?): function
Creates a new subclass of class sap.ui.core.util.MockServer with name
sClassName
and enriches it with the information contained in
oClassInfo
.
oClassInfo
might contain the same kind of information as described in sap.ui.base.ManagedObject.extend.
Parameters:
{string} | sClassName | Name of the class being created |
{object} | oClassInfo? | Object literal with information about the class |
{function} | FNMetaImpl? | Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata |
Returns:
{function} | Created class / constructor function |
Returns a metadata object for class sap.ui.core.util.MockServer.
Returns:
attachAfter(event, fnCallback, sEntitySet)
Attaches an event handler to be called after the built-in request processing of the mock server
Parameters:
{string} | event | type according to HTTP Method |
{function} | fnCallback | the name of the function that will be called at this exit The callback function exposes an event with parameters, depending on the type of the request. oEvent.getParameters() lists the parameters as per the request. Examples are: oXhr : the request object; oFilteredData : the mock data entries that are about to be returned in the response; oEntry : the mock data entry that is about to be returned in the response; |
{string} | sEntitySet | (optional) the name of the entity set |
attachBefore(event, fnCallback, sEntitySet)
Attaches an event handler to be called before the built-in request processing of the mock server
Parameters:
{string} | event | type according to HTTP Method |
{function} | fnCallback | the name of the function that will be called at this exit. The callback function exposes an event with parameters, depending on the type of the request. oEvent.getParameters() lists the parameters as per the request. Examples are: oXhr : the request object; sUrlParams : the URL parameters of the request; sKeys : key properties of the requested entry; sNavProp/sNavName : name of navigation |
{string} | sEntitySet | (optional) the name of the entity set |
destroy(bSuppressInvalidate?)
Cleans up the resources associated with this object and all its aggregated children.
After an object has been destroyed, it can no longer be used in!
Applications should call this method if they don't need the object any longer.
Parameters:
{boolean} | bSuppressInvalidate? | if true, this ManagedObject is not marked as changed |
See:
detachAfter(event, fnCallback, sEntitySet)
Removes a previously attached event handler
Parameters:
{string} | event | type according to HTTP Method |
{function} | fnCallback | the name of the function that will be called at this exit |
{string} | sEntitySet | (optional) the name of the entity set |
detachBefore(event, fnCallback, sEntitySet)
Removes a previously attached event handler
Parameters:
{string} | event | type according to HTTP Method |
{function} | fnCallback | the name of the function that will be called at this exit |
{string} | sEntitySet | (optional) the name of the entity set |
getEntitySetData(sEntitySetName): array
Returns the data model of the given EntitySet name.
Parameters:
| sEntitySetName | EntitySet name |
Returns:
{array} | data model of the given EntitySet |
getRequests(): object[]
Getter for property
requests
.
Default value is []
Returns:
{object[]} | the value of property rootUri |
getRootUri(): string
Getter for property
rootUri
.
Default value is empty/undefined
Returns:
{string} | the value of property rootUri |
isStarted(): boolean
Returns whether the server is started or not.
Returns:
{boolean} | whether the server is started or not. |
setEntitySetData(sEntitySetName, aData)
Sets the data of the given EntitySet name with the given array.
Parameters:
| sEntitySetName | EntitySet name |
| aData | |
setRequests(requests)
Setter for property
requests
.
Default value is is []
Each array entry should consist of an array with the following properties / values:
- method : "GET"|"POST"|"DELETE|"PUT"
(any HTTP verb) - path : "/path/to/resource"
The path is converted to a regular expression, so it can contain normal regular expression syntax. All regular expression groups are forwarded as arguments to the response
function. In addition to this, parameters can be written in this notation: :param
. These placeholder will be replaced by regular expression groups. - response : function(xhr, param1, param2, ...) { }
The xhr object can be used to respond on the request. Supported methods are:
xhr.respond(iStatusCode, mHeaders, sBody)
xhr.respondJSON(iStatusCode, mHeaders, oJsonObjectOrString)
. By default a JSON header is set for response header
xhr.respondXML(iStatusCode, mHeaders, sXmlString)
. By default a XML header is set for response header
xhr.respondFile(iStatusCode, mHeaders, sFileUrl)
. By default the mime type of the file is set for response header
Parameters:
{object[]} | requests | new value for property requests |
setRootUri(rootUri)
Setter for property
rootUri
. All request path URI are prefixed with this root URI if set.
Default value is empty/undefined
Parameters:
{string} | rootUri | new value for property rootUri |
simulate(sMetadataUrl, vMockdataSettings?)
Simulates an existing OData service by sepcifiying the metadata URL and the base URL for the mockdata. The server configures the request handlers depending on the service metadata. The mockdata needs to be stored individually for each entity type in a separate JSON file. The name of the JSON file needs to match the name of the entity type. If no base url for the mockdata is specified then the mockdata are generated from the metadata
Parameters:
{string} | sMetadataUrl | url to the service metadata document |
{string|object} | vMockdataSettings? | (optional) base url which contains the path to the mockdata, or an object which contains the following properties: sMockdataBaseUrl, bGenerateMissingMockData, aEntitySetsNames. See below for descriptions of these parameters. Ommit this parameter to produce random mock data based on the service metadata. |
{string} | vMockdataSettings.sMockdataBaseUrl? | base url which contains the mockdata as single .json files or the .json file containing the complete mock data |
{boolean} | vMockdataSettings.bGenerateMissingMockData? | true for the MockServer to generate mock data for missing .json files that are not found in sMockdataBaseUrl. Default value is false. |
{array} | vMockdataSettings.aEntitySetsNames? | list of entity set names to fetch. This parameter should be used to improve performance in case there are a lot of entity sets but only a few are needed to be fetched. Default value is empty - in this case all entity sets will be retrieved. |
- Since:
- 1.13.2
start()
Starts the server.