package Ġcom . co ach . fl ame . testing . component . api . daily Task Ċ Ċ import Ġcom . co ach . fl ame . jpa . entity . Daily Task Ċ import Ġcom . co ach . fl ame . jpa . entity . maker . Daily Task Builder Ċ import Ġcom . co ach . fl ame . testing . assertion . http . Error Assert Ċ import Ġcom . co ach . fl ame . testing . component . base . Base Component Test Ċ import Ġcom . co ach . fl ame . testing . framework . Json Builder Ċ import Ġcom . co ach . fl ame . testing . framework . Load Request Ċ import Ġio . mock k . every Ċ import Ġorg . assertj . core . api . BDD Assertions . then Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . data . jpa . domain . Specification Ċ import Ġorg . springframework . http . HttpStatus Ċ import Ġorg . springframework . http . MediaType Ċ import Ġorg . springframework . test . web . servlet . MockMvc Ċ import Ġorg . springframework . web . bind . annotation . Request Method Ċ Ċ class ĠDaily Task Get Using Filters Test Ġ: ĠBase Component Test () Ġ{ ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmock Mvc : ĠMock Mvc ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Load Request ( ĊĠĠĠĠĠĠĠ Ġpath Of Request Ġ= Ġ" requests / component / daily Task / get Daily Tasks One Filter . json ", ĊĠĠĠĠĠĠĠ Ġendpoint Ġ= Ġ"/ api / daily Task / get / tasks / filter ", ĊĠĠĠĠĠĠĠ Ġhttp Method Ġ= ĠRequestMethod . POST ĊĠĠĠ Ġ) ĊĠĠĠ Ġfun Ġ` test Ġget Ġdaily Ġtasks Ġusing Ġone Ġfilter `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġ// Ġgiven ĊĠĠĠĠĠĠĠ Ġval Ġdaily Task 0 Ġ= ĠDaily Task Builder . default () ĊĠĠĠĠĠĠĠ Ġval Ġdaily Task 1 Ġ= ĠDaily Task Builder . default () ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġdaily Task Repository Mock . findAll ( any < Specification < Daily Task >> ()) Ġ} Ġreturns ĠlistOf ( daily Task 0 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdaily Task 1 ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġwhen ĊĠĠĠĠĠĠĠ Ġval Ġmvn Response Ġ= Ġmock Mvc . perform ( request !! ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andReturn () ĊĊĠĠĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠĠĠ Ġthen ( mvn Response . response ). isNotNull ĊĠĠĠĠĠĠĠ Ġthen ( mvn Response . response . status ). isEqualTo ( HttpStatus . OK . value ()) ĊĠĠĠĠĠĠĠ Ġthen ( mvn Response . response . contentType ). isEqualTo ( MediaType . APPLICATION _ JSON _ VALUE ) ĊĊĠĠĠĠĠĠĠ Ġval Ġjson Response Ġ= ĠJson Builder . get Json From Mock Client ( mvn Response . response ) ĊĊĠĠĠĠĠĠĠ Ġthen ( json Response . getAs JsonArray (" daily Tasks ")). has Size ( 2 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġtask 0 Ġ= Ġjson Response . getAs JsonArray (" daily Tasks ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. first Ġ{ Ġit . as JsonObject . getAs Json Primitive (" identifier "). asString Ġ== Ġdaily Task 0 . uuid . toString () Ġ}. as JsonObject ĊĊĠĠĠĠĠĠĠ Ġthen ( task 0 . getAs Json Primitive (" task Name "). asString ). isEqualTo ( daily Task 0 . name ) ĊĠĠĠĠĠĠĠ Ġthen ( task 0 . getAs Json Primitive (" task Description "). asString ). isEqualTo ( daily Task 0 . description ) ĊĠĠĠĠĠĠĠ Ġthen ( task 0 . getAs Json Primitive (" date "). asString ). isEqualTo ( daily Task 0 . date . toString ()) ĊĠĠĠĠĠĠĠ Ġthen ( task 0 . getAs Json Primitive (" tick ed "). as Boolean ). isEqualTo ( daily Task 0 . tick ed ) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Load Request ( ĊĠĠĠĠĠĠĠ Ġpath Of Request Ġ= Ġ" requests / component / daily Task / get Daily Tasks One Filter . json ", ĊĠĠĠĠĠĠĠ Ġendpoint Ġ= Ġ"/ api / daily Task / get / tasks / filter ", ĊĠĠĠĠĠĠĠ Ġhttp Method Ġ= ĠRequestMethod . POST ĊĠĠĠ Ġ) ĊĠĠĠ Ġfun Ġ` test Ġget Ġdaily Ġtasks Ġusing Ġmultiple Ġfilters `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġ// Ġgiven ĊĠĠĠĠĠĠĠ Ġval Ġdaily Task 0 Ġ= ĠDaily Task Builder . default () ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġdaily Task Repository Mock . findAll ( any < Specification < Daily Task >> ()) Ġ} Ġreturns ĠlistOf ( daily Task 0 ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġwhen ĊĠĠĠĠĠĠĠ Ġval Ġmvn Response Ġ= Ġmock Mvc . perform ( request !! ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andReturn () ĊĊĠĠĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠĠĠ Ġthen ( mvn Response . response ). isNotNull ĊĠĠĠĠĠĠĠ Ġthen ( mvn Response . response . status ). isEqualTo ( HttpStatus . OK . value ()) ĊĠĠĠĠĠĠĠ Ġthen ( mvn Response . response . contentType ). isEqualTo ( MediaType . APPLICATION _ JSON _ VALUE ) ĊĊĠĠĠĠĠĠĠ Ġval Ġjson Response Ġ= ĠJson Builder . get Json From Mock Client ( mvn Response . response ) ĊĊĠĠĠĠĠĠĠ Ġthen ( json Response . getAs JsonArray (" daily Tasks ")). has Size ( 1 ) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Load Request ( ĊĠĠĠĠĠĠĠ Ġpath Of Request Ġ= Ġ" requests / component / daily Task / get Daily Tasks Invalid Filter . json ", ĊĠĠĠĠĠĠĠ Ġendpoint Ġ= Ġ"/ api / daily Task / get / tasks / filter ", ĊĠĠĠĠĠĠĠ Ġhttp Method Ġ= ĠRequestMethod . POST ĊĠĠĠ Ġ) ĊĠĠĠ Ġfun Ġ` test Ġget Ġdaily Ġtasks Ġusing Ġinvalid Ġfilters `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġ// Ġgiven ĊĠĠĠĠĠĠĠ Ġval Ġdaily Task 0 Ġ= ĠDaily Task Builder . default () ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġdaily Task Repository Mock . findAll ( any < Specification < Daily Task >> ()) Ġ} Ġreturns ĠlistOf ( daily Task 0 ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġwhen ĊĠĠĠĠĠĠĠ Ġval Ġmvn Response Ġ= Ġmock Mvc . perform ( request !! ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andReturn () ĊĊĠĠĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠĠĠ Ġthen ( mvn Response ). isNotNull ĊĠĠĠĠĠĠĠ Ġthen ( mvn Response . response . status ). isEqualTo ( HttpStatus . BAD _ REQUEST . value ()) ĊĠĠĠĠĠĠĠ Ġthen ( mvn Response . response . contentType ). isEqualTo ( MediaType . APPLICATION _ PRO BLE M _ JSON _ VALUE ) ĊĊĠĠĠĠĠĠĠ Ġval Ġbody Ġ= ĠJson Builder . get Json From Mock Client ( mvn Response . response ) ĊĊĠĠĠĠĠĠĠ ĠError Assert . assertThat ( body ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Type EndsWith (" Rest Invalid RequestException . html ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Title (" Rest Invalid RequestException ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Detail (" INVALID Ġis Ġan Ġinvalid Ġfilter ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Status (" 4 0 0 ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Code (" 1 0 0 1 ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Instance () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. not Has ErrorMessage Debug () ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Load Request ( ĊĠĠĠĠĠĠĠ Ġpath Of Request Ġ= Ġ" requests / component / daily Task / get Daily Tasks Missing Params Filter . json ", ĊĠĠĠĠĠĠĠ Ġendpoint Ġ= Ġ"/ api / daily Task / get / tasks / filter ", ĊĠĠĠĠĠĠĠ Ġhttp Method Ġ= ĠRequestMethod . POST ĊĠĠĠ Ġ) ĊĠĠĠ Ġfun Ġ` test Ġget Ġdaily Ġtasks Ġusing Ġmissing Ġparams Ġfilters `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġ// Ġgiven ĊĠĠĠĠĠĠĠ Ġval Ġdaily Task 0 Ġ= ĠDaily Task Builder . default () ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġdaily Task Repository Mock . findAll ( any < Specification < Daily Task >> ()) Ġ} Ġreturns ĠlistOf ( daily Task 0 ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġwhen ĊĠĠĠĠĠĠĠ Ġval Ġmvn Response Ġ= Ġmock Mvc . perform ( request !! ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andReturn () ĊĊĠĠĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠĠĠ Ġthen ( mvn Response ). isNotNull ĊĠĠĠĠĠĠĠ Ġthen ( mvn Response . response . status ). isEqualTo ( HttpStatus . INTERNAL _ SERVER _ ERROR . value ()) ĊĠĠĠĠĠĠĠ Ġthen ( mvn Response . response . contentType ). isEqualTo ( MediaType . APPLICATION _ PRO BLE M _ JSON _ VALUE ) ĊĊĠĠĠĠĠĠĠ Ġval Ġbody Ġ= ĠJson Builder . get Json From Mock Client ( mvn Response . response ) ĊĊĠĠĠĠĠĠĠ ĠError Assert . assertThat ( body ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Type EndsWith (" Rest Exception . html ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Title (" Rest Exception ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Detail (" B ETWEEN _ DAT ES Ġhas Ġan Ġinvalid Ġnumber Ġof Ġparams ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Status (" 5 0 0 ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Code (" 1 0 0 0 ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Instance () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. not Has ErrorMessage Debug () ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Load Request ( ĊĠĠĠĠĠĠĠ Ġpath Of Request Ġ= Ġ" requests / component / daily Task / get Daily Tasks Invalid Params Filter . json ", ĊĠĠĠĠĠĠĠ Ġendpoint Ġ= Ġ"/ api / daily Task / get / tasks / filter ", ĊĠĠĠĠĠĠĠ Ġhttp Method Ġ= ĠRequestMethod . POST ĊĠĠĠ Ġ) ĊĠĠĠ Ġfun Ġ` test Ġget Ġdaily Ġtasks Ġusing Ġinvalid Ġparams Ġfilters `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġ// Ġgiven ĊĠĠĠĠĠĠĠ Ġval Ġdaily Task 0 Ġ= ĠDaily Task Builder . default () ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġdaily Task Repository Mock . findAll ( any < Specification < Daily Task >> ()) Ġ} Ġreturns ĠlistOf ( daily Task 0 ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġwhen ĊĠĠĠĠĠĠĠ Ġval Ġmvn Response Ġ= Ġmock Mvc . perform ( request !! ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andReturn () ĊĊĠĠĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠĠĠ Ġthen ( mvn Response ). isNotNull ĊĠĠĠĠĠĠĠ Ġthen ( mvn Response . response . status ). isEqualTo ( HttpStatus . BAD _ REQUEST . value ()) ĊĠĠĠĠĠĠĠ Ġthen ( mvn Response . response . contentType ). isEqualTo ( MediaType . APPLICATION _ PRO BLE M _ JSON _ VALUE ) ĊĊĠĠĠĠĠĠĠ Ġval Ġbody Ġ= ĠJson Builder . get Json From Mock Client ( mvn Response . response ) ĊĊĠĠĠĠĠĠĠ ĠError Assert . assertThat ( body ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Type EndsWith (" Rest Invalid RequestException . html ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Title (" Rest Invalid RequestException ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Detail (" IDENTIFIER Ġis Ġan Ġinvalid Ġfilter ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Status (" 4 0 0 ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Code (" 1 0 0 1 ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has ErrorMessage Instance () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. not Has ErrorMessage Debug () ĊĊĠĠĠ Ġ} ĊĊ Ċ } Ċ