Skip to content

Commit f3f1eda

Browse files
committed
Add bundle validation test
1 parent 3b4bfa1 commit f3f1eda

File tree

1 file changed

+204
-0
lines changed

1 file changed

+204
-0
lines changed
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
package stix.validation
2+
3+
import io.digitalstate.stix.bundle.BundleableObject
4+
import io.digitalstate.stix.json.StixParserValidationException
5+
import io.digitalstate.stix.json.StixParsers
6+
import spock.lang.Specification
7+
8+
class BundleValidationSpec extends Specification {
9+
10+
def "Validate invalid Bundle JSON"() {
11+
when: "Parsing invalid Bundle JSON "
12+
String json = '''
13+
{
14+
"type": "bundle",
15+
"id": "bundle--830d3023-6c2d-4d91-b1dc-b594959b8d48",
16+
"spec_version": "2.0",
17+
"x_indolently": 232355.30549115842,
18+
"x_signora": "girts",
19+
"x_cementitious": "teetotally expansionism impudently loams solonchak hooligans awry yale snappingly blamed refutably natation schoolgirlish reshapes bought jots protectively waur whimsically pailfuls reddle deprivation quite bituminised thin falls mailman amie hugely crousely summarises saintliest faithfully gap flam eighth perdie choicely phut pears bifilar impetrative specialises yeah vainly religieuse pistole flown flail unplaced spicate repossesses trindles fidge cattishly limbed sural frits generousness hoppings palpitating stultifies topes intercity mat now mews slay bistouries instigating secretively rebuttable legitimate unslung compatibly rayless summarily reassure fresh canny shiftily inarm vernalizing crimp repopulates landscaping fumier abnegations hippophiles chastely bight unbrotherly coldly archaizes",
20+
"x_simular": 940778.1190796582,
21+
"x_orchestrates": 800790,
22+
"x_else": true,
23+
"x_scrumptiously": 189963.7126364522,
24+
"x_entraps": true,
25+
"x_pentathlons": "illustrious coequally forte seditiously topee geotropic undress bumpily dinars admeasure sham pruriently antiquations grate unsayable playable fey courteously lineally highlands stains barbarous euphonized intonate quickly insulators adumbrated wield telly girt acromion remorselessly discrete perigee truculently ducks subzero umpire sapindaceous lieve treats germane snecked clot uncordial lint mow gaiety perplexity starchily polyploidy stopless ablins flongs tongued weans chotts",
26+
"x_ghastfully": 947223,
27+
"x_repurifies": 348826,
28+
"x_lengthways": "precess",
29+
"x_altruistic": "scabious dissipating transmutably malefactors scatophagy ban disimpassioned ought negotiates deign vividly puddocks upstair equalising lampoonist monogenic acrogens nightmarishly dominances fishily lubricous pronely unknightly sass sport frogged clause backwater glumes suffumigates scag nomadic plaguy casket proud connectedly umbonate forbidder derestrict yare outtelling yodelling logicises poulterers breakaways prod fricassees divinizing days devitalize burglarises chomps lalangs entwining medalling interspacing xerography lochia outdoors sighs obnoxious moochers deceptively leadless revocably salving larch hairiest stomatitis outdares indiscreet tenth doomwatchers decretive socialistic manifold counterpoises cornier flaunts ninth confessedly recountal fruitions savorous toothed gorgonise keyless commensurate loads instructor",
30+
"x_tairas": "icier",
31+
"x_mumms": 410175,
32+
"x_marigold": 471065.5268547859,
33+
"x_annex": "overlive publicize sepulcher days kerchiefed objectivist quire whisk posh unsurfaced brooms chalk thrice lysing trichologist mair interplants transmigrated catacumbal when multipurpose bloated days clues strung reinstated bucktooth soppiest reinterring rimming picked charged strop licht dupes why pedicellate detribalized molto constructs obumbrates eradicate ruinable retail vivo throngs myall unnoticed concussive ever sugarless bleeds diffusedly hithermost cleverish crummier whiles fun monadelphous embowelling buoyancy linoleum alway arranges fasciate unbalances malingerers feal deputation federally lamellibranch reconquer beefeaters shill swith expressively mickles rhodic disport cauterized adhibit coves pencils dern likely inflaming neatly",
34+
"objects": [
35+
{
36+
"id": "vulnerability--f5c62801-f9b0-42a7-983e-78ed03560b2b",
37+
"type": "vulnerability",
38+
"created_by_ref": "identity--44fda38a-2010-4510-bd69-3e176224abe3",
39+
"created": "2019-03-21T20:51:39.872Z",
40+
"modified": "2019-03-21T20:51:39.872Z",
41+
"revoked": false,
42+
"labels": [
43+
"amphibrachic",
44+
"longly",
45+
"lode",
46+
"forehanded",
47+
"daglock",
48+
"yes",
49+
"unimportuned",
50+
"garotting",
51+
"loaf",
52+
"ferroconcrete",
53+
"downstairs"
54+
],
55+
"granular_markings": [
56+
{
57+
"marking_ref": "marking-definition--2ad5b13d-c9c7-4bea-9dfa-5b1e5a2194b7",
58+
"selectors": [
59+
"perisarc",
60+
"landslide",
61+
"thorps",
62+
"sonnets",
63+
"dryer",
64+
"skimmings"
65+
],
66+
"x_wifeless": "befitting prescriptivism slums lucubrated paynims mattresses thwacks welts quattrocento videodisk fraudful runed chugs moodier splodges psts swerve slink abloom incages filthily there overrates buss unaccounted promotive sisterliness alleviates wit bloodily smiles influent smut farawayness interbreedings massacres what geophagous scrimps sized inlets pocks melilots verifiers chirper docs inveigh forsooth quadrifid hybridizes doctoral aught whiles stoop around tidily worst choppy stridulous smash heap unsustaining untouchable doggone phut mischarging spasms attributing gratifiers interchanges militating invincibly dytiscid overselling prompt windmills slanderously counsellable"
67+
},
68+
{
69+
"marking_ref": "marking-definition--893f95c0-ea68-4c58-ba83-84c99e6a6eb3",
70+
"selectors": [
71+
"trailingly",
72+
"redesigns",
73+
"amounts",
74+
"hipped",
75+
"metaphrase",
76+
"meanwhile",
77+
"deeply"
78+
],
79+
"x_squirrelly": true,
80+
"x_nominated": true,
81+
"x_toothed": "loads goads quells wipes vagarious lampads sometimes proems flatter distastefully dotard monochromes brief luculent blithely basidial wastes",
82+
"x_cloying": 325664,
83+
"x_loath": "eructations",
84+
"x_lambkin": false,
85+
"x_pauperized": "sordid",
86+
"x_romantics": 831690,
87+
"x_conciliar": "yesterevening brought atomises",
88+
"x_doabs": "consistently",
89+
"x_tierced": false
90+
},
91+
{
92+
"marking_ref": "marking-definition--3697dbf5-c4d0-4c99-ba83-797dcb183387",
93+
"selectors": [
94+
"vivacities"
95+
],
96+
"x_dully": 509046,
97+
"x_fends": "byzants retting tight slap thig golfs robustly setts dentexes grout snide tight epos ways unhorsing ayahs microtones miters explorations chalkpits cuttles tight unchastely systematized surely restructure vixen uptearing clearly overplied floodlighted riverlike worse skirts unconstant unbespoken dent respirable",
98+
"x_bilk": "jargonises",
99+
"x_spang": 533218.6108306068,
100+
"x_smoulders": 193127.38563754444,
101+
"x_otherwhere": 500157,
102+
"x_compactedly": true,
103+
"x_reactively": "distinguish hues flops here maims undiminished condemnable casually engrossments unhusk loads copulating heliograph citruses succulently clam communizing cheesing weighs candelabrum cauld embedments",
104+
"x_explicitly": "swearings maliciously insolubly roaringly laggingly blamed griping undeserving aecidium sorobans transnational assai produces depresses tenderized fumed dutiable dismally carburizing course lest aestivate sump killikinick quintan clomb tinkling thin redips caracol tracklessness worst pitifully demagnetize yet crack unreproved pegh draftiness crawfishes romaines overcloud desiccate caustically pluckily thick rehearsed dyeable regulate entresol flawier wittingly imperium mistiest stannaries lucubrate ditto scorched patting incurs inward cholent stingingly expects screams mercilessly havocs ruffians bead pitched promises gurge hafts glumaceous chartists tressed since seriatim halest gainless imprisons between cognitions",
105+
"x_secretly": true,
106+
"x_banderilla": "pepino",
107+
"x_rewash": 315436.90735046,
108+
"x_convulsively": false,
109+
"x_daftly": "preannounce",
110+
"x_far": 444089.75319646124,
111+
"x_trichinized": true,
112+
"x_counteract": false,
113+
"x_mighty": 404750,
114+
"x_mauve": 123931
115+
}
116+
],
117+
"namee": "megaliths",
118+
"description": "towered left away symphysial cronk artier pocks unobtained tsarist could endarch revengingly nocuously could disquietly"
119+
},
120+
{
121+
"id": "vulnerability--f36853bb-7745-403f-af15-b3c324c057c7",
122+
"type": "vulnerability",
123+
"created_by_ref": "identity--c39f93f0-072f-4c97-a2e4-ec9358ecb093",
124+
"created": "2019-03-21T20:51:39.878Z",
125+
"modified": "2019-03-21T20:51:39.878Z",
126+
"revoked": true,
127+
"external_references": [
128+
{
129+
"source_name": "cognizes",
130+
"description": "smash barbeques shoehorn spang jade",
131+
"url": "http://www.chayscaprice.org",
132+
"hashes": {
133+
"SHA-512": "db39af5838979105222d43fbbd08f7ae8ee064e103c9a9523d8819f395bb2cdd56ecb0af54b4db3569497868556f8642277129280faf031e2dba369bbd5d950c"
134+
},
135+
"external_id": "1c5c3cb8-62b5-4a9b-a920-e3405235cb9a"
136+
},
137+
{
138+
"source_name": "vocative",
139+
"hashes": {
140+
"SHA-256": "e0ccc55e8669f4c6470de2f36553d377096136cebb0752566a4e644c1b79d3ad"
141+
}
142+
}
143+
],
144+
"object_marking_refs": [
145+
"marking-definition--c631a64f-df15-4be2-ad76-4350a4adb4e7"
146+
],
147+
"granular_markings": [
148+
{
149+
"marking_ref": "marking-definition--fe9ff6b4-8548-41d4-b6c5-9c304658581c",
150+
"selectors": [
151+
"discourages",
152+
"quaveringly",
153+
"goad",
154+
"evaded",
155+
"scores",
156+
"wrest",
157+
"lest",
158+
"historicism"
159+
]
160+
},
161+
{
162+
"marking_ref": "marking-definition--60900ddb-a0e2-4508-8d3d-f1122f644856",
163+
"selectors": [
164+
"boot",
165+
"newsier"
166+
]
167+
},
168+
{
169+
"marking_ref": "marking-definition--f941ff40-a304-4f8b-93c0-7cc7bf708540",
170+
"selectors": [
171+
"unovercome",
172+
"pewter",
173+
"cheesing",
174+
"cruelly"
175+
],
176+
"x_obtrusively": false,
177+
"x_motorises": true
178+
}
179+
],
180+
"namee": "beefcakes",
181+
"description": "sober fossilize hypostyle proprietors miscellanists deviceful keloidal fowls mesenteric scotomatous suburbanize nights undiscording inverter pinfolds dang redeems avail underdrawing reallotted segments arytenoid evaded lowering resiliently hereto excessively theologised demonstrative quads seaplanes lushy quirt equipoised typing reground dryer shoreward"
182+
}
183+
]
184+
}
185+
'''
186+
187+
then: "Should have 1 error"
188+
try {
189+
StixParsers.parseBundle(json)
190+
} catch (StixParserValidationException ex) {
191+
assert ex.getConstraintValidations().size() == 2
192+
ex.getConstraintValidations().each { x ->
193+
println "------"
194+
println "Type: ${x.getRootBean().getClass().getSimpleName()}"
195+
println "Object Id: ${x.getRootBean().asType(BundleableObject).getId()}"
196+
println "Message: ${x.getMessage()}"
197+
println "path: ${x.getPropertyPath()}"
198+
println "invalid_value: ${x.getInvalidValue().toString()}"
199+
println "------"
200+
}
201+
}
202+
}
203+
204+
}

0 commit comments

Comments
 (0)