package Ġcom . github . han se ter . json . editor Ċ Ċ import Ġjavafx . scene . control . DatePicker Ċ import Ġjavafx . scene . control . TextField Ċ import Ġjavafx . stage . Stage Ċ import Ġorg . hamcrest . Matcher Assert . assertThat Ċ import Ġorg . hamcrest . Matchers .` is ` Ċ import Ġorg . hamcrest . Matchers . null Value Ċ import Ġorg . json . JSONObject Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġorg . test fx . framework . junit 5 . Application Extension Ċ import Ġorg . test fx . framework . junit 5 . Start Ċ import Ġorg . test fx . util . WaitFor Async Utils Ċ Ċ @ Extend With ( Application Extension :: class ) Ċ class ĠString Test Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġeditor : ĠJson Properties Editor ĊĊĠĠĠ Ġ@ Start ĊĠĠĠ Ġfun Ġstart ( stage : ĠStage ) Ġ{ ĊĠĠĠĠĠĠĠ Ġeditor Ġ= ĠJson Properties Editor () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdisplay Existing Value () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġschema Ġ= ĠJSONObject (""" {" type ":" object "," properties ":{" string ":{" type ":" string "}} } """) ĊĠĠĠĠĠĠĠ Ġeditor . display (" 1 ", Ġ" 1 ", ĠJSONObject (). put (" string ", Ġ" foobar "), Ġschema ) Ġ{ Ġit Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġitem Table Ġ= Ġeditor . getItem Table () ĊĠĠĠĠĠĠĠ Ġval Ġstring Control Ġ= Ġeditor . get Control In Table (" string ") Ġas ĠTextField ĊĠĠĠĠĠĠĠ ĠassertThat ( string Control . text , Ġ` is ` (" foobar ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmodify Value By TextInput () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġschema Ġ= ĠJSONObject (""" {" type ":" object "," properties ":{" string ":{" type ":" string "}} } """) ĊĠĠĠĠĠĠĠ Ġval Ġdata Ġ= ĠJSONObject (). put (" string ", Ġ" foobar ") ĊĠĠĠĠĠĠĠ Ġeditor . display (" 1 ", Ġ" 1 ", Ġdata , Ġschema ) Ġ{ Ġit Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġitem Table Ġ= Ġeditor . getItem Table () ĊĠĠĠĠĠĠĠ Ġval Ġstring Control Ġ= Ġeditor . get Control In Table (" string ") Ġas ĠTextField ĊĠĠĠĠĠĠĠ Ġstring Control . text Ġ= Ġ" something " ĊĠĠĠĠĠĠĠ ĠassertThat ( data . getString (" string "), Ġ` is ` (" something ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmin Length Validation () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġschema Ġ= ĠJSONObject (""" {" type ":" object "," properties ":{" string ":{" type ":" string "," min Length ": 1 5 }}} """) ĊĠĠĠĠĠĠĠ Ġval Ġdata Ġ= ĠJSONObject (). put (" string ", Ġ" foobar ") ĊĠĠĠĠĠĠĠ Ġeditor . display (" 1 ", Ġ" 1 ", Ġdata , Ġschema ) Ġ{ Ġit Ġ} ĊĠĠĠĠĠĠĠ ĠWaitFor Async Utils . waitFor Fx Events () ĊĠĠĠĠĠĠĠ ĠassertThat ( editor . valid . get (), Ġ` is `( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmin Length Validation After Change () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġschema Ġ= ĠJSONObject (""" {" type ":" object "," properties ":{" string ":{" type ":" string "," min Length ": 5 }}} """) ĊĠĠĠĠĠĠĠ Ġval Ġdata Ġ= ĠJSONObject (). put (" string ", Ġ" foobar ") ĊĠĠĠĠĠĠĠ Ġeditor . display (" 1 ", Ġ" 1 ", Ġdata , Ġschema ) Ġ{ Ġit Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġstring Control Ġ= Ġeditor . get Control In Table (" string ") Ġas ĠTextField ĊĠĠĠĠĠĠĠ ĠWaitFor Async Utils . waitFor Fx Events () ĊĠĠĠĠĠĠĠ ĠassertThat ( editor . valid . get (), Ġ` is `( true )) ĊĠĠĠĠĠĠĠ Ġstring Control . text Ġ= Ġ" bar " ĊĠĠĠĠĠĠĠ ĠWaitFor Async Utils . waitFor Fx Events () ĊĠĠĠĠĠĠĠ ĠassertThat ( editor . valid . get (), Ġ` is `( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠmaxLength Validation () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġschema Ġ= ĠJSONObject (""" {" type ":" object "," properties ":{" string ":{" type ":" string "," maxLength ": 5 }}} """) ĊĠĠĠĠĠĠĠ Ġval Ġdata Ġ= ĠJSONObject (). put (" string ", Ġ" foobar ") ĊĠĠĠĠĠĠĠ Ġeditor . display (" 1 ", Ġ" 1 ", Ġdata , Ġschema ) Ġ{ Ġit Ġ} ĊĠĠĠĠĠĠĠ ĠWaitFor Async Utils . waitFor Fx Events () ĊĠĠĠĠĠĠĠ ĠassertThat ( editor . valid . get (), Ġ` is `( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠmaxLength Validation After Change () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġschema Ġ= ĠJSONObject (""" {" type ":" object "," properties ":{" string ":{" type ":" string "," maxLength ": 1 5 }}} """) ĊĠĠĠĠĠĠĠ Ġval Ġdata Ġ= ĠJSONObject (). put (" string ", Ġ" foobar ") ĊĠĠĠĠĠĠĠ Ġeditor . display (" 1 ", Ġ" 1 ", Ġdata , Ġschema ) Ġ{ Ġit Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġitem Table Ġ= Ġeditor . getItem Table () ĊĠĠĠĠĠĠĠ Ġval Ġstring Control Ġ= Ġeditor . get Control In Table (" string ") Ġas ĠTextField ĊĠĠĠĠĠĠĠ ĠWaitFor Async Utils . waitFor Fx Events () ĊĠĠĠĠĠĠĠ ĠassertThat ( editor . valid . get (), Ġ` is `( true )) ĊĠĠĠĠĠĠĠ Ġstring Control . text Ġ= Ġ" long er Ġthan Ġ 1 5 Ġchars " ĊĠĠĠĠĠĠĠ ĠWaitFor Async Utils . waitFor Fx Events () ĊĠĠĠĠĠĠĠ ĠassertThat ( editor . valid . get (), Ġ` is `( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġpattern Validation () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġschema Ġ= ĠJSONObject (""" {" type ":" object "," properties ":{" string ":{" type ":" string "," pattern ":" ^ b .* "}} } """) ĊĠĠĠĠĠĠĠ Ġval Ġdata Ġ= ĠJSONObject (). put (" string ", Ġ" foobar ") ĊĠĠĠĠĠĠĠ Ġeditor . display (" 1 ", Ġ" 1 ", Ġdata , Ġschema ) Ġ{ Ġit Ġ} ĊĠĠĠĠĠĠĠ ĠWaitFor Async Utils . waitFor Fx Events () ĊĠĠĠĠĠĠĠ ĠassertThat ( editor . valid . get (), Ġ` is `( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġpattern Validation After Change () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġschema Ġ= ĠJSONObject (""" {" type ":" object "," properties ":{" string ":{" type ":" string "," pattern ":" f .* "}} } """) ĊĠĠĠĠĠĠĠ Ġval Ġdata Ġ= ĠJSONObject (). put (" string ", Ġ" foobar ") ĊĠĠĠĠĠĠĠ Ġeditor . display (" 1 ", Ġ" 1 ", Ġdata , Ġschema ) Ġ{ Ġit Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġitem Table Ġ= Ġeditor . getItem Table () ĊĠĠĠĠĠĠĠ Ġval Ġstring Control Ġ= Ġeditor . get Control In Table (" string ") Ġas ĠTextField ĊĠĠĠĠĠĠĠ ĠWaitFor Async Utils . waitFor Fx Events () ĊĠĠĠĠĠĠĠ ĠassertThat ( editor . valid . get (), Ġ` is `( true )) ĊĠĠĠĠĠĠĠ Ġstring Control . text Ġ= Ġ" bar " ĊĠĠĠĠĠĠĠ ĠWaitFor Async Utils . waitFor Fx Events () ĊĠĠĠĠĠĠĠ ĠassertThat ( editor . valid . get (), Ġ` is `( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġformat Validation () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġschema Ġ= ĠJSONObject (""" {" type ":" object "," properties ":{" string ":{" type ":" string "," format ":" date "}} } """) ĊĠĠĠĠĠĠĠ Ġval Ġdata Ġ= ĠJSONObject (). put (" string ", Ġ" foobar ") ĊĠĠĠĠĠĠĠ Ġeditor . display (" 1 ", Ġ" 1 ", Ġdata , Ġschema ) Ġ{ Ġit Ġ} ĊĠĠĠĠĠĠĠ ĠWaitFor Async Utils . waitFor Fx Events () ĊĠĠĠĠĠĠĠ ĠassertThat ( editor . valid . get (), Ġ` is `( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġformat Validation After Modification () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġschema Ġ= ĠJSONObject (""" {" type ":" object "," properties ":{" string ":{" type ":" string "," format ":" date "}} } """) ĊĠĠĠĠĠĠĠ Ġval Ġdata Ġ= ĠJSONObject (). put (" string ", Ġ" 2 0 1 8 - 1 1 - 1 3 ") ĊĠĠĠĠĠĠĠ Ġeditor . display (" 1 ", Ġ" 1 ", Ġdata , Ġschema ) Ġ{ Ġit Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġitem Table Ġ= Ġeditor . getItem Table () ĊĠĠĠĠĠĠĠ Ġval Ġstring Control Ġ= Ġ( editor . get Control In Table (" string ") Ġas ĠDate Picker ). editor Ġas ĠTextField ĊĠĠĠĠĠĠĠ ĠWaitFor Async Utils . waitFor Fx Events () ĊĠĠĠĠĠĠĠ ĠassertThat ( editor . valid . get (), Ġ` is `( true )) ĊĠĠĠĠĠĠĠ Ġstring Control . text Ġ= Ġ" bar " ĊĠĠĠĠĠĠĠ ĠWaitFor Async Utils . waitFor Fx Events () ĊĠĠĠĠĠĠĠ ĠassertThat ( editor . valid . get (), Ġ` is `( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmulti Validation () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġschema Ġ= ĠJSONObject (""" {" type ":" object "," properties ":{" string ":{" type ":" string "," pattern ":" foo .+ "," min Length ": 5 }}} """) ĊĠĠĠĠĠĠĠ Ġval Ġdata Ġ= ĠJSONObject (). put (" string ", Ġ" foobar ") ĊĠĠĠĠĠĠĠ Ġeditor . display (" 1 ", Ġ" 1 ", Ġdata , Ġschema ) Ġ{ Ġit Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġitem Table Ġ= Ġeditor . getItem Table () ĊĠĠĠĠĠĠĠ Ġval Ġstring Control Ġ= Ġeditor . get Control In Table (" string ") Ġas ĠTextField ĊĠĠĠĠĠĠĠ ĠWaitFor Async Utils . waitFor Fx Events () ĊĠĠĠĠĠĠĠ ĠassertThat ( editor . valid . get (), Ġ` is `( true )) ĊĠĠĠĠĠĠĠ Ġstring Control . text Ġ= Ġ" long Ġenough Ġbut Ġpattern Ġdoes Ġnot Ġmatch " ĊĠĠĠĠĠĠĠ ĠWaitFor Async Utils . waitFor Fx Events () ĊĠĠĠĠĠĠĠ ĠassertThat ( editor . valid . get (), Ġ` is `( false )) ĊĠĠĠĠĠĠĠ Ġstring Control . text Ġ= Ġ" foobar Ġlong " ĊĠĠĠĠĠĠĠ ĠWaitFor Async Utils . waitFor Fx Events () ĊĠĠĠĠĠĠĠ ĠassertThat ( editor . valid . get (), Ġ` is `( true )) ĊĠĠĠĠĠĠĠ Ġstring Control . text Ġ= Ġ" foo " ĊĠĠĠĠĠĠĠ ĠWaitFor Async Utils . waitFor Fx Events () ĊĠĠĠĠĠĠĠ ĠassertThat ( editor . valid . get (), Ġ` is `( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdisplay DefaultValue () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġschema Ġ= ĠJSONObject (""" {" type ":" object "," properties ":{" string ":{" type ":" string "," default ": Ġ" foobar "}} } """) ĊĠĠĠĠĠĠĠ Ġeditor . display (" 1 ", Ġ" 1 ", ĠJSONObject (), Ġschema ) Ġ{ Ġit Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġitem Table Ġ= Ġeditor . getItem Table () ĊĠĠĠĠĠĠĠ Ġval Ġstring Control Ġ= Ġeditor . get Control In Table (" string ") Ġas ĠTextField ĊĠĠĠĠĠĠĠ ĠassertThat ( string Control . text , Ġ` is ` (" foobar ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdisplay Null () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġschema Ġ= ĠJSONObject (""" {" type ":" object "," properties ":{" string ":{" type ":" string "}} } """) ĊĠĠĠĠĠĠĠ Ġeditor . display (" 1 ", Ġ" 1 ", ĠJSONObject (), Ġschema ) Ġ{ Ġit Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġitem Table Ġ= Ġeditor . getItem Table () ĊĠĠĠĠĠĠĠ Ġval Ġstring Control Ġ= Ġeditor . get Control In Table (" string ") Ġas ĠTextField ĊĠĠĠĠĠĠĠ ĠassertThat ( string Control . text , Ġ` is `( null Value ())) ĊĠĠĠ Ġ} Ċ }