aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/mocks/datafilecollector-testharness/dr-sim/dmaapDR.js79
1 files changed, 56 insertions, 23 deletions
diff --git a/test/mocks/datafilecollector-testharness/dr-sim/dmaapDR.js b/test/mocks/datafilecollector-testharness/dr-sim/dmaapDR.js
index 7e57b6151..4e7317473 100644
--- a/test/mocks/datafilecollector-testharness/dr-sim/dmaapDR.js
+++ b/test/mocks/datafilecollector-testharness/dr-sim/dmaapDR.js
@@ -4,12 +4,13 @@ var ArgumentParser = require('argparse').ArgumentParser;
var express = require('express');
const stream = require('stream');
var app = express();
-var fs = require("fs");
+var fs = require('fs');
var path = require('path');
var privateKey = fs.readFileSync('cert/private.key', 'utf8');
var certificate = fs.readFileSync('cert/certificate.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};
-
+const allPublished = "allPublished";
+const nonePublished = "nonePublished";
var parser = new ArgumentParser({
version: '0.0.1',
@@ -27,22 +28,18 @@ parser.addArgument('--printtc' ,
var args = parser.parseArgs();
-if (args.tc=="100") {
- console.log("TC: 100")
-}
-if (args.tc=="101") {
- console.log("TC: 101")
- //preparations
+if (args.tc=="nonePublished") {
+ console.log("TC: nonePublished")
}
-if (args.tc=="102") {
- console.log("TC: 102")
+if (args.tc=="allPublished") {
+ console.log("TC: allPublished")
//preparations
}
if (args.printtc) {
- console.log("TC 100: receive all incoming files");
- console.log("TC 101: drop/deny first 10 publishing attempt, then receive all");
- console.log("TC 102: drop/deny/every second publisging attempt");
+ console.log("TC nonePublished: no file has already been published.");
+ console.log("TC allPublished: whatever is the request, this file is considered as published.");
+ console.log("No argument passed: normal behaviour, that is publish if not already published");
process.exit(0);
}
@@ -62,19 +59,55 @@ app.use(bodyParser.text({ type: 'text/html' }))
app.get("/",function(req, res){
res.send("ok");
})
-app.put('/publish/1/:filename', function (req, res) {
- console.log(req.files);
- console.log(req.body);
- console.log(req.headers);
- var filename = path.basename(req.params.filename);
- res.redirect(301, 'http://127.0.0.1:3908/publish/1/'+filename)
+
+
+var published = [];
+app.get('/feedlog/1/',function(req, res){
+ var filename = req.query.filename;
+ if(args.tc == allPublished){
+ res.send("[" + filename + "]");
+ } else if(args.tc == nonePublished){
+ res.send("[]");
+ } else {
+ if (published.includes(filename)) {
+ res.send("[" + filename + "]");
+ } else {
+ res.send("[]");
+ }
+ }
+})
+
+
+app.put('/publish/1/', function (req, res) {
+ var filename = req.query.filename;
+ var type = req.query.type;
+ if(typeof(filename) == 'undefined'){
+ res.status(400).send({error: 'No filename provided.'});
+ } else if(typeof(type) == 'undefined'){
+ res.status(400).send({error: 'No type provided.'});
+ } else {
+ if(args.tc == allPublished){
+ res.send("[" + filename + "]");
+ } else if(args.tc == nonePublished){
+ res.redirect(301, 'http://127.0.0.1:3908/publish/1/'+filename);
+ } else {
+ if (!published.includes(filename)) {
+ published.push(filename);
+ res.redirect(301, 'http://127.0.0.1:3908/publish/1/'+filename);
+ } else {
+ res.send("ok");
+ }
+ }
+ }
})
+
+
var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);
-var httpPort=3906
-var httpsPort=3907
+var httpPort=3906;
+var httpsPort=3907;
httpServer.listen(httpPort);
-console.log("DR-simulator listening (http) at "+httpPort)
+console.log("DR-simulator listening (http) at "+httpPort);
httpsServer.listen(httpsPort);
-console.log("DR-simulator listening (https) at "+httpsPort)
+console.log("DR-simulator listening (https) at "+httpsPort); \ No newline at end of file