@@ -18,27 +18,30 @@ final invalidTestDiscoveryUri =
18
18
Uri .parse ('$testUriScheme ://[::2]/.well-known/wot' );
19
19
final directoryTestUri1 = Uri .parse ('$testUriScheme ://[::3]/.well-known/wot' );
20
20
final directoryTestThingsUri1 = Uri .parse ('$testUriScheme ://[::3]/things' );
21
+ final directoryTestUri2 = Uri .parse ('$testUriScheme ://[::4]/.well-known/wot' );
22
+ final directoryTestThingsUri2 = Uri .parse ('$testUriScheme ://[::4]/things' );
21
23
22
- const validTestTitle = 'Test TD' ;
24
+ const validTestTitle1 = 'Test TD 1 ' ;
23
25
const validTestThingDescription = '''
24
26
{
25
27
"@context": "https://www.w3.org/2022/wot/td/v1.1",
26
- "title": "$validTestTitle ",
28
+ "title": "$validTestTitle1 ",
27
29
"security": "nosec_sc",
28
30
"securityDefinitions": {
29
31
"nosec_sc": {"scheme": "nosec"}
30
32
}
31
33
}
32
34
''' ;
33
35
36
+ const validDirectoryTestTitle1 = 'Test TD 2' ;
34
37
final directoryThingDescription1 = '''
35
38
{
36
39
"@context": [
37
40
"https://www.w3.org/2022/wot/td/v1.1",
38
41
"https://www.w3.org/2022/wot/discovery"
39
42
],
40
43
"@type": "ThingDirectory",
41
- "title": "$validTestTitle ",
44
+ "title": "$validDirectoryTestTitle1 ",
42
45
"security": "nosec_sc",
43
46
"securityDefinitions": {
44
47
"nosec_sc": {"scheme": "nosec"}
@@ -55,6 +58,31 @@ final directoryThingDescription1 = '''
55
58
}
56
59
''' ;
57
60
61
+ const validDirectoryTestTitle2 = 'Test TD 2' ;
62
+ final directoryThingDescription2 = '''
63
+ {
64
+ "@context": [
65
+ "https://www.w3.org/2022/wot/td/v1.1",
66
+ "https://www.w3.org/2022/wot/discovery"
67
+ ],
68
+ "@type": "ThingDirectory",
69
+ "title": "$validDirectoryTestTitle2 ",
70
+ "security": "nosec_sc",
71
+ "securityDefinitions": {
72
+ "nosec_sc": {"scheme": "nosec"}
73
+ },
74
+ "properties": {
75
+ "things": {
76
+ "forms": [
77
+ {
78
+ "href": "$directoryTestThingsUri2 "
79
+ }
80
+ ]
81
+ }
82
+ }
83
+ }
84
+ ''' ;
85
+
58
86
const invalidTestThingDescription = '"Hi there!"' ;
59
87
60
88
void main () {
@@ -70,7 +98,7 @@ void main() {
70
98
final thingDescription =
71
99
await wot.requestThingDescription (validTestDiscoveryUri);
72
100
73
- expect (thingDescription.title, validTestTitle );
101
+ expect (thingDescription.title, validTestTitle1 );
74
102
});
75
103
76
104
test (
@@ -107,11 +135,31 @@ void main() {
107
135
var counter = 0 ;
108
136
await for (final thingDescription in thingDiscoveryProcess) {
109
137
counter++ ;
110
- expect (thingDescription.title, validTestTitle );
138
+ expect (thingDescription.title, validTestTitle1 );
111
139
}
112
140
expect (counter, 1 );
113
141
expect (thingDiscoveryProcess.done, true );
114
142
});
143
+
144
+ test ('should be able to handle invalid TDs during discovery' , () async {
145
+ final servient = Servient (
146
+ clientFactories: [
147
+ _MockedProtocolClientFactory (),
148
+ ],
149
+ );
150
+
151
+ final wot = await servient.start ();
152
+ final thingDiscoveryProcess =
153
+ await wot.exploreDirectory (directoryTestUri2);
154
+
155
+ var counter = 0 ;
156
+ await for (final _ in thingDiscoveryProcess) {
157
+ counter++ ;
158
+ }
159
+ expect (counter, 0 );
160
+ expect (thingDiscoveryProcess.done, true );
161
+ // expect(thingDiscoveryProcess.error, isNotNull);
162
+ });
115
163
});
116
164
}
117
165
@@ -135,6 +183,10 @@ class _MockedProtocolClient implements ProtocolClient {
135
183
return '[$validTestThingDescription ]' .toContent ('application/td+json' );
136
184
}
137
185
186
+ if (href == directoryTestThingsUri2) {
187
+ return '[$invalidTestThingDescription ]' .toContent ('application/td+json' );
188
+ }
189
+
138
190
throw StateError ('Encountered an unknown URI $href .' );
139
191
}
140
192
@@ -152,6 +204,10 @@ class _MockedProtocolClient implements ProtocolClient {
152
204
return directoryThingDescription1.toDiscoveryContent (url);
153
205
}
154
206
207
+ if (url == directoryTestUri2) {
208
+ return directoryThingDescription2.toDiscoveryContent (url);
209
+ }
210
+
155
211
throw StateError ('Encountered invalid URL.' );
156
212
}
157
213
0 commit comments