@@ -38,89 +38,87 @@ feature -- Test routines
38
38
note
39
39
uri : " http://amundsen.com/media-types/collection/examples/#ex-minimal"
40
40
local
41
- l_doc : detachable CJ_DOCUMENT
41
+ l_coll : detachable CJ_COLLECTION
42
42
do
43
- l_doc := json_to_cj (" minimal_representation.json" )
44
- assert (" Not Void" , l_doc /= Void )
45
- if attached { CJ_DOCUMENT } l_doc as ll_doc then
46
- assert (" Expected href value http://example.org/friends/" , ll_doc . collection .href ~ " http://example.org/friends/" )
47
- assert (" Expected version 1.0" , ll_doc . collection .version ~ " 1.0" )
43
+ l_coll := json_to_cj (" minimal_representation.json" )
44
+ assert (" Not Void" , l_coll /= Void )
45
+ if l_coll /= Void then
46
+ assert (" Expected href value http://example.org/friends/" , l_coll .href ~ " http://example.org/friends/" )
47
+ assert (" Expected version 1.0" , l_coll .version ~ " 1.0" )
48
48
end
49
49
end
50
50
51
51
test_collection_representation
52
52
note
53
53
uri : " http://amundsen.com/media-types/collection/examples/#ex-collection"
54
54
local
55
- l_doc : detachable CJ_DOCUMENT
55
+ l_coll : detachable CJ_COLLECTION
56
56
do
57
- l_doc := json_to_cj (" collection_representation.json" )
58
- assert (" Document is not void" , l_doc /= Void )
59
- if attached { CJ_DOCUMENT } l_doc as ll_doc then
57
+ l_coll := json_to_cj (" collection_representation.json" )
58
+ assert (" Collection is not void" , l_coll /= Void )
59
+ if l_coll /= Void then
60
60
-- href
61
- assert (" Expected href value http://example.org/friends/" , ll_doc . collection .href ~ " http://example.org/friends/" )
61
+ assert (" Expected href value http://example.org/friends/" , l_coll .href ~ " http://example.org/friends/" )
62
62
-- version
63
- assert (" Expected version 1.0" , ll_doc . collection .version ~ " 1.0" )
63
+ assert (" Expected version 1.0" , l_coll .version ~ " 1.0" )
64
64
65
65
-- links
66
- assert (" Links is not void" , ll_doc . collection .links /= Void )
67
- if attached {LINKED_LIST [CJ_LINK ]} ll_doc . collection .links as ll_links then
66
+ assert (" Links is not void" , l_coll .links /= Void )
67
+ if attached {LIST [CJ_LINK ]} l_coll .links as ll_links then
68
68
assert (" Expect only one element" , ll_links .count = 1 )
69
69
assert (" Expected rel value:" , ll_links .at (1 ).rel ~ " feed" )
70
70
assert (" Expected href value:" , ll_links .at (1 ).href ~ " http://example.org/friends/rss" )
71
71
end
72
72
73
73
-- items
74
- assert (" Items is not void" , ll_doc . collection .items /= Void )
75
- if attached {LINKED_LIST [CJ_ITEM ]} ll_doc . collection .items as ll_items then
74
+ assert (" Items is not void" , l_coll .items /= Void )
75
+ if attached {LIST [CJ_ITEM ]} l_coll .items as ll_items then
76
76
assert (" Expect three elements" , ll_items .count = 3 )
77
- -- href
78
- assert ( " Expected href http://example.org/friends/rwilliams " , ll_items . at ( 3 ). href ~ " http://example.org/friends/rwilliams " )
79
-
80
- -- data
81
- assert ( " data is not void " , ll_items . at ( 3 ). data /= Void )
82
- if attached { LINKED_LIST [ CJ_DATA ]} ll_items . at ( 3 ) .data as ll_data then
83
- assert ( " Expected size 2 " , ll_data . count = 2 )
84
- assert (" Expected name:full-name " , ll_data .at ( 1 ). name ~ " full-name " )
85
- assert (" Expected value:R. Williams " , ll_data .at (1 ).value ~ " R. Williams " )
86
- check
87
- ll_data .at (1 ).prompt /= Void
77
+ if attached ll_items . at ( 3 ) as l_item_ 3 then
78
+ -- href
79
+ assert ( " Expected href http://example.org/friends/rwilliams " , l_item_ 3 . href ~ " http://example.org/friends/rwilliams " )
80
+
81
+ -- data
82
+ assert ( " data is not void " , l_item_ 3 .data /= Void )
83
+ if attached { LIST [ CJ_DATA ]} l_item_ 3 . data as ll_data then
84
+ assert (" Expected size 2 " , ll_data .count = 2 )
85
+ assert (" Expected name 1:full-name " , ll_data .at (1 ).name ~ " full-name " )
86
+ assert ( " Expected value 1:R. Williams " , ll_data . at ( 1 ). value ~ " R. Williams " )
87
+ assert ( " Expected prompt:Full Names " , ll_data .at (1 ).prompt ~ " Full Name " )
88
88
end
89
- assert (" Expected prompt:Full Names" , ll_data .at (1 ).prompt ~ " Full Name" )
90
- end
91
89
92
- -- links
93
- assert (" links is not void" , ll_items .at (3 ).links /= Void )
94
- if attached {LINKED_LIST [CJ_LINK ]} ll_items .at (3 ).links as ll_links then
95
- assert (" Expected size 2" , ll_links .count = 2 )
96
- assert (" Expected rel:blog" , ll_links .at (1 ).rel ~ " blog" )
97
- assert (" Expected href:http://examples.org/blogs/rwilliams" , ll_links .at (1 ).href ~ " http://examples.org/blogs/rwilliams" )
98
- check
99
- ll_links .at (1 ).prompt /= Void
90
+ -- links
91
+ assert (" links is not void" , l_item_ 3 .links /= Void )
92
+ if attached {LIST [CJ_LINK ]} l_item_ 3 .links as ll_links then
93
+ assert (" Expected size 2" , ll_links .count = 2 )
94
+ assert (" Expected rel 1: blog" , ll_links .at (1 ).rel ~ " blog" )
95
+ assert (" Expected href 1: http://examples.org/blogs/rwilliams" , ll_links .at (1 ).href ~ " http://examples.org/blogs/rwilliams" )
96
+ assert (" Expected prompt:Blog" , ll_links .at (1 ).prompt ~ " Blog" )
100
97
end
101
- assert (" Expected prompt:Blog" , ll_links .at (1 ).prompt ~ " Blog" )
98
+ else
99
+ assert (" Expect has element at 3" , False )
102
100
end
103
101
end
104
102
105
103
-- queries
106
- assert (" Queries is not void" , ll_doc . collection .queries /= Void )
107
- if attached {LINKED_LIST [CJ_QUERY ]} ll_doc . collection .queries as ll_queries then
104
+ assert (" Queries is not void" , l_coll .queries /= Void )
105
+ if attached {LIST [CJ_QUERY ]} l_coll .queries as ll_queries then
108
106
assert (" Expected size 1" , ll_queries .count = 1 )
109
107
assert (" Expected rel:search" , ll_queries .at (1 ).rel ~ " search" )
110
108
assert (" Expected href:http://example.org/friends/search" , ll_queries .at (1 ).href ~ " http://example.org/friends/search" )
111
109
112
110
-- data
113
111
assert (" Data is not void" , ll_queries .at (1 ).data /= Void )
114
- if attached {LINKED_LIST [CJ_DATA ]} ll_queries .at (1 ).data as ll_data then
112
+ if attached {LIST [CJ_DATA ]} ll_queries .at (1 ).data as ll_data then
115
113
assert (" Expected size 1" , ll_data .count = 1 )
116
114
assert (" Expected name:search" , ll_data .at (1 ).name ~ " search" )
117
115
assert (" Expected vale:" , ll_data .at (1 ).value ~ " " )
118
116
end
119
117
end
120
118
121
119
-- templates
122
- assert (" Template is not void" , ll_doc . collection .template /= Void )
123
- if attached {CJ_TEMPLATE } ll_doc . collection .template as ll_templates then
120
+ assert (" Template is not void" , l_coll .template /= Void )
121
+ if attached {CJ_TEMPLATE } l_coll .template as ll_templates then
124
122
assert (" Expected size 4" , ll_templates .data .count = 4 )
125
123
assert (" Expected name:avatar" , ll_templates .data .at (4 ).name ~ " avatar" )
126
124
assert (" Expected value:" , ll_templates .data .at (4 ).value ~ " " )
@@ -133,17 +131,17 @@ feature -- Test routines
133
131
note
134
132
uri :" http://amundsen.com/media-types/collection/examples/#ex-item"
135
133
local
136
- l_doc : detachable CJ_DOCUMENT
134
+ l_coll : detachable CJ_COLLECTION
137
135
do
138
- l_doc := json_to_cj (" item_representation.json" )
139
- assert (" Not Void" , l_doc /= Void )
140
- if attached { CJ_DOCUMENT } l_doc as ll_doc then
141
- assert (" Expected href value http://example.org/friends/" , ll_doc . collection .href ~ " http://example.org/friends/" )
142
- assert (" Expected version 1.0" , ll_doc . collection .version ~ " 1.0" )
136
+ l_coll := json_to_cj (" item_representation.json" )
137
+ assert (" Not Void" , l_coll /= Void )
138
+ if l_coll /= Void then
139
+ assert (" Expected href value http://example.org/friends/" , l_coll .href ~ " http://example.org/friends/" )
140
+ assert (" Expected version 1.0" , l_coll .version ~ " 1.0" )
143
141
144
142
-- items
145
- assert (" Items is not void" , ll_doc . collection .items /= Void )
146
- if attached {LINKED_LIST [CJ_ITEM ]} ll_doc . collection .items as l_items then
143
+ assert (" Items is not void" , l_coll .items /= Void )
144
+ if attached {LIST [CJ_ITEM ]} l_coll .items as l_items then
147
145
assert (" Expected size 1" , l_items .count = 1 )
148
146
assert (" Expected href:http://example.org/friends/jdoe" , l_items .at (1 ).href ~ " http://example.org/friends/jdoe" )
149
147
assert (" Expected data array" , l_items .at (1 ).data /= Void )
@@ -157,16 +155,16 @@ feature -- Test routines
157
155
note
158
156
uri :" http://amundsen.com/media-types/collection/examples/#ex-queries"
159
157
local
160
- l_doc : detachable CJ_DOCUMENT
158
+ l_coll : detachable CJ_COLLECTION
161
159
do
162
- l_doc := json_to_cj (" queries_representation.json" )
163
- assert (" Not Void" , l_doc /= Void )
164
- if attached { CJ_DOCUMENT } l_doc as ll_doc then
165
- assert (" Expected version 1.0" , ll_doc . collection .version ~ " 1.0" )
166
- assert (" Expected href value http://example.org/friends/" , ll_doc . collection .href ~ " http://example.org/friends/" )
160
+ l_coll := json_to_cj (" queries_representation.json" )
161
+ assert (" Not Void" , l_coll /= Void )
162
+ if l_coll /= Void then
163
+ assert (" Expected version 1.0" , l_coll .version ~ " 1.0" )
164
+ assert (" Expected href value http://example.org/friends/" , l_coll .href ~ " http://example.org/friends/" )
167
165
-- queries
168
- assert (" Queries is not void" , ll_doc . collection .queries /= Void )
169
- if attached {LINKED_LIST [CJ_QUERY ]} ll_doc . collection .queries as l_queries then
166
+ assert (" Queries is not void" , l_coll .queries /= Void )
167
+ if attached {LIST [CJ_QUERY ]} l_coll .queries as l_queries then
170
168
assert (" Expected size 1" , l_queries .count = 1 )
171
169
assert (" Expected rel" , l_queries .at (1 ).rel ~ " search" )
172
170
assert (" Expected href" , l_queries .at (1 ).href ~ " http://example.org/friends/search" )
@@ -182,16 +180,16 @@ feature -- Test routines
182
180
note
183
181
uri :" http://amundsen.com/media-types/collection/examples/#ex-template"
184
182
local
185
- l_doc : detachable CJ_DOCUMENT
183
+ l_coll : detachable CJ_COLLECTION
186
184
do
187
- l_doc := json_to_cj (" template_representation.json" )
188
- assert (" Not Void" , l_doc /= Void )
189
- if attached { CJ_DOCUMENT } l_doc as ll_doc then
190
- assert (" Expected version 1.0" , ll_doc . collection .version ~ " 1.0" )
191
- assert (" Expected href value http://example.org/friends/" , ll_doc . collection .href ~ " http://example.org/friends/" )
185
+ l_coll := json_to_cj (" template_representation.json" )
186
+ assert (" Not Void" , l_coll /= Void )
187
+ if l_coll /= Void then
188
+ assert (" Expected version 1.0" , l_coll .version ~ " 1.0" )
189
+ assert (" Expected href value http://example.org/friends/" , l_coll .href ~ " http://example.org/friends/" )
192
190
-- template
193
- assert (" Template is not void" , ll_doc . collection .template /= Void )
194
- if attached {CJ_TEMPLATE } ll_doc . collection .template as l_template then
191
+ assert (" Template is not void" , l_coll .template /= Void )
192
+ if attached {CJ_TEMPLATE } l_coll .template as l_template then
195
193
assert (" Expect 4 elements" , l_template .data .count = 4 )
196
194
end
197
195
end
@@ -201,16 +199,16 @@ feature -- Test routines
201
199
note
202
200
uri :" http://amundsen.com/media-types/collection/examples/#ex-error"
203
201
local
204
- l_doc : detachable CJ_DOCUMENT
202
+ l_coll : detachable CJ_COLLECTION
205
203
do
206
- l_doc := json_to_cj (" error_representation.json" )
207
- assert (" Not Void" , l_doc /= Void )
208
- if attached { CJ_DOCUMENT } l_doc as ll_doc then
209
- assert (" Expected version 1.0" , ll_doc . collection .version ~ " 1.0" )
210
- assert (" Expected href value http://example.org/friends/" , ll_doc . collection .href ~ " http://example.org/friends/" )
204
+ l_coll := json_to_cj (" error_representation.json" )
205
+ assert (" Not Void" , l_coll /= Void )
206
+ if l_coll /= Void then
207
+ assert (" Expected version 1.0" , l_coll .version ~ " 1.0" )
208
+ assert (" Expected href value http://example.org/friends/" , l_coll .href ~ " http://example.org/friends/" )
211
209
-- template
212
- assert (" Error is not void" , ll_doc . collection .error /= Void )
213
- if attached {CJ_ERROR } ll_doc . collection .error as l_error then
210
+ assert (" Error is not void" , l_coll .error /= Void )
211
+ if attached {CJ_ERROR } l_coll .error as l_error then
214
212
assert (" Expected title: Server Error" , l_error .title ~ " Server Error" )
215
213
assert (" Expected code: X1C2" , l_error .code ~ " X1C2" )
216
214
assert (" Expected message: The server have encountered an error, please wait and try again" , l_error .message ~ " The server have encountered an error, please wait and try again." )
@@ -238,8 +236,8 @@ feature -- Implementation
238
236
239
237
json_to_cjtempalte (fn : STRING ): detachable CJ_TEMPLATE
240
238
local
241
- dc : JSON_DATA_CONVERTER
242
- tc : JSON_TEMPLATE_CONVERTER
239
+ dc : CJ_DATA_JSON_CONVERTER
240
+ tc : CJ_TEMPLATE_JSON_CONVERTER
243
241
do
244
242
create dc .make
245
243
create tc .make
@@ -254,43 +252,33 @@ feature -- Implementation
254
252
end
255
253
end
256
254
257
- json_to_cj (fn : STRING ): detachable CJ_DOCUMENT
258
- local
259
- jdc : JSON_DOCUMENT_CONVERTER
260
- cc : JSON_COLLECTION_CONVERTER
261
- dc : JSON_DATA_CONVERTER
262
- ec : JSON_ERROR_CONVERTER
263
- ic : JSON_ITEM_CONVERTER
264
- qc : JSON_QUERY_CONVERTER
265
- tc : JSON_TEMPLATE_CONVERTER
266
- lc : JSON_LINK_CONVERTER
267
- l_col : CJ_COLLECTION
255
+ json_to_cj (fn : STRING ): detachable CJ_COLLECTION
268
256
do
269
- create jdc .make
270
- create cc .make
271
- create dc .make
272
- create ec .make
273
- create ic .make
274
- create qc .make
275
- create tc .make
276
- create lc .make
277
- json .add_converter (jdc )
278
- json .add_converter (cc )
279
- json .add_converter (dc )
280
- json .add_converter (ec )
281
- json .add_converter (ic )
282
- json .add_converter (qc )
283
- json .add_converter (tc )
284
- json .add_converter (lc )
257
+ initialize_converters (json )
285
258
if attached json_file_from (fn ) as json_file then
286
259
if attached json_value_from_file (json_file ) as jv then
287
- if attached {CJ_DOCUMENT } json .object (jv , " CJ_DOCUMENT " ) as l_doc then
288
- Result := l_doc
260
+ if attached {CJ_COLLECTION } json .object (jv , " CJ_COLLECTION " ) as l_col then
261
+ Result := l_col
289
262
end
290
263
end
291
264
end
292
265
end
293
266
267
+ initialize_converters (j : like json )
268
+ -- Initialize json converters `j'
269
+ do
270
+ j .add_converter (create {CJ_COLLECTION_JSON_CONVERTER }.make )
271
+ j .add_converter (create {CJ_DATA_JSON_CONVERTER }.make )
272
+ j .add_converter (create {CJ_ERROR_JSON_CONVERTER }.make )
273
+ j .add_converter (create {CJ_ITEM_JSON_CONVERTER }.make )
274
+ j .add_converter (create {CJ_QUERY_JSON_CONVERTER }.make )
275
+ j .add_converter (create {CJ_TEMPLATE_JSON_CONVERTER }.make )
276
+ j .add_converter (create {CJ_LINK_JSON_CONVERTER }.make )
277
+ if j .converter_for (create {ARRAYED_LIST [detachable ANY ]}.make (0 )) = Void then
278
+ j .add_converter (create {CJ_ARRAYED_LIST_JSON_CONVERTER }.make )
279
+ end
280
+ end
281
+
294
282
json_value : detachable JSON_VALUE
295
283
296
284
file_reader : JSON_FILE_READER
0 commit comments