Skip to content

Commit 0aa94ee

Browse files
committed
Fixed issue with CJ_LINK
and updated TEST_CJ_SUITE
1 parent 9f95186 commit 0aa94ee

File tree

2 files changed

+95
-107
lines changed

2 files changed

+95
-107
lines changed

library/converter/cj_link_json_converter.e

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ feature -- Conversion
3939
Result.set_name (l_ucs)
4040
end
4141
if attached {STRING_32} json_to_object (j.item (prompt_key), Void) as l_ucs then
42-
Result.set_rel (l_ucs)
42+
Result.set_prompt (l_ucs)
4343
end
4444
if attached {STRING_32} json_to_object (j.item (render_key), Void) as l_ucs then
4545
Result.set_render (l_ucs)

test/test_cj_suite.e

+94-106
Original file line numberDiff line numberDiff line change
@@ -38,89 +38,87 @@ feature -- Test routines
3838
note
3939
uri: "http://amundsen.com/media-types/collection/examples/#ex-minimal"
4040
local
41-
l_doc: detachable CJ_DOCUMENT
41+
l_coll: detachable CJ_COLLECTION
4242
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")
4848
end
4949
end
5050

5151
test_collection_representation
5252
note
5353
uri: "http://amundsen.com/media-types/collection/examples/#ex-collection"
5454
local
55-
l_doc: detachable CJ_DOCUMENT
55+
l_coll: detachable CJ_COLLECTION
5656
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
6060
--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/")
6262
--version
63-
assert ("Expected version 1.0", ll_doc.collection.version ~ "1.0")
63+
assert ("Expected version 1.0", l_coll.version ~ "1.0")
6464

6565
-- 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
6868
assert ("Expect only one element", ll_links.count = 1)
6969
assert ("Expected rel value:", ll_links.at (1).rel ~ "feed")
7070
assert ("Expected href value:", ll_links.at (1).href ~ "http://example.org/friends/rss")
7171
end
7272

7373
-- 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
7676
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")
8888
end
89-
assert ("Expected prompt:Full Names", ll_data.at (1).prompt ~ "Full Name")
90-
end
9189

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")
10097
end
101-
assert ("Expected prompt:Blog", ll_links.at (1).prompt ~ "Blog")
98+
else
99+
assert ("Expect has element at 3", False)
102100
end
103101
end
104102

105103
-- 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
108106
assert ("Expected size 1", ll_queries.count = 1)
109107
assert ("Expected rel:search", ll_queries.at (1).rel ~ "search")
110108
assert ("Expected href:http://example.org/friends/search", ll_queries.at (1).href ~ "http://example.org/friends/search")
111109

112110
--data
113111
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
115113
assert ("Expected size 1", ll_data.count = 1)
116114
assert ("Expected name:search", ll_data.at (1).name ~ "search")
117115
assert ("Expected vale:", ll_data.at (1).value ~ "")
118116
end
119117
end
120118

121119
-- 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
124122
assert ("Expected size 4", ll_templates.data.count = 4)
125123
assert ("Expected name:avatar", ll_templates.data.at (4).name ~ "avatar")
126124
assert ("Expected value:", ll_templates.data.at (4).value ~ "")
@@ -133,17 +131,17 @@ feature -- Test routines
133131
note
134132
uri:"http://amundsen.com/media-types/collection/examples/#ex-item"
135133
local
136-
l_doc : detachable CJ_DOCUMENT
134+
l_coll : detachable CJ_COLLECTION
137135
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")
143141

144142
-- 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
147145
assert("Expected size 1", l_items.count = 1)
148146
assert("Expected href:http://example.org/friends/jdoe", l_items.at(1).href ~ "http://example.org/friends/jdoe")
149147
assert("Expected data array", l_items.at (1).data /= Void)
@@ -157,16 +155,16 @@ feature -- Test routines
157155
note
158156
uri:"http://amundsen.com/media-types/collection/examples/#ex-queries"
159157
local
160-
l_doc : detachable CJ_DOCUMENT
158+
l_coll : detachable CJ_COLLECTION
161159
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/")
167165
-- 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
170168
assert("Expected size 1", l_queries.count = 1)
171169
assert("Expected rel", l_queries.at (1).rel ~ "search")
172170
assert("Expected href", l_queries.at (1).href ~ "http://example.org/friends/search")
@@ -182,16 +180,16 @@ feature -- Test routines
182180
note
183181
uri:"http://amundsen.com/media-types/collection/examples/#ex-template"
184182
local
185-
l_doc : detachable CJ_DOCUMENT
183+
l_coll : detachable CJ_COLLECTION
186184
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/")
192190
-- 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
195193
assert ("Expect 4 elements", l_template.data.count = 4)
196194
end
197195
end
@@ -201,16 +199,16 @@ feature -- Test routines
201199
note
202200
uri:"http://amundsen.com/media-types/collection/examples/#ex-error"
203201
local
204-
l_doc : detachable CJ_DOCUMENT
202+
l_coll : detachable CJ_COLLECTION
205203
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/")
211209
-- 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
214212
assert("Expected title: Server Error", l_error.title ~ "Server Error")
215213
assert("Expected code: X1C2", l_error.code ~ "X1C2")
216214
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
238236

239237
json_to_cjtempalte (fn: STRING): detachable CJ_TEMPLATE
240238
local
241-
dc: JSON_DATA_CONVERTER
242-
tc: JSON_TEMPLATE_CONVERTER
239+
dc: CJ_DATA_JSON_CONVERTER
240+
tc: CJ_TEMPLATE_JSON_CONVERTER
243241
do
244242
create dc.make
245243
create tc.make
@@ -254,43 +252,33 @@ feature -- Implementation
254252
end
255253
end
256254

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
268256
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)
285258
if attached json_file_from (fn) as json_file then
286259
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
289262
end
290263
end
291264
end
292265
end
293266

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+
294282
json_value: detachable JSON_VALUE
295283

296284
file_reader: JSON_FILE_READER

0 commit comments

Comments
 (0)