Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 1 | /*- |
| 2 | * ============LICENSE_START======================================================= |
| 3 | * SDC |
| 4 | * ================================================================================ |
| 5 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 6 | * ================================================================================ |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | * ============LICENSE_END========================================================= |
| 19 | */ |
| 20 | |
| 21 | var args = process.argv.slice(2); |
| 22 | |
| 23 | function defineRoutes(router) { |
| 24 | |
| 25 | //LICENSE-MODELS |
| 26 | router.get('/v1.0/vendor-license-models', licenseModelsList); |
| 27 | |
| 28 | //FEATURE-GROUP |
| 29 | router.get('/v1.0/vendor-license-models/:licenseModelId/feature-groups', featureGroupList); |
| 30 | router.get('/v1.0/vendor-license-models/:licenseModelId/feature-groups/:featureGroupId', featureGroup); |
| 31 | router.post('/v1.0/vendor-license-models/:licenseModelId/feature-groups', addFeatureGroup); |
| 32 | router.delete('/v1.0/vendor-license-models/:licenseModelId/feature-groups/:featureGroupId', deletefeatureGroup); |
| 33 | router.put('/v1.0/vendor-license-models/:licenseModelId/feature-groups/:featureGroupId', updatefeatureGroup); |
| 34 | |
| 35 | |
| 36 | |
| 37 | //LICENSE-AGREEMENT |
| 38 | router.get('/v1.0/vendor-license-models/:licenseModelId/license-agreements', licenseAgreementList); |
| 39 | router.post('/v1.0/vendor-license-models/:licenseModelId/license-agreements/', addLicenseAgreement); |
| 40 | router.delete('/v1.0/vendor-license-models/:licenseModelId/license-agreements/:licenseAgreementId', deleteLicenseAgreement); |
| 41 | router.put('/v1.0/vendor-license-models/:licenseModelId/license-agreements/:licenseAgreementId', updateLicenseAgreement); |
| 42 | |
| 43 | //ENTITLEMENT POOLS |
| 44 | router.get('/v1.0/vendor-license-models/:licenseModelId/entitlement-pools', entitlementPoolsList); |
| 45 | router.post('/v1.0/vendor-license-models/:licenseModelId/entitlement-pools', addEntitlementPool); |
| 46 | router.put('/v1.0/vendor-license-models/:licenseModelId/entitlement-pools/:entitlementPoolId', updateEntitlementPool); |
| 47 | router.delete('/v1.0/vendor-license-models/:licenseModelId/entitlement-pools/:entitlementPoolId', deleteEntitlementPool); |
| 48 | |
| 49 | //LICENSE KEY GROUPS |
| 50 | router.get('/v1.0/vendor-license-models/:licenseModelId/license-key-groups', licenseKeyGroupsList); |
| 51 | router.post('/v1.0/vendor-license-models/:licenseModelId/license-key-groups', addLicenseKeyGroup); |
| 52 | router.delete('/v1.0/vendor-license-models/:licenseModelId/license-key-groups/:licenseKeyGroupId', deleteLicenseKeyGroup); |
| 53 | router.put('/v1.0/vendor-license-models/:licenseModelId/license-key-groups/:licenseKeyGroupId', updateLicenseKeyGroup); |
| 54 | |
| 55 | //VENDOR SOFTWARE PRODUCT |
| 56 | |
| 57 | router.post('/v1.0/vendor-software-products/:vspId/upload', softwareProductUpload); |
| 58 | router.get('/v1.0/vendor-software-products/:vspId', getSoftwareProduct); |
| 59 | router.get('/v1.0/vendor-software-products', softwareProductList); |
| 60 | |
| 61 | router.put('/v1.0/vendor-software-products/:vspId/processes/:prcId', putSoftwareProductProcess); |
| 62 | router.post('/v1.0/vendor-software-products/:vspId/processes', postSoftwareProductProcess); |
| 63 | } |
| 64 | |
| 65 | |
| 66 | function licenseModelsList(req, res) { |
| 67 | res.json(require('./data/licenseModels')); |
| 68 | } |
| 69 | |
| 70 | function featureGroupList(req, res) { |
| 71 | res.json(require('./data/featureGroups')); |
| 72 | } |
| 73 | |
| 74 | function featureGroup(req, res) { |
| 75 | res.json(require('./data/featureGroup')); |
| 76 | } |
| 77 | |
| 78 | function deletefeatureGroup(req, res) { |
| 79 | res.json({ |
| 80 | returnCode: 'OK' |
| 81 | }); |
| 82 | } |
| 83 | |
| 84 | |
| 85 | function updatefeatureGroup(req, res) { |
| 86 | res.json({ |
| 87 | returnCode: 'OK' |
| 88 | }); |
| 89 | } |
| 90 | |
| 91 | function addFeatureGroup(req,res) { |
| 92 | var id = Math.floor(Math.random() * (100 - 1) + 1).toString(); |
| 93 | res.json({ |
| 94 | returnCode: 'OK', |
| 95 | value: id |
| 96 | }) |
| 97 | } |
| 98 | |
| 99 | /** ENTITLEMENT POOLS **/ |
| 100 | function entitlementPoolsList(req, res) { |
| 101 | res.json(require('./data/entitlementPools')); |
| 102 | } |
| 103 | |
| 104 | function updateEntitlementPool(req, res) { |
| 105 | res.json({ |
| 106 | returnCode: 'OK' |
| 107 | }); |
| 108 | } |
| 109 | |
| 110 | function addEntitlementPool(req,res) { |
| 111 | var id = Math.floor(Math.random() * (100 - 1) + 1).toString(); |
| 112 | res.json({ |
| 113 | returnCode: 'OK', |
| 114 | value: id |
| 115 | }) |
| 116 | } |
| 117 | |
| 118 | function deleteEntitlementPool(req, res) { |
| 119 | res.json({ |
| 120 | returnCode: 'OK' |
| 121 | }); |
| 122 | } |
| 123 | |
| 124 | /** LICENSE KEY GROUPS */ |
| 125 | |
| 126 | function licenseKeyGroupsList(req, res) { |
| 127 | res.json(require('./data/licenseKeyGroups')); |
| 128 | } |
| 129 | |
| 130 | function addLicenseKeyGroup(req,res) { |
| 131 | var id = Math.floor(Math.random() * (100 - 1) + 1).toString(); |
| 132 | res.json({ |
| 133 | returnCode: 'OK', |
| 134 | value: id |
| 135 | }) |
| 136 | } |
| 137 | |
| 138 | function deleteLicenseKeyGroup(req, res) { |
| 139 | res.json({ |
| 140 | returnCode: 'OK' |
| 141 | }); |
| 142 | } |
| 143 | |
| 144 | function updateLicenseKeyGroup(req, res) { |
| 145 | res.json({ |
| 146 | returnCode: 'OK' |
| 147 | }); |
| 148 | } |
| 149 | |
| 150 | function licenseAgreementList(req, res) { |
| 151 | res.json(require('./data/licenseAgreementList')); |
| 152 | } |
| 153 | |
| 154 | |
| 155 | function addLicenseAgreement(req,res) { |
| 156 | var id = Math.floor(Math.random() * (100 - 1) + 1).toString(); |
| 157 | res.json({ |
| 158 | returnCode: 'OK', |
| 159 | value: id |
| 160 | }) |
| 161 | } |
| 162 | function deleteLicenseAgreement(req, res) { |
| 163 | res.json({ |
| 164 | returnCode: 'OK' |
| 165 | }); |
| 166 | } |
| 167 | function updateLicenseAgreement(req, res) { |
| 168 | res.json({ |
| 169 | returnCode: 'OK' |
| 170 | }); |
| 171 | } |
| 172 | |
| 173 | /** VENDOR SOFTWARE PRODUCT */ |
| 174 | |
| 175 | function softwareProductUpload(req, res) { |
| 176 | res.json({ |
| 177 | status: 'SUCCESS' |
| 178 | }); |
| 179 | } |
| 180 | |
| 181 | function getSoftwareProduct(req, res) { |
| 182 | res.json(require('./data/softwareProduct')); |
| 183 | } |
| 184 | |
| 185 | |
| 186 | function putSoftwareProductProcess(req, res) { |
| 187 | res.json({ |
| 188 | status: 'SUCCESS' |
| 189 | }); |
| 190 | } |
| 191 | |
| 192 | function postSoftwareProductProcess(req, res) { |
| 193 | var id = Math.floor(Math.random() * (100 - 1) + 1).toString(); |
| 194 | res.json({ |
| 195 | returnCode: 'OK', |
| 196 | value: id |
| 197 | }); |
| 198 | } |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | function createFixtureServer(port) { |
| 204 | var express = require('express'); |
| 205 | var app = express(); |
| 206 | var bodyParser = require('body-parser'); |
| 207 | app.use(bodyParser.urlencoded({extended: true})); |
| 208 | app.use(bodyParser.json()); |
| 209 | |
| 210 | var router = express.Router(); |
| 211 | |
| 212 | defineRoutes(router); |
| 213 | |
| 214 | app.use('/api', router); |
| 215 | app.use('/onboarding-api', router); |
| 216 | app.use('/sdc1/feProxy/onboarding-api', router); |
| 217 | |
| 218 | app.listen(port); |
| 219 | |
| 220 | console.log('Fixture server is up. port->', port); |
| 221 | //console.log(router.stack); |
| 222 | return app; |
| 223 | } |
| 224 | |
| 225 | /** SOFTWARE PRODUCT LIST **/ |
| 226 | function softwareProductList(req, res) { |
| 227 | res.json(require('./data/softwareProductList')); |
| 228 | } |
| 229 | |
| 230 | |
| 231 | createFixtureServer(args[0]); |