Skip to content

Commit

Permalink
Merge pull request #59 from ligangty/2.0-refactor
Browse files Browse the repository at this point in the history
Add mock server for testing and debugging
  • Loading branch information
ligangty authored Nov 6, 2023
2 parents c733280 + 2f8b96f commit 3423eb1
Show file tree
Hide file tree
Showing 11 changed files with 498 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/webui/nodemon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"watch": ["src/server/"]
}
1 change: 1 addition & 0 deletions src/main/webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"dev": "webpack-dev-server --open --hot",
"lint": "eslint './src/**'",
"lint-fix": "eslint './src/**' --fix",
"server": "npm run build && nodemon src/server/app.js --exec babel-node --presets @babel/preset-env",
"test": "NODE_ENV=test jest"
}
}
18 changes: 18 additions & 0 deletions src/main/webui/src/server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# UI Mock Server

This mock server is used for frontend testing. It is served as a mock backend to provide mock data for frontend component data fetching

## How to run

Use

```bash
npm run server
```

to start the server

## How to add your mocking data

1. Add your mock data in mock folder, for example: [mock/list/FakeRemoteList.json](mock/list/FakeRemoteList.json) is for the remote listing mock data
2. Add code to provide your mock data through express server code with correct http providers. For details, please check the [app.js](app.js) for details.
100 changes: 100 additions & 0 deletions src/main/webui/src/server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import compression from 'compression';
import express from 'express';
import path from 'path';
import {Config} from './config/AppConfig';

const projectRoot = path.resolve(__dirname, '../../dist');
const indexHtml=path.join(projectRoot+'/index.html');

const app = express();
app.use(compression());
const server = app.listen(Config.SERVER_PORT, () => {
const host = server.address().address;
const port = server.address().port;

console.log("Example app listening at http://%s:%s", host, port);
});
app.use(express.static('dist'));

// For direct url bar addressing, will send home page directly for client router rendering
app.get([Config.APP_ROOT, `${Config.APP_ROOT}/*`, '/'], (req, res) => {
res.sendFile(indexHtml);
});

app.get('/api/admin/stores/_all/remote', (req, res) => {
const remoteList = require('./mock/list/FakeRemoteList.json');
res.status(200).json(remoteList);
});

app.get('/api/admin/stores/_all/hosted', (req, res) => {
const hostedList = require('./mock/list/FakeHostedList.json');
res.status(200).json(hostedList);
});

app.get('/api/admin/stores/_all/group', (req, res) => {
const groupList = require('./mock/list/FakeGroupList.json');
res.status(200).json(groupList);
});

app.get('/api/admin/schedule/store/all/disable-timeout', (req, res) => {
const disableTimeouts = require('./mock/FakeDisableTimeouts.json');
res.status(200).json(disableTimeouts);
});

app.get('/api/admin/schedule/store/:packageType/:type/:name/disable-timeout', (req, res) => {
const group = `${req.params.packageType}:${req.params.type}:${req.params.name}`;
if(group && group.length > 0){
const disList = require('./mock/FakeDisableTimeouts.json');
const result = disList.items.find(item=>item.group.includes(group));
if(result){
res.status(200).json(result);
}else{
res.status(404).json({error: "No such store!"});
}
}
});

app.get('/api/admin/stores/maven/remote/:name', (req, res) => {
const name = req.params.name;
if(name){
const remoteList = require('./mock/list/FakeRemoteList.json');
const result = remoteList.items.find(item=>item.name===name);
if(result){
res.status(200).json(result);
}else{
res.status(404).json({error: "No such store!"});
}
}else{
res.status(400).json({error: "Missing store name"});
}
});

app.get('/api/admin/stores/maven/hosted/:name', (req, res) => {
const name=req.params.name;
if(name){
const remoteList = require('./mock/list/FakeHostedList.json');
const result = remoteList.items.find(item=>item.name===name);
if(result){
res.status(200).json(result);
}else{
res.status(404).json({error: "No such store!"});
}
}else{
res.status(400).json({error: "Missing store name"});
}
});

app.get('/api/admin/stores/maven/group/:name', (req, res) => {
const name=req.params.name;
if(name){
const remoteList = require('./mock/list/FakeGroupList.json');
const result = remoteList.items.find(item=>item.name===name);
if(result){
res.status(200).json(result);
}else{
res.status(404).json({error: "No such store!"});
}
}else{
res.status(400).json({error: "Missing store name"});
}
});
5 changes: 5 additions & 0 deletions src/main/webui/src/server/config/AppConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const Config = {
SERVER_PORT: 4000,
APP_ROOT: "/#"
};

25 changes: 25 additions & 0 deletions src/main/webui/src/server/mock/FakeDisableTimeouts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"items" : [
{
"name" : "Disable-Timeout",
"group" : "maven:remote:koji-org.jboss.ws-jbossws-common-tools-1.2.4.Final_redhat_1-1",
"expiration": "1541577250077"
},
{
"name" : "Disable-Timeout",
"group" : "maven:remote:i-maven-restlet-4"
},
{
"name" : "Disable-Timeout",
"group" : "maven:hosted:FisZYfNgpR"
},
{
"name" : "Disable-Timeout",
"group" : "maven:group:build_org-keycloak-keycloak-parent-4-x_20180515.1724"
},
{
"name" : "Disable-Timeout",
"group" : "maven:group:build_org-keycloak-keycloak-parent-4-x_20180531.0218"
}
]
}
83 changes: 83 additions & 0 deletions src/main/webui/src/server/mock/list/FakeGroupList.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"items" : [
{
"type" : "group",
"key" : "maven:group:build_org-keycloak-keycloak-parent-4-x_20180515.1724",
"description" : "Aggregation group for PNC build #1859",
"metadata" : {
"changelog" : "Creating repository group for resolving artifacts in build: 1859 (repo: build_org-keycloak-keycloak-parent-4-x_20180515.1724)"
},
"disabled" : false,
"constituents" : [ "maven:hosted:FisZYfNgpR", "maven:remote:koji-org.jboss.ws-jbossws-common-tools-1.2.4.Final_redhat_1-1", "maven:group:build_vertx-infinispan-3-5-1_20180705.1313"],
"packageType" : "maven",
"name" : "build_org-keycloak-keycloak-parent-4-x_20180515.1724",
"disable_timeout" : 0,
"path_style" : "plain",
"authoritative_index" : false,
"prepend_constituent" : false
},
{
"type" : "group",
"key" : "maven:group:build_org-keycloak-keycloak-parent-4-x_20180531.0218",
"description" : "Aggregation group for PNC build #1981",
"metadata" : {
"changelog" : "Creating repository group for resolving artifacts in build: 1981 (repo: build_org-keycloak-keycloak-parent-4-x_20180531.0218)"
},
"disabled" : false,
"constituents" : [ "maven:hosted:tYMtROxQUA", "maven:remote:i-maven-restlet-4"],
"packageType" : "maven",
"name" : "build_org-keycloak-keycloak-parent-4-x_20180531.0218",
"disable_timeout" : 0,
"path_style" : "plain",
"authoritative_index" : false,
"prepend_constituent" : false
},
{
"type" : "group",
"key" : "maven:group:build_org-keycloak-keycloak-nodejs-auth-utils-3-xnpm_1-2-stage-4_20180104.1216",
"description" : "Aggregation group for PNC build #333",
"metadata" : {
"changelog" : "Creating repository group for resolving artifacts in build: 333 (repo: build_org-keycloak-keycloak-nodejs-auth-utils-3-xnpm_1-2-stage-4_20180104.1216)"
},
"disabled" : false,
"constituents" : [ "maven:hosted:LYnrVCMAZP", "maven:group:public", "maven:remote:repo.eclipse.org", "maven:remote:microprofile.repo.eclipse.org" ],
"packageType" : "maven",
"name" : "build_org-keycloak-keycloak-nodejs-auth-utils-3-xnpm_1-2-stage-4_20180104.1216",
"disable_timeout" : 0,
"path_style" : "plain",
"authoritative_index" : false,
"prepend_constituent" : false
},
{
"type" : "group",
"key" : "maven:group:build_vertx-infinispan-3-5-1_20180705.1313",
"description" : "Aggregation group for PNC build #2759",
"metadata" : {
"changelog" : "Creating repository group for resolving artifacts in build: 2759 (repo: build_vertx-infinispan-3-5-1_20180705.1313)"
},
"disabled" : false,
"constituents" : [ "maven:hosted:build_kie-soup_20180628.0657", "maven:group:public" ],
"packageType" : "maven",
"name" : "build_vertx-infinispan-3-5-1_20180705.1313",
"disable_timeout" : 0,
"path_style" : "plain",
"authoritative_index" : false,
"prepend_constituent" : false
},
{
"type" : "group",
"key" : "maven:group:public",
"metadata" : {
"changelog" : "test"
},
"disabled" : false,
"constituents" : [ "maven:remote:central", "maven:remote:mrrc-ga", "maven:remote:repo.eclipse.org", "maven:remote:microprofile.repo.eclipse.org" ],
"packageType" : "maven",
"name" : "public",
"disable_timeout" : 0,
"path_style" : "plain",
"authoritative_index" : false,
"prepend_constituent" : false
}
]
}
76 changes: 76 additions & 0 deletions src/main/webui/src/server/mock/list/FakeHostedList.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"items" : [
{
"type" : "hosted",
"key" : "maven:hosted:FisZYfNgpR",
"description" : "Build output for PNC build #48216536",
"metadata" : {
"changelog" : "Creating hosted repository for build: 48216536 (repo: FisZYfNgpR)"
},
"disabled" : false,
"snapshotTimeoutSeconds" : 0,
"readonly" : true,
"packageType" : "maven",
"name" : "FisZYfNgpR",
"disable_timeout" : 0,
"path_style" : "plain",
"authoritative_index" : true,
"allow_snapshots" : false,
"allow_releases" : true
},
{
"type" : "hosted",
"key" : "maven:hosted:tYMtROxQUA",
"description" : "Build output for PNC build #49682846",
"metadata" : {
"changelog" : "Creating hosted repository for build: 49682846 (repo: tYMtROxQUA)"
},
"disabled" : false,
"snapshotTimeoutSeconds" : 0,
"readonly" : false,
"packageType" : "maven",
"name" : "tYMtROxQUA",
"disable_timeout" : 0,
"path_style" : "plain",
"authoritative_index" : false,
"allow_snapshots" : false,
"allow_releases" : true
},
{
"type" : "hosted",
"key" : "maven:hosted:LYnrVCMAZP",
"description" : "Build output for PNC build #40419410",
"metadata" : {
"changelog" : "Creating hosted repository for build: 40419410 (repo: LYnrVCMAZP)"
},
"disabled" : false,
"snapshotTimeoutSeconds" : 0,
"readonly" : false,
"packageType" : "maven",
"name" : "LYnrVCMAZP",
"disable_timeout" : 0,
"path_style" : "plain",
"authoritative_index" : false,
"allow_snapshots" : false,
"allow_releases" : true
},
{
"type" : "hosted",
"key" : "maven:hosted:build_kie-soup_20180628.0657",
"description" : "Build output for PNC build #2601",
"metadata" : {
"changelog" : "Creating hosted repository for build: 2601 (repo: build_kie-soup_20180628.0657)"
},
"disabled" : false,
"snapshotTimeoutSeconds" : 0,
"readonly" : false,
"packageType" : "maven",
"name" : "build_kie-soup_20180628.0657",
"disable_timeout" : 0,
"path_style" : "plain",
"authoritative_index" : false,
"allow_snapshots" : false,
"allow_releases" : true
}
]
}
Loading

0 comments on commit 3423eb1

Please sign in to comment.