generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
2,054 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Error Handling Sample | ||
|
||
In this sample we just load a simple metadata file that the mockserver will leverage alongside with static mock data defined in json files | ||
|
||
The mock data file must be named with the same name as the EntitySet you're mocking. | ||
|
||
|
||
|
||
- [metadata file](./webapp/localService/metadata.xml) | ||
- [RootEntity file](./webapp/localService/mockdata/RootEntity.js) | ||
|
||
The RootEntity file implements the executeAction method now, meaning that it will be called when you define a custom action. | ||
It also throw an error for a specific object with key ID === 1 | ||
|
||
## Used / Implemented API function | ||
|
||
- [getInitialDataset](../../docs/MockserverAPI.md#getInitialDataset) | ||
- [executeAction](../../docs/MockserverAPI.md#executeAction) | ||
- [throwError](../../docs/MockserverAPI.md#throwError) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "error-handling", | ||
"version": "0.0.1", | ||
"private": true, | ||
"description": "Error handling sample for the mockserver", | ||
"main": "webapp/index.html", | ||
"scripts": { | ||
"start": "ui5 serve --open 'index.html#errorHandling-tile'", | ||
"start:100": "ui5 serve --open 'index.html?sap-client=100#errorHandling-tile'", | ||
"start:200": "ui5 serve --open 'index.html?sap-client=200#errorHandling-tile'" | ||
}, | ||
"devDependencies": { | ||
"@sap-ux/ui5-middleware-fe-mockserver": "workspace:*", | ||
"@sap/ux-ui5-tooling": "1.15.0", | ||
"@ui5/cli": "3.11.1", | ||
"rimraf": "3.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
specVersion: '2.4' | ||
metadata: | ||
name: 'basic-usage' | ||
type: application | ||
server: | ||
customMiddleware: | ||
- name: sap-fe-mockserver | ||
beforeMiddleware: compression | ||
configuration: | ||
service: | ||
urlBasePath: /here/goes/your/serviceurl | ||
name: '' | ||
metadataXmlPath: ./webapp/localService/metadata.xml | ||
mockdataRootPath: ./webapp/localService/mockdata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
sap.ui.define(['sap/fe/core/AppComponent'], function (AppComponent) { | ||
'use strict'; | ||
|
||
return AppComponent.extend('sap.fe.mockserver.errorHandling.errorHandling.Component', { | ||
metadata: { | ||
manifest: 'json' | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0"> | ||
<edmx:Reference Uri="https://sap.github.io/odata-vocabularies/vocabularies/Common.xml"> | ||
<edmx:Include Namespace="com.sap.vocabularies.Common.v1" Alias="Common"/> | ||
</edmx:Reference> | ||
<edmx:Reference Uri="https://sap.github.io/odata-vocabularies/vocabularies/UI.xml"> | ||
<edmx:Include Namespace="com.sap.vocabularies.UI.v1" Alias="UI"/> | ||
</edmx:Reference> | ||
<edmx:Reference Uri="https://sap.github.io/odata-vocabularies/vocabularies/Communication.xml"> | ||
<edmx:Include Namespace="com.sap.vocabularies.Communication.v1" Alias="Communication"/> | ||
</edmx:Reference> | ||
<edmx:Reference Uri="/here/goes/your/serviceurl/$metadata"> | ||
<edmx:Include Namespace="sap.fe.test.TestService"/> | ||
</edmx:Reference> | ||
<edmx:DataServices> | ||
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="sap.fe.mockserver.basicUsage"> | ||
</Schema> | ||
</edmx:DataServices> | ||
</edmx:Edmx> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<!-- Copyright (c) 2015 SAP AG, All Rights Reserved --> | ||
<head> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>{{appTitle}}</title> | ||
|
||
<!-- Bootstrap the unified shell in sandbox mode for standalone usage. | ||
The renderer is specified in the global Unified Shell configuration object "sap-ushell-config". | ||
The fiori2 renderer will render the shell header allowing, for instance, | ||
testing of additional application setting buttons. | ||
The navigation target resolution service is configured in a way that the empty URL hash is | ||
resolved to our own application. | ||
This example uses relative path references for the SAPUI5 resources and test-resources; | ||
it might be necessary to adapt them depending on the target runtime platform. | ||
The sandbox platform is restricted to development or demo use cases and must NOT be used | ||
for productive scenarios. | ||
--> | ||
<script type="text/javascript"> | ||
window['sap-ushell-config'] = { | ||
defaultRenderer: 'fiori2', | ||
bootstrapPlugins: { | ||
RuntimeAuthoringPlugin: { | ||
component: 'sap.ushell.plugins.rta', | ||
config: { | ||
validateAppVersion: false | ||
} | ||
} | ||
}, | ||
renderers: { | ||
fiori2: { | ||
componentData: { | ||
config: { | ||
search: 'hidden' | ||
} | ||
} | ||
} | ||
}, | ||
applications: { | ||
'errorHandling-tile': { | ||
title: 'Basic Usage', | ||
description: '', | ||
additionalInformation: 'SAPUI5.Component=sap.fe.mockserver.errorHandling.errorHandling', | ||
applicationType: 'URL', | ||
url: './' | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<script | ||
src="https://ui5.sap.com/test-resources/sap/ushell/bootstrap/sandbox.js" | ||
id="sap-ushell-bootstrap"></script> | ||
<!-- Bootstrap the UI5 core library --> | ||
<script | ||
id="sap-ui-bootstrap" | ||
src="https://ui5.sap.com/resources/sap-ui-core.js" | ||
data-sap-ui-libs="sap.m, sap.ushell, sap.fe.templates" | ||
data-sap-ui-async="true" | ||
data-sap-ui-preload="async" | ||
data-sap-ui-theme="sap_fiori_3" | ||
data-sap-ui-compatVersion="edge" | ||
data-sap-ui-language="en" | ||
data-sap-ui-resourceroots='{"sap.fe.mockserver.errorHandling.errorHandling": "./"}' | ||
data-sap-ui-frameOptions="allow"> | ||
// NON-SECURE setting for testing environment | ||
</script> | ||
<script type="text/javascript"> | ||
sap.ui.getCore().attachInit(function () { | ||
// initialize the ushell sandbox component | ||
sap.ushell.Container.createRenderer().placeAt('content'); | ||
}); | ||
</script> | ||
</head> | ||
|
||
<!-- UI Content --> | ||
|
||
<body class="sapUiBody" id="content"></body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
module.exports = { | ||
/** | ||
* This function returns the initial dataset for the WorkstationSet entity. | ||
* It reads the content from the corresponding JSON file and returns it as an array of objects. | ||
* @param {string} contextId - Represents the tenant id for the current request (optional). | ||
* @param {string} fileName - The name of the file to load with full path. | ||
* @param {string} currentDir - The current directory of the file. | ||
* @returns {Array} - The initial dataset for the WorkstationSet entity. | ||
*/ | ||
getInitialDataSet: function (contextId, fileName, currentDir) { | ||
let filePath = ''; | ||
|
||
// Extract the base file name without extension | ||
const baseFileName = path.basename(fileName, path.extname(fileName)).replace(/\.js$/, ''); | ||
|
||
// Construct the file name based on contextId | ||
const fileNameSuffix = contextId === 'tenant-default' ? '' : `-${contextId.replace('tenant-', '')}`; | ||
const jsonFileName = `${baseFileName}${fileNameSuffix}.json`; | ||
|
||
// Construct the full file path (from current directory) | ||
filePath = path.join(currentDir, jsonFileName); | ||
|
||
// Check if the file exists | ||
if (!fs.existsSync(filePath)) { | ||
console.warn(`File not found: ${filePath}`); | ||
// try loading default file | ||
filePath = path.join(currentDir, `${baseFileName}.json`); | ||
if (!fs.existsSync(filePath)) { | ||
console.warn(`File not found: ${filePath}`); | ||
return []; | ||
} | ||
} | ||
|
||
// Read and parse the JSON file | ||
const data = JSON.parse(fs.readFileSync(filePath, 'utf8')); | ||
|
||
return data; | ||
} | ||
}; |
Oops, something went wrong.