package Ġorg . got son . kom ga . infrastructure . jooq Ċ Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . assertj . core . api . Assertions . catch Throwable Ċ import Ġorg . got son . kom ga . domain . model . Author Ċ import Ġorg . got son . kom ga . domain . model . Book Metadata Aggregation Ċ import Ġorg . got son . kom ga . domain . model . make Library Ċ import Ġorg . got son . kom ga . domain . model . make Series Ċ import Ġorg . got son . kom ga . domain . persistence . Library Repository Ċ import Ġorg . got son . kom ga . domain . persistence . Series Repository Ċ import Ġorg . junit . jupiter . api . After All Ċ import Ġorg . junit . jupiter . api . After Each Ċ import Ġorg . junit . jupiter . api . Before All Ċ 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 . test . context . junit . jupiter . Spring Extension Ċ import Ġjava . time . LocalDate Ċ import Ġjava . time . LocalDateTime Ċ Ċ @ Extend With ( Spring Extension :: class ) Ċ @ SpringBootTest Ċ class ĠBook Metadata Aggregation Dao Test ( ĊĠ Ġ@ Autowired Ġprivate Ġval Ġbook Metadata Aggregation Dao : ĠBook Metadata Aggregation Dao , ĊĠ Ġ@ Autowired Ġprivate Ġval Ġseries Repository : ĠSeries Repository , ĊĠ Ġ@ Autowired Ġprivate Ġval Ġlibrary Repository : ĠLibrary Repository Ċ ) Ġ{ ĊĊĠ Ġprivate Ġval Ġlibrary Ġ= Ġmake Library () ĊĊĠ Ġ@ Before All ĊĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠ Ġlibrary Repository . insert ( library ) ĊĠ Ġ} ĊĊĠ Ġ@ After Each ĊĠ Ġfun Ġdelete Series () Ġ{ ĊĠĠĠ Ġseries Repository . findAll (). forEach Ġ{ ĊĠĠĠĠĠ Ġbook Metadata Aggregation Dao . delete ( it . id ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġseries Repository . delete All () ĊĠ Ġ} ĊĊĠ Ġ@ After All ĊĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠ Ġlibrary Repository . delete All () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` given Ġa Ġbook Metadata Aggregation Ġwhen Ġinserting Ġthen Ġit Ġis Ġpersisted `() Ġ{ ĊĠĠĠ Ġval Ġseries Ġ= Ġmake Series (" Series ", Ġlibrary Id Ġ= Ġlibrary . id ). also Ġ{ Ġseries Repository . insert ( it ) Ġ} ĊĊĠĠĠ Ġval Ġnow Ġ= ĠLocalDateTime . now () ĊĠĠĠ Ġval Ġmetadata Ġ= ĠBook Metadata Aggregation ( ĊĠĠĠĠĠ Ġauthors Ġ= ĠlistOf ( Author (" author ", Ġ" role ")), ĊĠĠĠĠĠ Ġrelease Date Ġ= ĠLocalDate . now (), ĊĠĠĠĠĠ Ġsummary Ġ= Ġ" Summary ", ĊĠĠĠĠĠ Ġsummary Number Ġ= Ġ" 1 ", ĊĠĠĠĠĠ Ġseries Id Ġ= Ġseries . id ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġbook Metadata Aggregation Dao . insert ( metadata ) ĊĠĠĠ Ġval Ġcreated Ġ= Ġbook Metadata Aggregation Dao . findById ( metadata . series Id ) ĊĊĠĠĠ ĠassertThat ( created . series Id ). isEqualTo ( series . id ) ĊĠĠĠ ĠassertThat ( created . created Date ). is Close To ( now , Ġoffset ) ĊĠĠĠ ĠassertThat ( created . last ModifiedDate ). is Close To ( now , Ġoffset ) ĊĊĠĠĠ ĠassertThat ( created . release Date ). isEqualTo ( metadata . release Date ) ĊĠĠĠ ĠassertThat ( created . summary ). isEqualTo ( metadata . summary ) ĊĠĠĠ ĠassertThat ( created . summary Number ). isEqualTo ( metadata . summary Number ) ĊĠĠĠ Ġwith ( created . authors . first ()) Ġ{ ĊĠĠĠĠĠ ĠassertThat ( name ). isEqualTo ( metadata . authors . first (). name ) ĊĠĠĠĠĠ ĠassertThat ( role ). isEqualTo ( metadata . authors . first (). role ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` given Ġa Ġminimum Ġbook Metadata Aggregation Ġwhen Ġinserting Ġthen Ġit Ġis Ġpersisted `() Ġ{ ĊĠĠĠ Ġval Ġseries Ġ= Ġmake Series (" Series ", Ġlibrary Id Ġ= Ġlibrary . id ). also Ġ{ Ġseries Repository . insert ( it ) Ġ} ĊĊĠĠĠ Ġval Ġnow Ġ= ĠLocalDateTime . now () ĊĠĠĠ Ġval Ġmetadata Ġ= ĠBook Metadata Aggregation ( ĊĠĠĠĠĠ Ġseries Id Ġ= Ġseries . id ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġbook Metadata Aggregation Dao . insert ( metadata ) ĊĠĠĠ Ġval Ġcreated Ġ= Ġbook Metadata Aggregation Dao . findById ( metadata . series Id ) ĊĊĠĠĠ ĠassertThat ( created . series Id ). isEqualTo ( series . id ) ĊĠĠĠ ĠassertThat ( created . created Date ). is Close To ( now , Ġoffset ) ĊĠĠĠ ĠassertThat ( created . last ModifiedDate ). is Close To ( now , Ġoffset ) ĊĊĠĠĠ ĠassertThat ( created . release Date ). isNull () ĊĠĠĠ ĠassertThat ( created . summary ). isBlank ĊĠĠĠ ĠassertThat ( created . summary Number ). isBlank ĊĠĠĠ ĠassertThat ( created . authors ). isEmpty () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` given Ġexisting Ġbook Metadata Aggregation Ġwhen Ġfinding Ġby Ġid Ġthen Ġmetadata Ġis Ġreturned `() Ġ{ ĊĠĠĠ Ġval Ġseries Ġ= Ġmake Series (" Series ", Ġlibrary Id Ġ= Ġlibrary . id ). also Ġ{ Ġseries Repository . insert ( it ) Ġ} ĊĊĠĠĠ Ġval Ġmetadata Ġ= ĠBook Metadata Aggregation ( ĊĠĠĠĠĠ Ġauthors Ġ= ĠlistOf ( Author (" author ", Ġ" role ")), ĊĠĠĠĠĠ Ġrelease Date Ġ= ĠLocalDate . now (), ĊĠĠĠĠĠ Ġsummary Ġ= Ġ" Summary ", ĊĠĠĠĠĠ Ġseries Id Ġ= Ġseries . id ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġbook Metadata Aggregation Dao . insert ( metadata ) ĊĊĠĠĠ Ġval Ġfound Ġ= Ġbook Metadata Aggregation Dao . findById ( series . id ) ĊĊĠĠĠ ĠassertThat ( found ). isNotNull ĊĠĠĠ ĠassertThat ( found . summary ). isEqualTo (" Summary ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` given Ġnon - existing Ġbook Metadata Aggregation Ġwhen Ġfinding Ġby Ġid Ġthen Ġexception Ġis Ġthrown `() Ġ{ ĊĠĠĠ Ġval Ġfound Ġ= Ġcatch Throwable Ġ{ Ġbook Metadata Aggregation Dao . findById (" 1 2 8 7 4 2 ") Ġ} ĊĊĠĠĠ ĠassertThat ( found ). isInstanceOf ( Exception :: class . java ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` given Ġnon - existing Ġbook Metadata Aggregation Ġwhen Ġfind ById OrNull Ġthen Ġnull Ġis Ġreturned `() Ġ{ ĊĠĠĠ Ġval Ġfound Ġ= Ġbook Metadata Aggregation Dao . findById OrNull (" 1 2 8 7 4 2 ") ĊĊĠĠĠ ĠassertThat ( found ). isNull () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` given Ġa Ġbook Metadata Aggregation Ġwhen Ġupdating Ġthen Ġit Ġis Ġpersisted `() Ġ{ ĊĠĠĠ Ġval Ġseries Ġ= Ġmake Series (" Series ", Ġlibrary Id Ġ= Ġlibrary . id ). also Ġ{ Ġseries Repository . insert ( it ) Ġ} ĊĊĠĠĠ Ġval Ġmetadata Ġ= ĠBook Metadata Aggregation ( ĊĠĠĠĠĠ Ġauthors Ġ= ĠlistOf ( Author (" author ", Ġ" role ")), ĊĠĠĠĠĠ Ġrelease Date Ġ= ĠLocalDate . now (), ĊĠĠĠĠĠ Ġsummary Ġ= Ġ" Summary ", ĊĠĠĠĠĠ Ġsummary Number Ġ= Ġ" 1 ", ĊĠĠĠĠĠ Ġseries Id Ġ= Ġseries . id ĊĠĠĠ Ġ) ĊĠĠĠ Ġbook Metadata Aggregation Dao . insert ( metadata ) ĊĠĠĠ Ġval Ġcreated Ġ= Ġbook Metadata Aggregation Dao . findById ( metadata . series Id ) ĊĊĠĠĠ Ġval Ġmodification Date Ġ= ĠLocalDateTime . now () ĊĊĠĠĠ Ġval Ġupdated Ġ= Ġwith ( created ) Ġ{ ĊĠĠĠĠĠ Ġcopy ( ĊĠĠĠĠĠĠĠ Ġrelease Date Ġ= ĠLocalDate . now (). plus Years ( 1 ), ĊĠĠĠĠĠĠĠ Ġsummary Ġ= Ġ" Summary Updated ", ĊĠĠĠĠĠĠĠ Ġsummary Number Ġ= Ġ" 2 ", ĊĠĠĠĠĠĠĠ Ġauthors Ġ= ĠlistOf ( Author (" author Updated ", Ġ" role Updated "), ĠAuthor (" author 2 ", Ġ" role 2 ")), ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġbook Metadata Aggregation Dao . update ( updated ) ĊĠĠĠ Ġval Ġmodified Ġ= Ġbook Metadata Aggregation Dao . findById ( updated . series Id ) ĊĊĠĠĠ ĠassertThat ( modified . series Id ). isEqualTo ( series . id ) ĊĠĠĠ ĠassertThat ( modified . created Date ). isEqualTo ( updated . created Date ) ĊĠĠĠ ĠassertThat ( modified . last ModifiedDate ) ĊĠĠĠĠĠ Ġ. is Close To ( modification Date , Ġoffset ) ĊĠĠĠĠĠ Ġ. isNot EqualTo ( modified . created Date ) ĊĊĠĠĠ ĠassertThat ( modified . release Date ). isEqualTo ( updated . release Date ) ĊĠĠĠ ĠassertThat ( modified . summary ). isEqualTo ( updated . summary ) ĊĠĠĠ ĠassertThat ( modified . authors ). has Size ( 2 ) ĊĠĠĠ ĠassertThat ( modified . authors . map Ġ{ Ġit . name Ġ}). contains Exactly In Any Order Elements Of ( updated . authors . map Ġ{ Ġit . name Ġ}) ĊĠĠĠ ĠassertThat ( modified . authors . map Ġ{ Ġit . role Ġ}). contains Exactly In Any Order Elements Of ( updated . authors . map Ġ{ Ġit . role Ġ}) ĊĠ Ġ} Ċ } Ċ