package Ġorg . relax ed base . web . rest Ċ Ċ import Ġjava . time . Instant Ċ import Ġorg . assertj . core . api . Assertions For Class Types . assertThat Ċ import Ġorg . hamcrest . Matchers . has Item Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . relax ed base . Rel ax ed base App Ċ import Ġorg . relax ed base . domain . Persistent Audit Event Ċ import Ġorg . relax ed base . repository . Persistence Audit Event Repository Ċ import Ġorg . relax ed base . security . ADMIN Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . autoconfigure . web . servlet . Auto Configure MockMvc Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ import Ġorg . springframework . http . MediaType Ċ import Ġorg . springframework . security . test . context . support . With Mock User Ċ import Ġorg . springframework . test . web . servlet . MockMvc Ċ import Ġorg . springframework . test . web . servlet . request . MockMvc Request Builders . get Ċ import Ġorg . springframework . test . web . servlet . result . MockMvc Result Matchers . content Ċ import Ġorg . springframework . test . web . servlet . result . MockMvc Result Matchers . header Ċ import Ġorg . springframework . test . web . servlet . result . MockMvc Result Matchers . json Path Ċ import Ġorg . springframework . test . web . servlet . result . MockMvc Result Matchers . status Ċ import Ġorg . springframework . transaction . annotation . Transactional Ċ Ċ private Ġconst Ġval ĠSAMPLE _ PR INC IP AL Ġ= Ġ" SAMPLE _ PR INC IP AL " Ċ private Ġconst Ġval ĠSAMPLE _ TYPE Ġ= Ġ" SAMPLE _ TYPE " Ċ private Ġval ĠSAMPLE _ TIMESTAMP Ġ= ĠInstant . parse (" 2 0 1 5 - 0 8 - 0 4 T 1 0 : 1 1 : 3 0 Z ") Ċ private Ġconst Ġval ĠSE CON DS _ PER _ DAY Ġ= Ġ( 6 0 Ġ* Ġ 6 0 Ġ* Ġ 2 4 ). to Long () Ċ Ċ /** Ċ Ġ* ĠIntegration Ġtests Ġfor Ġthe Ġ[ Audit Resource ] ĠREST Ġcontroller . Ċ Ġ*/ Ċ @ Auto Configure MockMvc Ċ @ With Mock User ( author ities Ġ= Ġ[ ADMIN ]) Ċ @ SpringBootTest ( classes Ġ= Ġ[ Rel ax ed base App :: class ]) Ċ @ Transactional Ċ class ĠAudit Resource IT Ġ{ ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġaudit Event Repository : ĠPersistence Audit Event Repository ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġaudit Event : ĠPersistent Audit Event ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġrest Audit MockMvc : ĠMock Mvc ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun Ġinit Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġaudit Event Repository . delete All () ĊĠĠĠĠĠĠĠ Ġaudit Event Ġ= ĠPersistent Audit Event ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġaudit EventType Ġ= ĠSAMPLE _ TYPE , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġprincipal Ġ= ĠSAMPLE _ PR INC IP AL , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġaudit Event Date Ġ= ĠSAMPLE _ TIMESTAMP ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( Exception :: class ) ĊĠĠĠ Ġfun ĠgetAll Aud its () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠInitialize Ġthe Ġdatabase ĊĠĠĠĠĠĠĠ Ġaudit Event Repository . save ( audit Event ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠGet Ġall Ġthe Ġaud its ĊĠĠĠĠĠĠĠ Ġrest Audit MockMvc . perform ( get ("/ management / aud its ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( content (). contentType ( MediaType . APPLICATION _ JSON _ VALUE )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( json Path ("\ $. [* ]. principal "). value ( has Item ( SAMPLE _ PR INC IP AL ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( Exception :: class ) ĊĠĠĠ Ġfun Ġget Audit () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠInitialize Ġthe Ġdatabase ĊĠĠĠĠĠĠĠ Ġaudit Event Repository . save ( audit Event ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠGet Ġthe Ġaudit ĊĠĠĠĠĠĠĠ Ġrest Audit MockMvc . perform ( get ("/ management / aud its /{ id }", Ġaudit Event . id )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( content (). contentType ( MediaType . APPLICATION _ JSON _ VALUE )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( json Path ("\ $. principal "). value ( SAMPLE _ PR INC IP AL )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( Exception :: class ) ĊĠĠĠ Ġfun Ġget Aud its By Date () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠInitialize Ġthe Ġdatabase ĊĠĠĠĠĠĠĠ Ġaudit Event Repository . save ( audit Event ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠGenerate Ġdates Ġfor Ġselecting Ġaud its Ġby Ġdate , Ġmaking Ġsure Ġthe Ġperiod Ġwill Ġcontain Ġthe Ġaudit ĊĠĠĠĠĠĠĠ Ġval Ġfrom Date Ġ= ĠSAMPLE _ TIMESTAMP . minus Seconds ( SECONDS _ PER _ DAY ). toString (). substring ( 0 , Ġ 1 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġto Date Ġ= ĠSAMPLE _ TIMESTAMP . plus Seconds ( SECONDS _ PER _ DAY ). toString (). substring ( 0 , Ġ 1 0 ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠGet Ġthe Ġaudit ĊĠĠĠĠĠĠĠ Ġrest Audit MockMvc . perform ( get ("/ management / aud its ? from Date =$ from Date & toDate =$ toDate ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( content (). contentType ( MediaType . APPLICATION _ JSON _ VALUE )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( json Path ("\ $. [* ]. principal "). value ( has Item ( SAMPLE _ PR INC IP AL ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( Exception :: class ) ĊĠĠĠ Ġfun Ġget Non Existing Aud its By Date () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠInitialize Ġthe Ġdatabase ĊĠĠĠĠĠĠĠ Ġaudit Event Repository . save ( audit Event ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠGenerate Ġdates Ġfor Ġselecting Ġaud its Ġby Ġdate , Ġmaking Ġsure Ġthe Ġperiod Ġwill Ġnot Ġcontain Ġthe Ġsample Ġaudit ĊĠĠĠĠĠĠĠ Ġval Ġfrom Date Ġ= ĠSAMPLE _ TIMESTAMP . minus Seconds ( 2 Ġ* ĠSE CON DS _ PER _ DAY ). toString (). substring ( 0 , Ġ 1 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġto Date Ġ= ĠSAMPLE _ TIMESTAMP . minus Seconds ( SECONDS _ PER _ DAY ). toString (). substring ( 0 , Ġ 1 0 ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠQuery Ġaud its Ġbut Ġexpect Ġno Ġresults ĊĠĠĠĠĠĠĠ Ġrest Audit MockMvc . perform ( get ("/ management / aud its ? from Date =$ from Date & toDate =$ toDate ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( content (). contentType ( MediaType . APPLICATION _ JSON _ VALUE )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( header (). string (" X - Total - Count ", Ġ" 0 ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( Exception :: class ) ĊĠĠĠ Ġfun Ġget Non Existing Audit () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠGet Ġthe Ġaudit ĊĠĠĠĠĠĠĠ Ġrest Audit MockMvc . perform ( get ("/ management / aud its /{ id }", Ġjava . lang . Long . MAX _ VALUE )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). is NotFound ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( Exception :: class ) ĊĠĠĠ Ġfun Ġtest Persistent Audit Event Equals () Ġ{ ĊĠĠĠĠĠĠĠ Ġequals Verifier ( Persistent Audit Event :: class ) ĊĠĠĠĠĠĠĠ Ġval Ġaudit Event 1 Ġ= ĠPersistent Audit Event ( id Ġ= Ġ 1 L ) ĊĠĠĠĠĠĠĠ Ġval Ġaudit Event 2 Ġ= ĠPersistent Audit Event ( id Ġ= Ġaudit Event 1 . id ) ĊĠĠĠĠĠĠĠ ĠassertThat ( audit Event 1 ). isEqualTo ( audit Event 2 ) ĊĠĠĠĠĠĠĠ Ġaudit Event 2 . id Ġ= Ġ 2 L ĊĠĠĠĠĠĠĠ ĠassertThat ( audit Event 1 ). isNot EqualTo ( audit Event 2 ) ĊĠĠĠĠĠĠĠ Ġaudit Event 1 . id Ġ= Ġnull ĊĠĠĠĠĠĠĠ ĠassertThat ( audit Event 1 ). isNot EqualTo ( audit Event 2 ) ĊĠĠĠ Ġ} Ċ } Ċ