-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMqttSpecificationComplianceTests.java
231 lines (179 loc) · 9.11 KB
/
MqttSpecificationComplianceTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.slj.mqtt.tree.*;
import java.util.Set;
public class MqttSpecificationComplianceTests extends AbstractMqttTreeTests {
@Test
public void splitTest(){
String[] arr = MqttTreeUtils.splitPath("this/is/a/test");
Assert.assertEquals("array len should match", 7, arr.length);
arr = MqttTreeUtils.splitPath("/");
Assert.assertEquals("array len should match", 1, arr.length);
arr = MqttTreeUtils.splitPath("//");
Assert.assertEquals("array len should match", 2, arr.length);
arr = MqttTreeUtils.splitPath("///");
Assert.assertEquals("array len should match", 3, arr.length);
arr = MqttTreeUtils.splitPath("/another/test/");
Assert.assertEquals("array len should match", 5, arr.length);
}
@Test
public void testMultiLevelSpecificationExamplesNormative() throws MqttTreeException, MqttTreeLimitExceededException {
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("sport/tennis/player1/#", "Client");
Assert.assertTrue("subscription should exist",
tree.search("sport/tennis/player1").size() == 1);
Assert.assertTrue("subscription should exist",
tree.search("sport/tennis/player1/ranking").size() == 1);
Assert.assertTrue("subscription should exist",
tree.search("sport/tennis/player1/score/wimbledon").size() == 1);
}
@Test
public void testMultiLevelSpecificationExamplesNonNormativeExample2() throws MqttTreeException, MqttTreeLimitExceededException {
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("sport/tennis/#", "Client");
}
@Test(expected = MqttTreeInputException.class)
public void testMultiLevelSpecificationExamplesNonNormativeExample3() throws MqttTreeException, MqttTreeLimitExceededException {
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("sport/tennis#", "Client");
}
@Test(expected = MqttTreeInputException.class)
public void testMultiLevelSpecificationExamplesNonNormativeExample4() throws MqttTreeException, MqttTreeLimitExceededException {
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("sport/tennis/#/ranking", "Client");
}
@Test
public void testMultiLevelSpecificationExamplesNonNormativeExample1() throws MqttTreeException, MqttTreeLimitExceededException {
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("sport/#", "Client");
Assert.assertTrue("subscription should exist",
tree.search("sport").size() == 1);
}
@Test
public void testSingleLevelSpecificationExamplesNonNormativeExample1() throws MqttTreeException, MqttTreeLimitExceededException {
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("sport/tennis/+", "Client");
System.err.println(tree.toTree(System.lineSeparator()));
// Assert.assertTrue("subscription should exist",
// tree.search("sport/tennis/player1").size() == 1);
//
// Assert.assertTrue("subscription should exist",
// tree.search("sport/tennis/player2").size() == 1);
Assert.assertEquals("subscription should NOT exist",0,
tree.search("sport/tennis/player1/ranking").size() );
}
@Test
@Ignore("Wildpath needs addressing")
public void testSingleLevelSpecificationExamplesNonNormativeExample1b() throws MqttTreeException, MqttTreeLimitExceededException {
//because the single-level wildcard matches only a single level, “sport/+” does not match “sport” but it does match “sport/”.
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("sport/+", "Client1");
Assert.assertTrue("subscription should NOT exist",
tree.search("sport").size() == 0);
Assert.assertTrue("subscription should exist",
tree.search("sport/").size() == 1);
}
@Test
public void testSingleLevelSpecificationExamplesNonNormativeExample2() throws MqttTreeException, MqttTreeLimitExceededException {
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("+", "Client");
Assert.assertTrue("subscription should exist",
tree.search("foo").size() == 1);
}
@Test
public void testSingleLevelSpecificationExamplesNonNormativeExample3() throws MqttTreeException, MqttTreeLimitExceededException {
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("+/tennis/#", "Client");
Assert.assertTrue("subscription should exist",
tree.search("foo/tennis/player1").size() == 1);
Assert.assertTrue("subscription should NOT exist",
tree.search("foo/ten/player1").size() == 0);
}
@Test(expected = MqttTreeInputException.class)
public void testSingleLevelSpecificationExamplesNonNormativeExample4() throws MqttTreeException, MqttTreeLimitExceededException {
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("sport+", "Client");
}
@Test
public void testSingleLevelSpecificationExamplesNonNormativeExample5() throws MqttTreeException, MqttTreeLimitExceededException {
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("sport/+/player1", "Client");
tree.subscribe("sport/+/player2", "Client2");
Assert.assertTrue("subscription should exist",
tree.search("sport/any/player1").size() == 1);
}
@Test
@Ignore("Wildpath needs addressing")
public void testSingleLevelSpecificationExamplesNonNormativeExample6() throws MqttTreeException, MqttTreeLimitExceededException {
//“/finance” matches “+/+” and “/+”, but not “+”
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("+", "Client1");
tree.subscribe("+/+", "Client2");
tree.subscribe("/+", "Client3");
Set<String> s = tree.search("/finance");
System.err.println(s);
Assert.assertEquals("subscription should exist",
2, s.size());
}
@Test
public void testSingleLevelSpecificationExamplesNonNormativeExample6Edge() throws MqttTreeException, MqttTreeLimitExceededException {
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("+/+", "Client");
System.err.println(tree.getDistinctPaths(true));
Set<String> s = tree.search("/");
System.err.println(s);
Assert.assertEquals("subscription should exist",
1, s.size());
}
@Test(expected = MqttTreeInputException.class)
public void testSemanticExample1() throws MqttTreeException, MqttTreeLimitExceededException {
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("", "Client1");
}
@Test
public void testSemanticExample4() throws MqttTreeException, MqttTreeLimitExceededException {
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("/leading/", "Client1");
tree.subscribe("leading/", "Not1");
tree.subscribe("/leading", "Not2");
Set<String> m = tree.search("/leading/");
Assert.assertEquals("subscription should exist", 1,
m.size());
Assert.assertEquals("subscription should exist",
m.stream().findFirst().get(), "Client1");
}
@Test
public void testSemanticExample5() throws MqttTreeException, MqttTreeLimitExceededException {
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("/", "Client1");
Set<String> m = tree.search("/");
Assert.assertEquals("subscription should exist", 1,
m.size());
Assert.assertEquals("subscription should exist",
m.stream().findFirst().get(), "Client1");
}
@Test
public void testSemanticExample8() throws MqttTreeException, MqttTreeLimitExceededException {
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("ACCOUNTS", "Client1");
tree.subscribe("accounts", "Client2");
Assert.assertEquals("should be 2 distinct branches", 2, tree.getBranchCount());
Assert.assertTrue("subscription should exist",
tree.search("ACCOUNTS").size() == 1);
}
@Test
public void testSemanticExample9() throws MqttTreeException, MqttTreeLimitExceededException {
MqttTree<String> tree = createTreeDefaultConfig();
tree.subscribe("Accounts payable", "Client1");
Assert.assertEquals("should be 1 distinct branches", 1, tree.getBranchCount());
Assert.assertTrue("subscription should exist",
tree.search("Accounts payable").size() == 1);
Assert.assertTrue("subscription should NOT exist",
tree.search("Accounts").size() == 0);
Assert.assertTrue("subscription should NOT exist",
tree.search("payable").size() == 0);
Assert.assertTrue("subscription should NOT exist",
tree.search("Accountspayable").size() == 0);
}
}