ardtweeno 0.0.2 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG +179 -1
- data/COPYING +4 -3
- data/Gemfile +29 -0
- data/Gemfile.lock +76 -0
- data/INSTALL +12 -0
- data/Procfile +1 -0
- data/README.md +26 -2
- data/Rakefile +14 -7
- data/lib/ardtweeno/api.rb +542 -0
- data/lib/ardtweeno/configreader.rb +65 -0
- data/lib/ardtweeno/db.rb +51 -0
- data/lib/ardtweeno/dispatcher.rb +538 -0
- data/lib/ardtweeno/exceptions.rb +33 -0
- data/lib/ardtweeno/node.rb +117 -0
- data/lib/ardtweeno/nodemanager.rb +300 -0
- data/lib/ardtweeno/packet.rb +98 -0
- data/lib/ardtweeno/restapi.rb +266 -0
- data/lib/ardtweeno/serialparser.rb +221 -0
- data/lib/ardtweeno.rb +120 -1
- data/public/glossy_green_button.svg +123 -0
- data/public/glossy_red_button.svg +75 -0
- data/public/main.css +129 -0
- data/public/raspberrypi.jpg +0 -0
- data/resources/conf.yaml +41 -0
- data/resources/nodelist.yaml +26 -0
- data/resources/serialparser.js +84 -0
- data/test/api_test.rb +255 -0
- data/test/dispatcher_test.rb +115 -0
- data/test/node_test.rb +105 -0
- data/test/nodemanager_test.rb +167 -0
- data/test/packet_test.rb +75 -0
- data/test/parser_test.rb +147 -0
- data/test/post_watch +11 -0
- data/test/rest_api_test.rb +248 -0
- data/test/run_mock +17 -0
- data/test/run_packet_push +14 -0
- data/test/serialport_mock.rb +43 -0
- data/test/test_helper.rb +15 -0
- data/test/tty0tty-1.1/AUTHORS +1 -0
- data/test/tty0tty-1.1/COPYING +340 -0
- data/test/tty0tty-1.1/INSTALL +18 -0
- data/test/tty0tty-1.1/README +52 -0
- data/test/tty0tty-1.1/THANKS +4 -0
- data/test/tty0tty-1.1/TODO +3 -0
- data/test/tty0tty-1.1/VERSION +4 -0
- data/test/tty0tty-1.1/module/Makefile +41 -0
- data/{bin/ardtweeno → test/tty0tty-1.1/module/Module.symvers} +0 -0
- data/test/tty0tty-1.1/module/modules.order +1 -0
- data/test/tty0tty-1.1/module/tty0tty.c +678 -0
- data/test/tty0tty-1.1/module/tty0tty.ko +0 -0
- data/test/tty0tty-1.1/module/tty0tty.mod.c +51 -0
- data/test/tty0tty-1.1/module/tty0tty.mod.o +0 -0
- data/test/tty0tty-1.1/module/tty0tty.o +0 -0
- data/test/tty0tty-1.1/pts/Makefile +10 -0
- data/test/tty0tty-1.1/pts/tty0tty +0 -0
- data/test/tty0tty-1.1/pts/tty0tty.c +222 -0
- data/views/createpost.erb +45 -0
- data/views/home.erb +59 -0
- metadata +89 -37
- data/README +0 -1
- data/test/Rakefile +0 -6
- data/test/features/ardtweeno.feature +0 -14
- data/test/features/step_definitions/ardtweeno_steps.rb +0 -24
data/public/main.css
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
html, body {
|
2
|
+
margin: 0;
|
3
|
+
padding: 0;
|
4
|
+
}
|
5
|
+
|
6
|
+
body {
|
7
|
+
background: #1E1C17;
|
8
|
+
color: #ccc;
|
9
|
+
font-family: 'Trebuchet MS', 'Lucida Grande', Arial, Helvetica, sans-serif;
|
10
|
+
line-height: 1.2em;
|
11
|
+
}
|
12
|
+
|
13
|
+
img {
|
14
|
+
border: 0;
|
15
|
+
}
|
16
|
+
|
17
|
+
#status {
|
18
|
+
position: relative;
|
19
|
+
top: 6px;
|
20
|
+
}
|
21
|
+
|
22
|
+
|
23
|
+
a {
|
24
|
+
text-decoration: underline;
|
25
|
+
color: #FCC240;
|
26
|
+
text-decoration: none;
|
27
|
+
}
|
28
|
+
a:hover {
|
29
|
+
color: #BF4B31;
|
30
|
+
}
|
31
|
+
|
32
|
+
h1, h2, h3 {
|
33
|
+
font-size: 1.8em;
|
34
|
+
margin: 1em 0 0.5em 0;
|
35
|
+
padding: 0 0 0.2em 0;
|
36
|
+
color: #666;
|
37
|
+
}
|
38
|
+
h2 {
|
39
|
+
font-size: 1.4em;
|
40
|
+
}
|
41
|
+
h3 {
|
42
|
+
font-size: 1.2em;
|
43
|
+
}
|
44
|
+
|
45
|
+
hr {
|
46
|
+
position: relative;
|
47
|
+
background: transparent;
|
48
|
+
background: #ccc;
|
49
|
+
height: 0px;
|
50
|
+
border: 1px solid #ccc;
|
51
|
+
}
|
52
|
+
|
53
|
+
code {
|
54
|
+
background: #CED6B4;
|
55
|
+
padding: 0.7em;
|
56
|
+
font-family: Monaco, monospace;
|
57
|
+
color: #1E1C17;
|
58
|
+
border: 2px solid #444;
|
59
|
+
display: block;
|
60
|
+
}
|
61
|
+
|
62
|
+
div#content {
|
63
|
+
position: relative;
|
64
|
+
margin: 2em 2em;
|
65
|
+
}
|
66
|
+
|
67
|
+
div#post {
|
68
|
+
padding: 0 0 2.5em 0;
|
69
|
+
}
|
70
|
+
|
71
|
+
#intro {
|
72
|
+
padding: 0 0 2.5em 0;
|
73
|
+
}
|
74
|
+
|
75
|
+
#content p {
|
76
|
+
max-width: 50em;
|
77
|
+
}
|
78
|
+
|
79
|
+
div#header {
|
80
|
+
position: relative;
|
81
|
+
height: 3em;
|
82
|
+
margin: 0;
|
83
|
+
background: #4D8B4D;
|
84
|
+
border-bottom: 3px solid #FCC240;
|
85
|
+
text-align: left;
|
86
|
+
}
|
87
|
+
#logo {
|
88
|
+
position: absolute;
|
89
|
+
top: 15px;
|
90
|
+
left: 1em;
|
91
|
+
color: #fff;
|
92
|
+
font-size: 200%;
|
93
|
+
}
|
94
|
+
|
95
|
+
ul#navigation {
|
96
|
+
font-size: 90%;
|
97
|
+
position: absolute;
|
98
|
+
bottom: 0;
|
99
|
+
right: 2em;
|
100
|
+
}
|
101
|
+
ul#navigation li {
|
102
|
+
list-style-type: none;
|
103
|
+
display: inline;
|
104
|
+
margin-right: 1em;
|
105
|
+
}
|
106
|
+
ul#navigation a {
|
107
|
+
color: #ccc;
|
108
|
+
text-decoration: none;
|
109
|
+
}
|
110
|
+
ul#navigation a:hover {
|
111
|
+
color: #fff;
|
112
|
+
border-bottom: 2px solid #fff;
|
113
|
+
}
|
114
|
+
|
115
|
+
p#blurb {
|
116
|
+
font-size: 120%;
|
117
|
+
color: #CED6B4;
|
118
|
+
}
|
119
|
+
|
120
|
+
img#me {
|
121
|
+
float: right;
|
122
|
+
margin-top: -1em;
|
123
|
+
margin-left: 2em;
|
124
|
+
border: 3px solid #444;
|
125
|
+
}
|
126
|
+
|
127
|
+
.clear {
|
128
|
+
clear: both;
|
129
|
+
}
|
Binary file
|
data/resources/conf.yaml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Device the serial device to which the Ardtweeno SerialParser will connect
|
2
|
+
dev: /dev/ttyUSB0
|
3
|
+
speed: 9600
|
4
|
+
|
5
|
+
# Administrator API Key
|
6
|
+
adminkey: 1230aea77d7bd38898fec74a75a87738dea9f657
|
7
|
+
|
8
|
+
# Settings for the Database
|
9
|
+
db:
|
10
|
+
dbHost: localhost
|
11
|
+
dbPort: 27017
|
12
|
+
dbUser: herp
|
13
|
+
dbPass: 86ddd1420701a08d4a4380ca5d240ba7
|
14
|
+
dbName: ardtweeno
|
15
|
+
dbPacketsColl: packets
|
16
|
+
|
17
|
+
# Zone configuration
|
18
|
+
zones:
|
19
|
+
-
|
20
|
+
zonename: testzone0
|
21
|
+
zonekey: 455a807bb34b1976bac820b07c263ee81bd267cc
|
22
|
+
zonenodes:
|
23
|
+
- node0
|
24
|
+
-
|
25
|
+
zonename: testzone1
|
26
|
+
zonekey: 79a7c75758879243418fe2c87ec7d5d4e1451129
|
27
|
+
zonenodes:
|
28
|
+
- node1
|
29
|
+
|
30
|
+
|
31
|
+
## Some spare unused hashes
|
32
|
+
#f32b8561622c16cb0f758d2c0b4bdc3e651bbfc1
|
33
|
+
#1b901dc0e9db739cc88a5568d201eb594742d1a2
|
34
|
+
#0f3f3b500b694f515aa57f4ca13fc67b2f9f48d6
|
35
|
+
#72b1a50b637f2051f1606c3997e80d33e36cba14
|
36
|
+
#f7c98a41cc2705d9425b52d94ebd46296900d2aa
|
37
|
+
#3dde6ae0f124c2446d7c50a6741a87e6ab0012ed
|
38
|
+
#4ce7c012462a50256274bd38e3c12b720a99e4e0
|
39
|
+
#b41143c153fdb15b5299c99bf451dc6a67fe2e36
|
40
|
+
#78431dac18f37d437aa3c055d40d65d813a73143
|
41
|
+
#8b785ee6da0a558f10db9da80e40df3fef44d43f
|
@@ -0,0 +1,26 @@
|
|
1
|
+
-
|
2
|
+
name: node0
|
3
|
+
key: 500d81aafe637717a52f8650e54206e64da33d27
|
4
|
+
description: This node has a temperature sensor
|
5
|
+
version: 0.2.1
|
6
|
+
sensors:
|
7
|
+
- Temperature
|
8
|
+
-
|
9
|
+
name: node1
|
10
|
+
key: f937c37e949d9efa20d2958af309235c73ec039a
|
11
|
+
description: This node has a movement sensor
|
12
|
+
version: 0.2.1
|
13
|
+
sensors:
|
14
|
+
- Movement
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
#node2 : 2dbf44a68b77b15bfa5bc3d66c97892a57402bbe
|
20
|
+
#node3 : a46fe0c4dab0453f5d86bed6206040880f59393e
|
21
|
+
#node4 : 9da30539af3639c600c6256f7691750a581c36c2
|
22
|
+
#node5 : b0a69b1f9fe82d6c149179ce48e22f9c8411afe3
|
23
|
+
#node6 : 74e5a4bcab7355b8cab7df73d07747cd85c925e7
|
24
|
+
#node7 : c03e55d15602a33922858e97664ea33f368ef5de
|
25
|
+
#node8 : c65b8681a4eec1d41b1ba1b013535f1c96d943ab
|
26
|
+
#node9 : 0785284586ef5810b80560319ef24968e897f7ce
|
@@ -0,0 +1,84 @@
|
|
1
|
+
var serialport = require("serialport");
|
2
|
+
var SerialPort = serialport.SerialPort;
|
3
|
+
var needle = require('needle');
|
4
|
+
|
5
|
+
// Read in the ARGV object parameters and remove the first two which hold the node variable
|
6
|
+
// and the name of the script file.
|
7
|
+
var myArgs = process.argv.slice(2);
|
8
|
+
|
9
|
+
// Check to ensure the remaining parameters size is 2
|
10
|
+
if(!(myArgs.length == 3)){
|
11
|
+
console.log("Usage: node serialparser.js /dev/ttyUSB0 9600 adminkey");
|
12
|
+
process.exit();
|
13
|
+
}
|
14
|
+
|
15
|
+
var dev = myArgs[0];
|
16
|
+
var options = {
|
17
|
+
parser: serialport.parsers.raw,
|
18
|
+
baudrate: parseInt(myArgs[1])
|
19
|
+
};
|
20
|
+
|
21
|
+
var sp = new SerialPort(dev, options);
|
22
|
+
var tempData = "";
|
23
|
+
var attempts = 0;
|
24
|
+
|
25
|
+
sp.on("data", function (data) {
|
26
|
+
data = data.toString().trim();
|
27
|
+
|
28
|
+
console.log("Data received: " + data);
|
29
|
+
|
30
|
+
try {
|
31
|
+
if(attempts > 0){
|
32
|
+
throw new Error('Preventing loss of data in buffer');
|
33
|
+
}
|
34
|
+
JSON.parse(data);
|
35
|
+
tempData = "";
|
36
|
+
attempts = 0;
|
37
|
+
console.log("Data for transmit: " + data);
|
38
|
+
var theData = 'key=' + myArgs[2] + '&payload=' + data
|
39
|
+
|
40
|
+
needle.post('http://localhost:4567/api/v1/packets', theData, function(err, resp, body){
|
41
|
+
try {
|
42
|
+
console.log("Got status code: " + resp.statusCode);
|
43
|
+
// you can pass params as a string or as an object
|
44
|
+
} catch (e){
|
45
|
+
console.log(e.message)
|
46
|
+
}
|
47
|
+
});
|
48
|
+
|
49
|
+
} catch (e) {
|
50
|
+
tempData += data;
|
51
|
+
tempData = tempData.trim();
|
52
|
+
|
53
|
+
if(attempts < 15){
|
54
|
+
try {
|
55
|
+
JSON.parse(tempData);
|
56
|
+
data = tempData;
|
57
|
+
tempData = "";
|
58
|
+
attempts = 0;
|
59
|
+
console.log("Data for transmit: " + data);
|
60
|
+
var theData = 'key=' + myArgs[2] + '&payload=' + data
|
61
|
+
|
62
|
+
needle.post('http://localhost:4567/api/v1/packets', theData, function(err, resp, body){
|
63
|
+
try {
|
64
|
+
console.log("Got status code: " + resp.statusCode);
|
65
|
+
// you can pass params as a string or as an object
|
66
|
+
} catch (e){
|
67
|
+
console.log(e.message)
|
68
|
+
}
|
69
|
+
});
|
70
|
+
|
71
|
+
} catch(e){
|
72
|
+
console.log("buffer contains: " + tempData);
|
73
|
+
console.log("Nope still not a valid JSON string, buffering...");
|
74
|
+
}
|
75
|
+
|
76
|
+
}
|
77
|
+
else
|
78
|
+
{
|
79
|
+
tempData = "";
|
80
|
+
attempts = 0;
|
81
|
+
}
|
82
|
+
attempts += 1;
|
83
|
+
}
|
84
|
+
});
|
data/test/api_test.rb
ADDED
@@ -0,0 +1,255 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rack/test'
|
4
|
+
require 'ardtweeno'
|
5
|
+
require 'logger'
|
6
|
+
require 'json'
|
7
|
+
require 'date'
|
8
|
+
|
9
|
+
ENV['RACK_ENV'] = 'test'
|
10
|
+
|
11
|
+
|
12
|
+
class APITest < Test::Unit::TestCase
|
13
|
+
|
14
|
+
include Rack::Test::Methods
|
15
|
+
|
16
|
+
attr_accessor :dispatch, :nodelist, :nodemanager, :params, :date, :hour, :minute
|
17
|
+
|
18
|
+
|
19
|
+
# Test suite fixtures
|
20
|
+
def setup
|
21
|
+
|
22
|
+
begin
|
23
|
+
# Inform the Ardtweeno::Dispatcher we are in testing mode so do not run the bootstrap()
|
24
|
+
# method as we will be creating instances of all required classes in the fixtures then
|
25
|
+
# injecting them into the dispatcher
|
26
|
+
Ardtweeno.setup({:test=>true, :log=>Logger.new(STDOUT), :level=>Logger::DEBUG})
|
27
|
+
@dispatch = Ardtweeno::Dispatcher.instance
|
28
|
+
|
29
|
+
|
30
|
+
# Create a DateTime instance
|
31
|
+
today = DateTime.now
|
32
|
+
theDate = today.year.to_s() + "-" + "%02d" % today.month.to_s() + "-" + "%02d" % today.day.to_s()
|
33
|
+
|
34
|
+
# Default values
|
35
|
+
@date = theDate
|
36
|
+
@hour = ("%02d" % today.hour).to_s
|
37
|
+
@minute = ("%02d" % today.min).to_s
|
38
|
+
|
39
|
+
@nodeList = Array.new
|
40
|
+
|
41
|
+
5.times do |i|
|
42
|
+
@nodeList << Ardtweeno::Node.new("node#{i}", "abcdef#{i}", {:version=>"0.5.0"})
|
43
|
+
end
|
44
|
+
|
45
|
+
@nodemanager = Ardtweeno::NodeManager.new({:nodelist => @nodeList})
|
46
|
+
|
47
|
+
@dispatch.nodeManager = @nodemanager
|
48
|
+
|
49
|
+
@params = { :empty=> {},
|
50
|
+
:withnode=> {:node=>"node1"},
|
51
|
+
:withinvalidnode=> {:node=>"node7"},
|
52
|
+
:withoffset=> {:offset=>2},
|
53
|
+
:withnegativeoffset=> {:offset=>-32},
|
54
|
+
:withoffsetbordertest=> {:offset=>5},
|
55
|
+
:withlength=> {:length=>2},
|
56
|
+
:withzerolength=> {:length=>0},
|
57
|
+
:withlargelength=> {:length=>500},
|
58
|
+
:withsort=> {:sort=>"asc"},
|
59
|
+
:withsortreverse=> {:sort=>"desc"},
|
60
|
+
:withdate=> {:date=>@date},
|
61
|
+
:withhour=> {:hour=>@hour},
|
62
|
+
:withdatewrong=> {:date=>"11-111-1111"},
|
63
|
+
:withhourwrong=> {:hour=>"022"},
|
64
|
+
:withminute=> {:minute=>@minute},
|
65
|
+
:withminutewrong=> {:minute=>"022"},
|
66
|
+
:withseqno=> {:seqno=>35},
|
67
|
+
:withseqnowrong=> {:seqno=>50000},
|
68
|
+
:withversion=> {:version=> "0.5.0"},
|
69
|
+
:withversionwrong=> {:version=> "0.0.0"},
|
70
|
+
:withname=> {:name=>"node0"},
|
71
|
+
:withnamewrong=> {:name=>"node28"},
|
72
|
+
:withnodekey=> {:nodekey=>"abcdef1"},
|
73
|
+
:withnodekeywrong=> {:nodekey=>"fffffffffff"},
|
74
|
+
:withzonename=> {:zonename=>"testzone0"},
|
75
|
+
:withoutzonename=> {:zonename=>"notazonename"}
|
76
|
+
}
|
77
|
+
|
78
|
+
5.times do |i|
|
79
|
+
@dispatch.store('{"data":[23.5,997.5,65],"key":"abcdef1"}')
|
80
|
+
end
|
81
|
+
|
82
|
+
rescue Exception => e
|
83
|
+
puts e.message
|
84
|
+
puts e.backtrace
|
85
|
+
exit
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
# tear down the test fixtures between each test
|
92
|
+
def teardown
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
# Test the retrievezones method
|
98
|
+
def test_retrievezones
|
99
|
+
results = @dispatch.retrieve_zones(@params[:withzonename])
|
100
|
+
assert_equal(1, results[:zones].size)
|
101
|
+
|
102
|
+
results = @dispatch.retrieve_zones(@params[:withoutzonename])
|
103
|
+
assert_equal(0, results[:zones].size)
|
104
|
+
|
105
|
+
results = @dispatch.retrieve_zones(@params[:empty])
|
106
|
+
assert_equal(2, results[:zones].size)
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
# Test the retrievenodes method
|
113
|
+
def test_retrievenodes
|
114
|
+
results = @dispatch.retrieve_nodes(@params[:empty])
|
115
|
+
assert_equal(5, results[:nodes].size)
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
# Test the retrievepackets method
|
120
|
+
def test_retrievepackets
|
121
|
+
results = @dispatch.retrieve_packets(@params[:withnode])
|
122
|
+
assert_equal(5, results[:packets].size)
|
123
|
+
|
124
|
+
results = @dispatch.retrieve_packets(@params[:withinvalidnode])
|
125
|
+
assert_equal(0, results[:packets].size)
|
126
|
+
|
127
|
+
results = @dispatch.retrieve_packets(@params[:empty])
|
128
|
+
assert_equal(5, results[:packets].size)
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
# Test the handleVersion method
|
134
|
+
def test_handleVersion
|
135
|
+
results = @dispatch.retrieve_nodes(@params[:withversion])
|
136
|
+
assert_equal(5, results[:nodes].size)
|
137
|
+
|
138
|
+
results = @dispatch.retrieve_nodes(@params[:withversionwrong])
|
139
|
+
assert_equal(0 , results[:nodes].size)
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
# Test the handleName method
|
144
|
+
def test_handleName
|
145
|
+
results = @dispatch.retrieve_nodes(@params[:withname])
|
146
|
+
assert_equal(1, results[:nodes].size)
|
147
|
+
|
148
|
+
results = @dispatch.retrieve_nodes(@params[:withnamewrong])
|
149
|
+
assert_equal(0 , results[:nodes].size)
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
# Test the handleNodeKey method
|
154
|
+
def test_handleNodeKey
|
155
|
+
results = @dispatch.retrieve_nodes(@params[:withnodekey])
|
156
|
+
assert_equal(1, results[:nodes].size)
|
157
|
+
|
158
|
+
results = @dispatch.retrieve_nodes(@params[:withnodekeywrong])
|
159
|
+
assert_equal(0 , results[:nodes].size)
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
# Test the handleSeqNo method
|
164
|
+
def test_handleSeqNo
|
165
|
+
results = @dispatch.retrieve_packets(@params[:withseqno])
|
166
|
+
assert_equal(1, results[:packets].size)
|
167
|
+
|
168
|
+
results = @dispatch.retrieve_packets(@params[:withseqnowrong])
|
169
|
+
assert_equal(0, results[:packets].size)
|
170
|
+
end
|
171
|
+
|
172
|
+
# Test the handleMinute method
|
173
|
+
def test_handleMinute
|
174
|
+
results = @dispatch.retrieve_packets(@params[:withminute])
|
175
|
+
assert_equal(5, results[:packets].size)
|
176
|
+
|
177
|
+
results = @dispatch.retrieve_packets(@params[:withminutewrong])
|
178
|
+
assert_equal(0, results[:packets].size)
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
# Test the handleHour method
|
183
|
+
def test_handleHour
|
184
|
+
results = @dispatch.retrieve_packets(@params[:withhour])
|
185
|
+
assert_equal(5, results[:packets].size)
|
186
|
+
|
187
|
+
results = @dispatch.retrieve_packets(@params[:withhourwrong])
|
188
|
+
assert_equal(0, results[:packets].size)
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
# Test the handleDate method
|
193
|
+
def test_handleDate
|
194
|
+
results = @dispatch.retrieve_packets(@params[:withdate])
|
195
|
+
assert_equal(5, results[:packets].size)
|
196
|
+
|
197
|
+
results = @dispatch.retrieve_packets(@params[:withdatewrong])
|
198
|
+
assert_equal(0, results[:packets].size)
|
199
|
+
end
|
200
|
+
|
201
|
+
|
202
|
+
# Test the handleOffset method
|
203
|
+
def test_handleOffset
|
204
|
+
results = @dispatch.retrieve_packets(@params[:withoffset])
|
205
|
+
assert_equal(3, results[:packets].size)
|
206
|
+
|
207
|
+
results = @dispatch.retrieve_packets(@params[:withoffsetbordertest])
|
208
|
+
assert_equal(0, results[:packets].size)
|
209
|
+
|
210
|
+
results = @dispatch.retrieve_packets(@params[:withnegativeoffset])
|
211
|
+
assert_equal(5, results[:packets].size)
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
# Test the handleLenght method
|
217
|
+
def test_handleLength
|
218
|
+
results = @dispatch.retrieve_packets(@params[:withlength])
|
219
|
+
assert_equal(2, results[:packets].size)
|
220
|
+
|
221
|
+
results = @dispatch.retrieve_packets(@params[:withzerolength])
|
222
|
+
assert_equal(0, results[:packets].size)
|
223
|
+
|
224
|
+
results = @dispatch.retrieve_packets(@params[:withlargelength])
|
225
|
+
assert_equal(5, results[:packets].size)
|
226
|
+
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
|
+
# Test the handleSort method
|
231
|
+
def test_handleSort
|
232
|
+
results = @dispatch.retrieve_packets(@params[:withsort])
|
233
|
+
assert_equal(5, results[:packets].size)
|
234
|
+
|
235
|
+
assert_block do
|
236
|
+
val1 = results[:packets][0].seqNo
|
237
|
+
val2 = results[:packets][4].seqNo
|
238
|
+
|
239
|
+
if val2 > val1 then return true; else return false; end
|
240
|
+
end
|
241
|
+
|
242
|
+
|
243
|
+
results = @dispatch.retrieve_packets(@params[:withsortreverse])
|
244
|
+
assert_equal(5, results[:packets].size)
|
245
|
+
|
246
|
+
assert_block do
|
247
|
+
val1 = results[:packets][0].seqNo
|
248
|
+
val2 = results[:packets][4].seqNo
|
249
|
+
|
250
|
+
if val2 < val1 then return true; else return false; end
|
251
|
+
end
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rack/test'
|
4
|
+
require 'ardtweeno'
|
5
|
+
require 'logger'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
ENV['RACK_ENV'] = 'test'
|
9
|
+
|
10
|
+
|
11
|
+
class DispatcherTest < Test::Unit::TestCase
|
12
|
+
|
13
|
+
include Rack::Test::Methods
|
14
|
+
|
15
|
+
attr_accessor :dispatch
|
16
|
+
|
17
|
+
|
18
|
+
# Test suite fixtures
|
19
|
+
def setup
|
20
|
+
|
21
|
+
begin
|
22
|
+
# Inform the Ardtweeno::Dispatcher we are in testing mode so do not run the bootstrap()
|
23
|
+
# method as we will be creating instances of all required classes in the fixtures then
|
24
|
+
# injecting them into the dispatcher
|
25
|
+
Ardtweeno.setup({:test=>true, :log=>Logger.new(STDOUT), :level=>Logger::DEBUG})
|
26
|
+
@dispatch = Ardtweeno::Dispatcher.instance
|
27
|
+
|
28
|
+
@nodeList = Array.new
|
29
|
+
|
30
|
+
5.times do |i|
|
31
|
+
@nodeList << Ardtweeno::Node.new("node#{i}", "abcdef#{i}")
|
32
|
+
end
|
33
|
+
|
34
|
+
@nodemanager = Ardtweeno::NodeManager.new({:nodelist => @nodeList})
|
35
|
+
|
36
|
+
@dispatch.nodeManager = @nodemanager
|
37
|
+
|
38
|
+
rescue Exception => e
|
39
|
+
puts e.message
|
40
|
+
puts e.backtrace
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# tear down the test fixtures between each test
|
48
|
+
def teardown
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
# Test to ensure the Ardtweeno::Dispatcher#running? is operating correctly
|
53
|
+
def test_running
|
54
|
+
assert_equal(false, @dispatch.running?)
|
55
|
+
|
56
|
+
@dispatch.start
|
57
|
+
assert_equal(true, @dispatch.running?)
|
58
|
+
|
59
|
+
@dispatch.stop
|
60
|
+
assert_equal(false, @dispatch.running?)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Test to ensure the Ardtweeno::Dispatcher#start can launch the system correctly
|
64
|
+
def test_start
|
65
|
+
assert_equal(true, @dispatch.start)
|
66
|
+
assert_equal(false, @dispatch.start)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Test to ensure the Ardtweeno::Dispatcher#stop can terminate the system correctly.
|
70
|
+
def test_stop
|
71
|
+
@dispatch.start
|
72
|
+
assert_equal(true, @dispatch.stop)
|
73
|
+
assert_equal(false, @dispatch.stop)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Test to ensure the Ardtweeno::Dispatcher#store method is operating correctly
|
77
|
+
def test_store
|
78
|
+
# Test to ensure it will raise an exception if we try to add something other than an
|
79
|
+
# Ardtweeno::Packet
|
80
|
+
assert_raise TypeError do
|
81
|
+
@dispatch.store(Hash.new)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Raise a JSON ParserError if we send a string but invalid JSON
|
85
|
+
assert_raise JSON::ParserError do
|
86
|
+
@dispatch.store("{derp:}")
|
87
|
+
end
|
88
|
+
|
89
|
+
# Raises Ardtweeno InvalidData if we send valid JSON but invalid Packet data
|
90
|
+
assert_raise Ardtweeno::InvalidData do
|
91
|
+
@dispatch.store("{}")
|
92
|
+
end
|
93
|
+
|
94
|
+
# Raises Ardtweeno InvalidData if we send valid JSON but invalid Packet data
|
95
|
+
assert_raise Ardtweeno::InvalidData do
|
96
|
+
@dispatch.store('{"key":"500d81aafe637717a52f8650e54206e64da33d27"}')
|
97
|
+
end
|
98
|
+
|
99
|
+
# Raises Ardtweeno InvalidData if we send valid JSON but invalid Packet data
|
100
|
+
assert_raise Ardtweeno::InvalidData do
|
101
|
+
@dispatch.store('{"data":[23.5,997.5,65]}')
|
102
|
+
end
|
103
|
+
|
104
|
+
# Raises Ardtweeno NodeNotAuthorised if valid JSON, valid Packet but unauthorised node key
|
105
|
+
assert_raise Ardtweeno::NodeNotAuthorised do
|
106
|
+
@dispatch.store('{"data":[23.5,997.5,65],"key":"500d81aafe637717a52f8650e54206e64da33d27"}')
|
107
|
+
end
|
108
|
+
|
109
|
+
# Valid Packet
|
110
|
+
assert_equal(true, @dispatch.store('{"data":[23.5,997.5,65],"key":"abcdef0"}'))
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
end
|