package Ġuk . gov . just ice . digital . h mp ps . cmd . api . controllers Ċ Ċ import Ġcom . fasterxml . jackson . core . type . Type Reference Ċ import Ġcom . fasterxml . jackson . databind . ObjectMapper Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . DisplayName Ċ 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 . context . SpringBootTest Ċ import Ġorg . springframework . boot . test . json . Basic Json Tester Ċ import Ġorg . springframework . boot . test . web . client . Test Rest Template Ċ import Ġorg . springframework . http . HttpMethod Ċ import Ġorg . springframework . http . HttpStatus Ċ import Ġorg . springframework . http . Response Entity Ċ import Ġorg . springframework . test . context . Active Profiles Ċ import Ġorg . springframework . test . context . jdbc . Sql Ċ import Ġorg . springframework . test . context . jdbc . Sql Config Ċ import Ġorg . springframework . test . context . jdbc . Sql Group Ċ import Ġorg . springframework . test . context . junit . jupiter . Spring Extension Ċ import Ġuk . gov . just ice . digital . h mp ps . cmd . api . dto . Notification Dto Ċ import Ġjava . time . LocalDate Ċ Ċ @ Extend With ( Spring Extension :: class ) Ċ @ SpringBootTest ( web Environment Ġ= ĠSpring Boot Test . Web Environment . RANDOM _ PORT ) Ċ @ Sql Group ( ĊĠ ĠSql ( scripts Ġ= Ġ[" classpath : notification / before - test . sql "], Ġconfig Ġ= ĠSql Config ( transaction Mode Ġ= ĠSql Config . Transaction Mode . IS OL ATED )), ĊĠ ĠSql ( scripts Ġ= Ġ[" classpath : notification / after - test . sql "], Ġconfig Ġ= ĠSql Config ( transaction Mode Ġ= ĠSql Config . Transaction Mode . IS OL ATED ), Ġexecution Phase Ġ= ĠSql . Execution Phase . AFTER _ TEST _ METHOD ) Ċ ) Ċ @ Active Profiles ( value Ġ= Ġ[" test "]) Ċ @ DisplayName (" Integration ĠTests Ġfor ĠNotification ĠController ") Ċ class ĠNotification Controller Get IntegrationTest ( ĊĠ Ġ@ Autowired Ġval Ġtest Rest Template : ĠTest Rest Template , ĊĠ Ġ@ Autowired Ġval Ġentity Builder : ĠEntity With Jwt Author isation Builder , ĊĠ Ġ@ Autowired Ġval ĠobjectMapper : ĠObjectMapper Ċ ) Ġ{ ĊĠ Ġval Ġjson Tester Ġ= ĠBasic Json Tester ( this . java Class ) ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` It Ġreturns Ġnotifications `() Ġ{ ĊĠĠĠ Ġval Ġresponse Ġ= Ġget Notifications ( A _ USER , Ġ"/ notifications ") ĊĠĠĠ Ġwith ( response ) Ġ{ ĊĠĠĠĠĠ ĠassertThat ( statusCode ). isEqualTo ( HttpStatus . OK ) ĊĠĠĠĠĠ Ġ// Ġwe Ġuse Ġan Ġinsert Ġof ĠCURRENT _ DATE Ġin Ġthe Ġtest Ġdata . Ġso Ġthere Ġshould Ġbe Ġ 4 Ġreturned ĊĠĠĠĠĠ ĠassertThat ( json Tester . from ( body )). extract ing Json Path Value ("$ "). asList (). has Size ( 4 ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` It Ġreturns Ġnotifications Ġdeep Ġinspection ĠEmail `() Ġ{ ĊĠĠĠ Ġval Ġresponse Ġ= Ġget Notifications ( A _ USER , Ġ"/ notifications ") ĊĠĠĠ Ġwith ( response ) Ġ{ ĊĠĠĠĠĠ ĠassertThat ( statusCode ). isEqualTo ( HttpStatus . OK ) ĊĠĠĠĠĠ Ġ// Ġwe Ġuse Ġan Ġinsert Ġof ĠCURRENT _ DATE Ġin Ġthe Ġtest Ġdata . Ġso Ġthere Ġshould Ġbe Ġ 4 Ġreturned ĊĠĠĠĠĠ Ġval Ġnotification List : ĠList < Notification Dto > Ġ= ĠobjectMapper . readValue ( body , Ġobject Ġ: ĠType Reference < List < Notification Dto >>() Ġ{}) ĊĠĠĠĠĠ ĠassertThat ( notification List ). has Size ( 4 ) ĊĊĠĠĠĠĠ Ġval Ġnotification Ġ= Ġnotification List . find Last Ġ{ Ġit . description . contains (" has Ġbeen Ġadded .") Ġ} ĊĠĠĠĠĠ ĠassertThat ( notification ). isNotNull ĊĠĠĠĠĠ ĠassertThat ( notification ?. processed ). isFalse () ĊĠĠĠĠĠ ĠassertThat ( notification ?. shift Modified ). isEqualTo ( LocalDate . now (). at Start OfDay ()) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` It Ġreturns Ġnotifications Ġwith Ġan Ġunread Ġonly Ġpreference Ġof Ġfalse `() Ġ{ ĊĠĠĠ Ġval Ġresponse Ġ= Ġget Notifications ( A _ USER , Ġ"/ notifications ? un processed Only = false ") ĊĠĠĠ Ġwith ( response ) Ġ{ ĊĠĠĠĠĠ ĠassertThat ( statusCode ). isEqualTo ( HttpStatus . OK ) ĊĠĠĠĠĠ Ġ// Ġwe Ġhave Ġone Ġread Ġand Ġone Ġnot Ġfor Ġeach Ġtype Ġso Ġthere Ġshould Ġbe Ġ 4 Ġreturned ĊĠĠĠĠĠ ĠassertThat ( json Tester . from ( body )). extract ing Json Path Value ("$ "). asList (). has Size ( 4 ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` It Ġreturns Ġnotifications Ġwith Ġan Ġunread Ġpreference Ġof Ġtrue `() Ġ{ ĊĠĠĠ Ġval Ġresponse Ġ= Ġget Notifications ( A _ USER , Ġ"/ notifications ? un processed Only = true ") ĊĠĠĠ Ġwith ( response ) Ġ{ ĊĠĠĠĠĠ ĠassertThat ( statusCode ). isEqualTo ( HttpStatus . OK ) ĊĠĠĠĠĠ Ġ// Ġwe Ġhave Ġone Ġread Ġand Ġone Ġnot Ġfor Ġeach Ġtype Ġso Ġthere Ġshould Ġbe Ġ 2 Ġreturned ĊĠĠĠĠĠ ĠassertThat ( json Tester . from ( body )). extract ing Json Path Value ("$ "). asList (). has Size ( 2 ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` It Ġreturns Ġno Ġnotifications Ġif Ġthere Ġare Ġnone Ġfor Ġa Ġuser `() Ġ{ ĊĠĠĠ Ġval Ġresponse Ġ= Ġget Notifications ( A _ USER _ NO _ DATA , Ġ"/ notifications ") ĊĠĠĠ Ġwith ( response ) Ġ{ ĊĠĠĠĠĠ ĠassertThat ( statusCode ). isEqualTo ( HttpStatus . OK ) ĊĊĠĠĠĠĠ ĠassertThat ( json Tester . from ( body )). extract ing Json Path Value ("$ "). asList (). has Size ( 0 ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` It Ġreturns Ġnotifications Ġbetween Ġtwo Ġdates Ġwith Ġdata Ġfor Ġafter Ġthe Ġ' to '` () Ġ{ ĊĠĠĠ Ġval Ġfrom Ġ= ĠLocalDate . now () ĊĠĠĠ Ġval Ġto Ġ= ĠLocalDate . now (). plus Days ( 2 ) ĊĠĠĠ Ġval Ġresponse Ġ= Ġget Notifications ( A _ USER , Ġ"/ notifications ? from =$ from & to =$ to ") ĊĠĠĠ Ġwith ( response ) Ġ{ ĊĠĠĠĠĠ ĠassertThat ( statusCode ). isEqualTo ( HttpStatus . OK ) ĊĠĠĠĠĠ Ġ// Ġwe Ġuse Ġan Ġinsert Ġof ĠCURRENT _ DATE + 7 Ġfor Ġ 2 / 4 Ġin Ġthe Ġtest Ġdata . Ġso Ġthere Ġshould Ġbe Ġ 2 Ġreturned ĊĠĠĠĠĠ ĠassertThat ( json Tester . from ( body )). extract ing Json Path Value ("$ "). asList (). has Size ( 2 ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` It Ġreturns Ġnotifications Ġbetween Ġtwo Ġdates Ġwith Ġdata Ġfor Ġbefore Ġthe Ġ' from '` () Ġ{ ĊĠĠĠ Ġval Ġfrom Ġ= ĠLocalDate . now (). plus Days ( 2 ) ĊĠĠĠ Ġval Ġto Ġ= ĠLocalDate . now (). plus Days ( 8 ) ĊĠĠĠ Ġval Ġresponse Ġ= Ġget Notifications ( A _ USER , Ġ"/ notifications ? from =$ from & to =$ to ") ĊĠĠĠ Ġwith ( response ) Ġ{ ĊĠĠĠĠĠ ĠassertThat ( statusCode ). isEqualTo ( HttpStatus . OK ) ĊĠĠĠĠĠ Ġ// Ġwe Ġuse Ġan Ġinsert Ġof ĠCURRENT _ DATE + 7 Ġfor Ġ 2 / 4 Ġin Ġthe Ġtest Ġdata . Ġso Ġthere Ġshould Ġbe Ġ 2 Ġreturned ĊĠĠĠĠĠ ĠassertThat ( json Tester . from ( body )). extract ing Json Path Value ("$ "). asList (). has Size ( 2 ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` It Ġreturns Ġempty Ġwhen Ġ' from ' Ġis Ġafter Ġ' to '` () Ġ{ ĊĠĠĠ Ġval Ġfrom Ġ= ĠLocalDate . now (). plus Days ( 2 ) ĊĠĠĠ Ġval Ġto Ġ= ĠLocalDate . now (). plus Days ( 8 ) ĊĠĠĠ Ġval Ġresponse Ġ= Ġget Notifications ( A _ USER , Ġ"/ notifications ? from =$ to & to =$ from ") ĊĠĠĠ Ġwith ( response ) Ġ{ ĊĠĠĠĠĠ ĠassertThat ( statusCode ). isEqualTo ( HttpStatus . OK ) ĊĠĠĠĠĠ Ġ// Ġwe Ġuse Ġan Ġinsert Ġof ĠCURRENT _ DATE + 7 Ġfor Ġ 2 / 4 Ġin Ġthe Ġtest Ġdata . Ġso Ġthere Ġshould Ġbe Ġ 2 Ġreturned ĊĠĠĠĠĠ ĠassertThat ( json Tester . from ( body )). extract ing Json Path Value ("$ "). asList (). has Size ( 0 ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` It Ġreturns Ġnotifications Ġapplying Ġboth Ġdates Ġand Ġunread Ġfilters `() Ġ{ ĊĠĠĠ Ġval Ġfrom Ġ= ĠLocalDate . now (). plus Days ( 2 ) ĊĠĠĠ Ġval Ġto Ġ= ĠLocalDate . now (). plus Days ( 8 ) ĊĠĠĠ Ġval Ġresponse Ġ= Ġget Notifications ( A _ USER , Ġ"/ notifications ? from =$ from & to =$ to & un processed Only = true ") ĊĠĠĠ Ġwith ( response ) Ġ{ ĊĠĠĠĠĠ ĠassertThat ( statusCode ). isEqualTo ( HttpStatus . OK ) ĊĠĠĠĠĠ Ġ// Ġwe Ġuse Ġan Ġinsert Ġof ĠCURRENT _ DATE + 7 Ġfor Ġ 2 / 4 Ġin Ġthe Ġtest Ġdata Ġwith Ġone Ġof Ġthose Ġunread . Ġso Ġthere Ġshould Ġbe Ġ 1 Ġreturned ĊĠĠĠĠĠ ĠassertThat ( json Tester . from ( body )). extract ing Json Path Value ("$ "). asList (). has Size ( 1 ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` It Ġreturns Ġnotifications Ġand Ġmarks Ġthem Ġas Ġread `() Ġ{ ĊĠĠĠ Ġval Ġresponse One Ġ= Ġget Notifications ( A _ USER , Ġ"/ notifications ") ĊĠĠĠ Ġwith ( response One ) Ġ{ ĊĠĠĠĠĠ ĠassertThat ( statusCode ). isEqualTo ( HttpStatus . OK ) ĊĠĠĠĠĠ Ġ// Ġthere Ġare Ġtwo Ġun processed Ġnotifications Ġand Ġtwo Ġprocessed ĊĠĠĠĠĠ ĠassertThat ( json Tester . from ( body )). extract ing Json Path Value ("$ "). asList (). has Size ( 4 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġresponse Two Ġ= Ġget Notifications ( A _ USER , Ġ"/ notifications ? un processed Only = true ") ĊĠĠĠ Ġwith ( response Two ) Ġ{ ĊĠĠĠĠĠ ĠassertThat ( statusCode ). isEqualTo ( HttpStatus . OK ) ĊĠĠĠĠĠ Ġ// Ġthere Ġshould Ġnow Ġbe Ġ 0 Ġun processed Ġnotifications ĊĠĠĠĠĠ ĠassertThat ( json Tester . from ( body )). extract ing Json Path Value ("$ "). asList (). has Size ( 0 ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` It Ġreturns Ġnotifications Ġand Ġdoesn 't Ġmark Ġthem Ġas Ġread `() Ġ{ ĊĠĠĠ Ġval Ġresponse One Ġ= Ġget Notifications ( A _ USER , Ġ"/ notifications ? process On Read = false ") ĊĠĠĠ Ġwith ( response One ) Ġ{ ĊĠĠĠĠĠ ĠassertThat ( statusCode ). isEqualTo ( HttpStatus . OK ) ĊĠĠĠĠĠ Ġ// Ġthere Ġare Ġtwo Ġun processed Ġnotifications Ġand Ġtwo Ġprocessed ĊĠĠĠĠĠ ĠassertThat ( json Tester . from ( body )). extract ing Json Path Value ("$ "). asList (). has Size ( 4 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġresponse Two Ġ= Ġget Notifications ( A _ USER , Ġ"/ notifications ") ĊĠĠĠ Ġwith ( response Two ) Ġ{ ĊĠĠĠĠĠ ĠassertThat ( statusCode ). isEqualTo ( HttpStatus . OK ) ĊĠĠĠĠĠ Ġ// Ġthere Ġshould Ġnow Ġbe Ġ 0 Ġun processed Ġnotifications ĊĠĠĠĠĠ ĠassertThat ( json Tester . from ( body )). extract ing Json Path Value ("$ "). asList (). has Size ( 4 ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġget Notifications ( user : ĠString , Ġurl : ĠString ): ĠResponseEntity < String > Ġ= ĊĠĠĠ Ġtest Rest Template . exchange ( ĊĠĠĠĠĠ Ġurl , ĊĠĠĠĠĠ ĠHttpMethod . GET , ĊĠĠĠĠĠ Ġentity Builder . entity With Jwt Author isation ( user , ĠNO _ RO LES ), ĊĠĠĠĠĠ ĠString :: class . java ĊĠĠĠ Ġ) ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĊĠĠĠ Ġprivate Ġconst Ġval ĠA _ USER Ġ= Ġ" API _ TEST _ USER " ĊĠĠĠ Ġprivate Ġconst Ġval ĠA _ USER _ NO _ DATA Ġ= Ġ" API _ TEST _ USER _ NO _ DATA " ĊĠĠĠ Ġprivate Ġval ĠNO _ RO LES Ġ= ĠlistOf < String >() ĊĠ Ġ} Ċ } Ċ