-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #281 from art-community/fix/json-parsing
fix json parsing
- Loading branch information
Showing
2 changed files
with
244 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
233 changes: 233 additions & 0 deletions
233
application-test/src/test/groovy/ru/art/test/specification/json/JsonSpecification.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
package ru.art.test.specification.json | ||
|
||
|
||
import spock.lang.Specification | ||
|
||
import static ru.art.core.constants.StringConstants.* | ||
import static ru.art.json.descriptor.JsonEntityReader.readJson | ||
import static ru.art.json.descriptor.JsonEntityWriter.writeJson | ||
|
||
|
||
class JsonSpecification extends Specification { | ||
def "should correctly parse/write json"() { | ||
setup: | ||
def json = | ||
""" | ||
{ | ||
"result": [ | ||
{ | ||
"data": [ | ||
{ | ||
"key": "ÔÈÎ", | ||
"value": "ÞÐÎÂÀ ÀÍÀÑÒÀÑÈß Âß×ÅÑËÀÂÎÂÍÀ" | ||
}, | ||
{ | ||
"key": "Áàëëàíñ", | ||
"value": "-2084.06" | ||
}, | ||
{ | ||
"key": "Ëîãèí PPPoE", | ||
"value": "qcnsua6p5u" | ||
} | ||
], | ||
"type": "kv", | ||
"title": "Èíôîðìàöèÿ î êëèåíòå" | ||
}, | ||
{ | ||
"data": [ | ||
[ | ||
{ | ||
"key": "Èìÿ ñåðâèñà", | ||
"value": "i0011251363" | ||
}, | ||
{ | ||
"key": "Òèï ñåðâèñà", | ||
"value": "INTERNET" | ||
}, | ||
{ | ||
"key": "Òàðèôíûé ïëàí", | ||
"value": "[ÐÒÊ] xPON Âñ¸ âìåñòå \\"Äëÿ íà÷àëà\\" ÌÎÍÎ 100Ìáèò/ñ" | ||
}, | ||
{ | ||
"key": "Ñêîðîñòü ïî òàðèôó [Ìáèò/ñåê]", | ||
"value": "100" | ||
} | ||
] | ||
], | ||
"type": "table", | ||
"title": "Èíôîðìàöèÿ îá óñëóãàõ" | ||
}, | ||
{ | ||
"data": [ | ||
{ | ||
"key": "Äàííûå ÒÓ", | ||
"value": "RST-TCN-GIRNOV-PON1-5608-001-013_01-06 [] âîëîêíî âîëîêíî41-48/43" | ||
}, | ||
{ | ||
"key": "Îáîðóäîâàíèå ÒÓ", | ||
"value": "RST-TCN-GIRNOV-PON1-5608-001-013_01-06" | ||
}, | ||
{ | ||
"key": "Ïîðò ÒÓ", | ||
"value": "41/48/43" | ||
}, | ||
{ | ||
"key": "Àâòîðèçîâàí ñ", | ||
"value": "RST-TCN-GIRNOV-PON1-5608 xpon 0/1/0/1:1.1.2000" | ||
}, | ||
{ | ||
"key": "Îáîðóäîâàíèå ïîñëåäíåé ìèëè", | ||
"value": "RST-TCN-GIRNOV-PON1-5608" | ||
}, | ||
{ | ||
"key": "Ïîðò ïîñëåäíåé ìèëè", | ||
"value": "0/1/1" | ||
} | ||
], | ||
"type": "kv", | ||
"title": "Òåõíè÷åñêèé ó÷åò" | ||
}, | ||
{ | ||
"data": [ | ||
{ | ||
"key": "×èñëî ñåññèé çà ïîñëåäíèé ÷àñ", | ||
"value": "0" | ||
}, | ||
{ | ||
"key": "×èñëî ñåññèé çà ïîñëåäíèå 3 ÷àñà", | ||
"value": "0" | ||
}, | ||
{ | ||
"key": "×èñëî ñåññèé çà ïîñëåäíèå ñóòêè", | ||
"value": "3" | ||
}, | ||
{ | ||
"key": "×èñëî ñåññèé çà ïîñëåäíèå 3-îå ñóòîê", | ||
"value": "3" | ||
} | ||
], | ||
"type": "kv", | ||
"title": "Ñòàòèñòèêà ñåññèé" | ||
}, | ||
{ | ||
"data": [ | ||
{ | ||
"key": "Ëîãèí", | ||
"value": "qcnsua6p5u" | ||
}, | ||
{ | ||
"key": "IP", | ||
"value": "46.61.84.219" | ||
}, | ||
{ | ||
"key": "Íà÷àëî", | ||
"value": "2020-02-25T08:17:29.000Z" | ||
}, | ||
{ | ||
"key": "Êîíåö", | ||
"value": "2020-02-28T08:17:30.000Z" | ||
}, | ||
{ | ||
"key": "Àêòèâíà", | ||
"value": "Íåò", | ||
"estimate": "2" | ||
} | ||
], | ||
"type": "kv", | ||
"title": "Ïîñëåäíÿÿ ñåññèÿ" | ||
}, | ||
{ | ||
"data": [ | ||
{ | ||
"key": "Cîñòîÿíèå ïëàòû", | ||
"value": "ðàáîòàåò êîððåêíî", | ||
"estimate": "0" | ||
}, | ||
{ | ||
"key": "Àäìèíèñòðàòèâíîå ñîñòîÿíèå ïîðòà", | ||
"value": "âêëþ÷åí", | ||
"estimate": "0" | ||
}, | ||
{ | ||
"key": "Îïåðàòèâíîå ñîñòîÿíèå ïîðòà", | ||
"value": "âêëþ÷åí", | ||
"estimate": "0" | ||
}, | ||
{ | ||
"key": "Ñòàòóñ ïîäêëþ÷åíèÿ ONT", | ||
"value": "îòêëþ÷åí", | ||
"estimate": "1" | ||
}, | ||
{ | ||
"key": "Îïèñàíèå", | ||
"value": "auto-add-Mon-Jan-13-12-10-18-202" | ||
}, | ||
{ | ||
"key": "Äëèíà ëèíèè [km]", | ||
"value": "0" | ||
}, | ||
{ | ||
"key": "Çàòóõàíèå [dB]", | ||
"value": "0", | ||
"estimate": "0" | ||
}, | ||
{ | ||
"key": "SN", | ||
"value": "5A544547C8BB20DF (ZTEG-C8BB20DF)" | ||
} | ||
], | ||
"type": "kv", | ||
"title": "Ñîñòîÿíèå ïîðòà" | ||
}, | ||
{ | ||
"data": [], | ||
"type": "table", | ||
"title": "Òàáëèöà MAC-àäðåñîâ" | ||
}, | ||
{ | ||
"data": [ | ||
[] | ||
], | ||
"type": "table1", | ||
"title": "Ïîðòû ONT" | ||
} | ||
], | ||
"request_id": "6778335", | ||
"conclusions": [ | ||
{ | ||
"conclusion_text": "Äàííûå ÒÓ ïîëó÷åíû îáîèìè ìåòîäàìè íî íå ðàâíû.", | ||
"conclusion_level": 2, | ||
"conclusion_title": "Òåõíè÷åñêèé ó÷åò" | ||
} | ||
], | ||
"request_created": "2020-05-12T19:43:49+0000" | ||
}""" | ||
when: | ||
def value = readJson(json) | ||
|
||
then: | ||
writeJson(value).replaceAll(NEW_LINE, EMPTY_STRING).replaceAll(SPACE, EMPTY_STRING) == json.replaceAll(NEW_LINE, EMPTY_STRING).replaceAll(SPACE, EMPTY_STRING) | ||
} | ||
|
||
} |