package Ġcom . demo . d ynam op oc . delivery . rest Ċ Ċ import Ġcom . demo . d ynam op oc . core . measure . DB Measure Ċ import Ġcom . demo . d ynam op oc . core . report . Report Ċ import Ġcom . demo . d ynam op oc . core . use cases . Retrieve DB Measures UseCase Ċ import Ġcom . fasterxml . jackson . databind . ObjectMapper Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . times Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġorg . junit . jupiter . api . Assertions Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . autoconfigure . web . servlet . Web Mvc Test Ċ import Ġorg . springframework . boot . test . mock . mockito . Mock Bean Ċ import Ġorg . springframework . test . context . junit . jupiter . Spring Extension Ċ import Ġorg . springframework . test . web . servlet . MockMvc Ċ import Ġorg . springframework . test . web . servlet . request . MockMvc Request Builders Ċ import Ġorg . springframework . test . web . servlet . result . MockMvc Result Matchers Ċ Ċ @ Extend With ( Spring Extension :: class ) Ċ @ Web Mvc Test ( controllers Ġ= Ġ[ Retrieve DB Measures Controller :: class ]) Ċ class ĠRetrieve DB Measures Controller Test Ġ{ ĊĊĠĠĠ Ġ@ Mock Bean ĊĠĠĠ Ġlateinit Ġvar Ġretrieve DB Measures : ĠRetrieve DB Measures UseCase ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġlateinit Ġvar Ġmock Mvc : ĠMock Mvc ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġlateinit Ġvar ĠobjectMapper : ĠObjectMapper ĊĊĠĠĠ Ġprivate Ġval Ġreport Ġ= ĠReport . Builder (). add Measure ( DB Measure (" description ", Ġ 1 0 , Ġ 1 0 )). build () ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( retrieve DB Measures . execute Scan Query ()). thenReturn ( report ) ĊĠĠĠĠĠĠĠ Ġwhenever ( retrieve DB Measures . executeQuery By Category ()). thenReturn ( report ) ĊĠĠĠĠĠĠĠ Ġwhenever ( retrieve DB Measures . executeQuery By Category And Created Date ()). thenReturn ( report ) ĊĠĠĠĠĠĠĠ Ġwhenever ( retrieve DB Measures . executeQuery By Category And Price ()). thenReturn ( report ) ĊĠĠĠĠĠĠĠ Ġwhenever ( retrieve DB Measures . executeQuery By Price ()). thenReturn ( report ) ĊĠĠĠĠĠĠĠ Ġwhenever ( retrieve DB Measures . executeQuery By Date ()). thenReturn ( report ) ĊĠĠĠĠĠĠĠ Ġwhenever ( retrieve DB Measures . executeQuery By Rating ()). thenReturn ( report ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġget Ġdb Ġmeasures Ġby Ġscan Ġquery Ġthen Ġshould Ġretrieve Ġa Ġreport `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġmock Mvc . perform ( MockMvc Request Builders . get ("$ db Measures Path / scan _ query ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( MockMvc Result Matchers . status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andReturn () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. response ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. content AsString ĊĊĠĠĠĠĠĠĠ Ġthen Report Was Returned ( response ) ĊĠĠĠĠĠĠĠ Ġverify ( retrieve DB Measures , Ġtimes ( 1 )). execute Scan Query () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġget Ġdb Ġmeasures Ġby Ġcategory Ġthen Ġshould Ġretrieve Ġa Ġreport `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġmock Mvc . perform ( MockMvc Request Builders . get ("$ db Measures Path / query _ by _ category ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( MockMvc Result Matchers . status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andReturn () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. response ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. content AsString ĊĊĠĠĠĠĠĠĠ Ġthen Report Was Returned ( response ) ĊĠĠĠĠĠĠĠ Ġverify ( retrieve DB Measures , Ġtimes ( 1 )). executeQuery By Category () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġget Ġdb Ġmeasures Ġby Ġcategory Ġand Ġcreated Ġdate Ġthen Ġshould Ġretrieve Ġa Ġreport `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġmock Mvc . perform ( MockMvc Request Builders . get ("$ db Measures Path / query _ by _ category _ and _ created _ date ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( MockMvc Result Matchers . status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andReturn () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. response ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. content AsString ĊĊĠĠĠĠĠĠĠ Ġthen Report Was Returned ( response ) ĊĠĠĠĠĠĠĠ Ġverify ( retrieve DB Measures , Ġtimes ( 1 )). executeQuery By Category And Created Date () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġget Ġdb Ġmeasures Ġby Ġcategory Ġand Ġprice Ġthen Ġshould Ġretrieve Ġa Ġreport `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġmock Mvc . perform ( MockMvc Request Builders . get ("$ db Measures Path / query _ by _ category _ and _ price ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( MockMvc Result Matchers . status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andReturn () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. response ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. content AsString ĊĊĠĠĠĠĠĠĠ Ġthen Report Was Returned ( response ) ĊĠĠĠĠĠĠĠ Ġverify ( retrieve DB Measures , Ġtimes ( 1 )). executeQuery By Category And Price () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġget Ġdb Ġmeasures Ġby Ġprice Ġthen Ġshould Ġretrieve Ġa Ġreport `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġmock Mvc . perform ( MockMvc Request Builders . get ("$ db Measures Path / query _ by _ price ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( MockMvc Result Matchers . status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andReturn () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. response ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. content AsString ĊĊĠĠĠĠĠĠĠ Ġthen Report Was Returned ( response ) ĊĠĠĠĠĠĠĠ Ġverify ( retrieve DB Measures , Ġtimes ( 1 )). executeQuery By Price () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġget Ġdb Ġmeasures Ġby Ġdate Ġthen Ġshould Ġretrieve Ġa Ġreport `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġmock Mvc . perform ( MockMvc Request Builders . get ("$ db Measures Path / query _ by _ date ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( MockMvc Result Matchers . status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andReturn () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. response ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. content AsString ĊĊĠĠĠĠĠĠĠ Ġthen Report Was Returned ( response ) ĊĠĠĠĠĠĠĠ Ġverify ( retrieve DB Measures , Ġtimes ( 1 )). executeQuery By Date () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġget Ġdb Ġmeasures Ġby Ġrating Ġthen Ġshould Ġretrieve Ġa Ġreport `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġmock Mvc . perform ( MockMvc Request Builders . get ("$ db Measures Path / query _ by _ rating ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( MockMvc Result Matchers . status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andReturn () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. response ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. content AsString ĊĊĠĠĠĠĠĠĠ Ġthen Report Was Returned ( response ) ĊĠĠĠĠĠĠĠ Ġverify ( retrieve DB Measures , Ġtimes ( 1 )). executeQuery By Rating () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġthen Report Was Returned ( response : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġreport Returned Ġ= ĠobjectMapper . readValue ( response , ĠReport :: class . java ) ĊĠĠĠĠĠĠĠ ĠAssertions . assertTrue ( report Returned . meas ures . isNotEmpty ()) ĊĠĠĠ Ġ} Ċ }