/* Ċ Ġ* ĠCopyright Ġ 2 0 1 9 ĠRod ĠMac K enz ie . Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġcom . github . ro dm . team city . usage Ċ Ċ import Ġjet brains . build Server . controllers . Xml Response Util Ċ import Ġorg . hamcrest . Matcher Assert . assertThat Ċ import Ġorg . hamcrest . Matchers .* Ċ import Ġorg . j dom . Element Ċ import Ġorg . junit . jupiter . api . Test Ċ Ċ class ĠSearch Results Test Ġ{ ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` capt ures Ġmatching Ġnames Ġby Ġconfiguration Ġsection `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= ĠSearch Result (" id ", Ġ" name ") ĊĊĠĠĠĠĠĠĠ Ġresult . names For (" General ĠSettings ", ĠlistOf (" param 1 ", Ġ" param 2 ")) ĊĠĠĠĠĠĠĠĠĊĠĠĠĠĠĠĠ ĠassertThat ( result . names By Section . keys , Ġhas Size ( 1 )) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . names By Section [" General ĠSettings "], Ġcontains In Any Order ( equalTo (" param 1 "), ĠequalTo (" param 2 "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` capt ures Ġmatching Ġnames Ġby Ġconfiguration Ġin Ġsection Ġorder `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= ĠSearch Result (" id ", Ġ" name ") ĊĊĠĠĠĠĠĠĠ Ġresult . names For (" General ĠSettings ", ĠlistOf (" param 1 ")) ĊĠĠĠĠĠĠĠ Ġresult . names For (" Build ĠFeatures ", ĠlistOf (" param 1 ")) ĊĊĠĠĠĠĠĠĠ Ġval Ġsections Ġ= Ġresult . names By Section . keys . toList () ĊĠĠĠĠĠĠĠ ĠassertThat ( sections , Ġhas Size ( 2 )) ĊĠĠĠĠĠĠĠ ĠassertThat ( sections [ 0 ], ĠequalTo (" General ĠSettings ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( sections [ 1 ], ĠequalTo (" Build ĠFeatures ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` captured Ġmatching Ġnames Ġare Ġnot Ġduplicated Ġin Ġa Ġsection `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= ĠSearch Result (" id ", Ġ" name ") ĊĊĠĠĠĠĠĠĠ Ġresult . names For (" Build ĠSteps ", ĠlistOf (" param 1 ")) ĊĠĠĠĠĠĠĠ Ġresult . names For (" Build ĠSteps ", ĠlistOf (" param 1 ")) ĊĊĠĠĠĠĠĠĠ Ġval Ġbuild Steps Ġ= Ġresult . names By Section [" Build ĠSteps "] ĊĠĠĠĠĠĠĠ ĠassertThat ( build Steps , Ġhas Size ( 1 )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` empty Ġmatching Ġnames Ġare Ġnot Ġcaptured `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= ĠSearch Result (" id ", Ġ" name ") ĊĊĠĠĠĠĠĠĠ Ġresult . names For (" Build ĠSteps ", ĠlistOf ()) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( result . names By Section . keys , Ġhas Size ( 0 )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` search Ġresult Ġwith Ġno Ġmatches `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= ĠSearch Result (" id ", Ġ" name ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( result . has Matches (), Ġ` is `( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` search Ġresult Ġwith Ġmatches `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= ĠSearch Result (" id ", Ġ" name ") ĊĠĠĠĠĠĠĠ Ġresult . names For (" General ĠSettings ", ĠlistOf (" param 1 ")) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( result . has Matches (), Ġ` is `( true )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` serialize Ġempty Ġsearch Ġresults Ġreturns Ġno Ġresult Ġelements `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġxml Response Ġ= ĠXml Response Util . new Xml Response () ĊĠĠĠĠĠĠĠ Ġval Ġresults Ġ= ĠSearch Results ( listOf ()) ĊĊĠĠĠĠĠĠĠ Ġresults . serialize ( xml Response ) ĊĊĠĠĠĠĠĠĠ Ġval Ġnodes Ġ= Ġxml Response . getChildren (" result ") ĊĠĠĠĠĠĠĠ ĠassertThat ( nodes , Ġhas Size ( 0 )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` serialize Ġsearch Ġresults Ġwith Ġmatching Ġbuild Ġtype Ġreturns Ġresult Ġelement `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġxml Response Ġ= ĠXml Response Util . new Xml Response () ĊĠĠĠĠĠĠĠ Ġval Ġresults Ġ= ĠSearch Results ( listOf ( SearchResult (" ext Id ", Ġ" build Ġname "))) ĊĊĠĠĠĠĠĠĠ Ġresults . serialize ( xml Response ) ĊĊĠĠĠĠĠĠĠ Ġval Ġnodes Ġ= Ġxml Response . getChildren (" result ") ĊĠĠĠĠĠĠĠ ĠassertThat ( nodes , Ġhas Size ( 1 )) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġnodes [ 0 ] Ġas ĠElement ĊĠĠĠĠĠĠĠ ĠassertThat ( result . getAttribute Value (" id ") Ġas ĠString , ĠequalTo (" ext Id ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . getAttribute Value (" name ") Ġas ĠString , ĠequalTo (" build Ġname ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` serialize Ġsearch Ġresults Ġwith Ġbuild Ġtype Ġreturns Ġresult Ġelement Ġwith Ġbuild Ġtype Ġattribute `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġxml Response Ġ= ĠXml Response Util . new Xml Response () ĊĠĠĠĠĠĠĠ Ġval Ġresults Ġ= ĠSearch Results ( listOf ( SearchResult (" ext Id ", Ġ" build Ġname ", ĠType . BUILD ))) ĊĊĠĠĠĠĠĠĠ Ġresults . serialize ( xml Response ) ĊĊĠĠĠĠĠĠĠ Ġval Ġnodes Ġ= Ġxml Response . getChildren (" result ") ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġnodes [ 0 ] Ġas ĠElement ĊĠĠĠĠĠĠĠ ĠassertThat ( result . getAttribute Value (" type ") Ġas ĠString , ĠequalTo (" BUILD ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` serialize Ġsearch Ġresults Ġwith Ġbuild Ġtemplate Ġreturns Ġresult Ġelement Ġwith Ġtemplate Ġtype Ġattribute `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġxml Response Ġ= ĠXml Response Util . new Xml Response () ĊĠĠĠĠĠĠĠ Ġval Ġresults Ġ= ĠSearch Results ( listOf ( SearchResult (" ext Id ", Ġ" build Ġname ", ĠType . TEMPLATE ))) ĊĊĠĠĠĠĠĠĠ Ġresults . serialize ( xml Response ) ĊĊĠĠĠĠĠĠĠ Ġval Ġnodes Ġ= Ġxml Response . getChildren (" result ") ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġnodes [ 0 ] Ġas ĠElement ĊĠĠĠĠĠĠĠ ĠassertThat ( result . getAttribute Value (" type ") Ġas ĠString , ĠequalTo (" TEMPLATE ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` serialize Ġsearch Ġresults Ġwith Ġproject Ġreturns Ġresult Ġelement Ġwith Ġproject Ġtype Ġattribute `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġxml Response Ġ= ĠXml Response Util . new Xml Response () ĊĠĠĠĠĠĠĠ Ġval Ġresults Ġ= ĠSearch Results ( listOf ( SearchResult (" ext Id ", Ġ" project Ġname ", ĠType . PROJECT ))) ĊĊĠĠĠĠĠĠĠ Ġresults . serialize ( xml Response ) ĊĊĠĠĠĠĠĠĠ Ġval Ġnodes Ġ= Ġxml Response . getChildren (" result ") ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġnodes [ 0 ] Ġas ĠElement ĊĠĠĠĠĠĠĠ ĠassertThat ( result . getAttribute Value (" type ") Ġas ĠString , ĠequalTo (" PROJECT ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` serialize Ġsearch Ġresults Ġreturns Ġresult Ġelement Ġfor Ġeach Ġbuild Ġtype `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġxml Response Ġ= ĠXml Response Util . new Xml Response () ĊĠĠĠĠĠĠĠ Ġval Ġresults Ġ= ĠSearch Results ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSearch Result (" ext Id 1 ", Ġ" build Ġname Ġ 1 "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSearch Result (" ext Id 2 ", Ġ" build Ġname Ġ 2 ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ)) ĊĊĠĠĠĠĠĠĠ Ġresults . serialize ( xml Response ) ĊĊĠĠĠĠĠĠĠ Ġval Ġnodes Ġ= Ġxml Response . getChildren (" result ") ĊĠĠĠĠĠĠĠ ĠassertThat ( nodes , Ġhas Size ( 2 )) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġnodes [ 1 ] Ġas ĠElement ĊĠĠĠĠĠĠĠ ĠassertThat ( result . getAttribute Value (" id ") Ġas ĠString , ĠequalTo (" ext Id 2 ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . getAttribute Value (" name ") Ġas ĠString , ĠequalTo (" build Ġname Ġ 2 ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` serialize Ġsearch Ġresult Ġoutputs Ġsections Ġfor Ġmatching Ġparameters `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġxml Response Ġ= ĠXml Response Util . new Xml Response () ĊĠĠĠĠĠĠĠ Ġval Ġsearch Result Ġ= ĠSearch Result (" ext Id ", Ġ" build Ġname ") ĊĠĠĠĠĠĠĠ Ġsearch Result . names For (" General ĠSettings ", ĠlistOf (" param 1 ", Ġ" param 2 ")) ĊĠĠĠĠĠĠĠ Ġsearch Result . names For (" Build ĠSteps ", ĠlistOf (" param 1 ", Ġ" param 3 ")) ĊĠĠĠĠĠĠĠ Ġval Ġresults Ġ= ĠSearch Results ( listOf ( search Result )) ĊĊĠĠĠĠĠĠĠ Ġresults . serialize ( xml Response ) ĊĊĠĠĠĠĠĠĠ Ġval Ġnodes Ġ= Ġxml Response . getChildren (" result ") ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġnodes [ 0 ] Ġas ĠElement ĊĠĠĠĠĠĠĠ Ġval Ġsections Ġ= Ġresult . getChildren (" section "). map Ġ{ Ġ( it Ġas ĠElement ). getAttribute Value (" name ") Ġ} ĊĠĠĠĠĠĠĠ ĠassertThat ( sections , Ġcontains ( equalTo (" General ĠSettings "), ĠequalTo (" Build ĠSteps "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġnames From ( element : ĠElement ): ĠList < String > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġelement . getChildren (" name "). map Ġ{ Ġ( it Ġas ĠElement ). getAttribute Value (" value ") Ġ}. toList () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` serialize Ġsearch Ġresult Ġoutputs Ġnames Ġfor Ġeach Ġsection Ġfor Ġmatching Ġparameters `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġxml Response Ġ= ĠXml Response Util . new Xml Response () ĊĠĠĠĠĠĠĠ Ġval Ġsearch Result Ġ= ĠSearch Result (" ext Id ", Ġ" build Ġname ") ĊĠĠĠĠĠĠĠ Ġsearch Result . names For (" General ĠSettings ", ĠlistOf (" param 1 ", Ġ" param 2 ")) ĊĠĠĠĠĠĠĠ Ġsearch Result . names For (" Build ĠSteps ", ĠlistOf (" param 1 ", Ġ" param 3 ")) ĊĠĠĠĠĠĠĠ Ġval Ġresults Ġ= ĠSearch Results ( listOf ( search Result )) ĊĊĠĠĠĠĠĠĠ Ġresults . serialize ( xml Response ) ĊĊĠĠĠĠĠĠĠ Ġval Ġnodes Ġ= Ġxml Response . getChildren (" result ") ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġnodes [ 0 ] Ġas ĠElement ĊĠĠĠĠĠĠĠ Ġval Ġsections Ġ= Ġresult . getChildren (" section ") ĊĠĠĠĠĠĠĠ Ġval Ġnames 1 Ġ= Ġnames From ( sections [ 0 ] Ġas ĠElement ) ĊĠĠĠĠĠĠĠ ĠassertThat ( names 1 , Ġcontains ( equalTo (" param 1 "), ĠequalTo (" param 2 "))) ĊĠĠĠĠĠĠĠ Ġval Ġnames 2 Ġ= Ġnames From ( sections [ 1 ] Ġas ĠElement ) ĊĠĠĠĠĠĠĠ ĠassertThat ( names 2 , Ġcontains ( equalTo (" param 1 "), ĠequalTo (" param 3 "))) ĊĠĠĠ Ġ} Ċ } Ċ