package Ġde . de bu gle vel . pd ff orm fill er . form Ċ Ċ import Ġde . de bu gle vel . pd ff orm fill er . Pdf Utils Ċ import Ġde . de bu gle vel . pd ff orm fill er . pdf . Test DataProvider Ċ import Ġde . de bu gle vel . pd ff orm fill er . with Response On Exception Ċ import Ġio . mic ronaut . http . Basic Auth Ċ import Ġio . mic ronaut . http . HttpStatus Ċ import Ġio . mic ronaut . http . MediaType Ċ import Ġio . mic ronaut . test . annotation . Mic ronaut Test Ċ import Ġorg . assertj . core . api . Assertions Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . Test Instance Ċ import Ġorg . junit . jupiter . params . Parameterized Test Ċ import Ġorg . junit . jupiter . params . provider . Method Source Ċ import Ġjava . time . LocalDateTime Ċ import Ġjava . time . temporal . Ch rono Unit Ċ import Ġjava . util .* Ċ import Ġjavax . inject . Inject Ċ import Ġkotlin . io . path . Experimental Path Api Ċ import Ġkotlin . io . path . read Bytes Ċ Ċ @ Experimental Path Api Ċ @ Mic ronaut Test Ċ @ Test Instance ( Test Instance . Lifecycle . PER _ CLASS ) Ċ class ĠForm Client Tests Ġ{ ĊĠĠĠ Ġfun Ġform Provider () Ġ= ĠTest DataProvider . form Provider () ĊĠĠĠ Ġfun Ġfilled Form Provider () Ġ= ĠTest DataProvider . filled Form Provider () ĊĊĠĠĠ Ġprivate Ġval Ġbasic Auth Ġ= ĠBasic Auth (" username ", Ġ" password ") ĊĊĠĠĠ Ġ@ Inject ĊĠĠĠ Ġlateinit Ġvar Ġform Client : ĠForm Client ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Ġform `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠArrange ĊĠĠĠĠĠĠĠ Ġval Ġminimal Pdf Bytes Ġ= ĠPdf Utils . get Minimal Pdf (). toByteArray () ĊĠĠĠĠĠĠĠ Ġval Ġadd Form Request Ġ= ĠAdd Form Request ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpdf Base 6 4 Ġ= ĠBase 6 4 . get Encoder (). encode ToString ( minimal Pdf Bytes ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġadd Form Response Ġ= Ġform Client . post One ( add Form Request ). body () !! ĊĊĠĠĠĠĠĠĠ Ġ// ĠAct ĊĠĠĠĠĠĠĠ Ġval ĠhttpResponse Ġ= Ġform Client . getOne ( add Form Response . id ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠAssert ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . status ). isEqualTo ( HttpStatus . OK ) ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . contentType . get ()). isEqualTo ( MediaType . APPLICATION _ JSON _ TYPE ) ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . content Length ). is GreaterThan ( 0 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġget Form Response Ġ= ĠhttpResponse . body . get () ĊĠĠĠĠĠĠĠ ĠassertThat ( get Form Response . id ). isNotNull ĊĠĠĠĠĠĠĠ ĠassertThat ( Base 6 4 . get Decoder (). decode ( get Form Response . pdf Base 6 4 )). isEqualTo ( minimal Pdf Bytes ) ĊĠĠĠĠĠĠĠ ĠassertThat ( get Form Response . created On ). isNotNull ĊĠĠĠĠĠĠĠ ĠassertThat ( get Form Response . lastModified On ). isNotNull ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Ġform Ġwith Ġan Ġunknown Ġid `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠArrange ĊĠĠĠĠĠĠĠ Ġval Ġunknown Id Ġ= ĠUUID . randomUUID () ĊĊĠĠĠĠĠĠĠ Ġ// ĠAct ĊĠĠĠĠĠĠĠ Ġval ĠhttpResponse Ġ= Ġform Client . getOne ( unknown Id ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠAssert ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . status ). isEqualTo ( HttpStatus . NOT _ FOUND ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Ġall Ġforms `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠArrange ĊĠĠĠĠĠĠĠ Ġform Client . delete All ( basic Auth ) ĊĊĠĠĠĠĠĠĠ Ġfor Ġ( iteration Ġin Ġ 1 .. 1 0 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠArrange ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġminimal Pdf Bytes Ġ= ĠPdf Utils . get Minimal Pdf (). toByteArray () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġadd Form Request Ġ= ĠAdd Form Request ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpdf Base 6 4 Ġ= ĠBase 6 4 . get Encoder (). encode ToString ( minimal Pdf Bytes ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġadd Form Response Ġ= Ġform Client . post One ( add Form Request ). body () !! ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠAct ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval ĠhttpResponse Ġ= Ġform Client . getList ( basic Auth ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠAssert ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . status ). isEqualTo ( HttpStatus . OK ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . contentType . get ()). isEqualTo ( MediaType . APPLICATION _ JSON _ TYPE ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . content Length ). is GreaterThan ( 0 ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġget Form Responses Ġ= ĠhttpResponse . body . get () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( get Form Responses . size ). isEqualTo ( iteration ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( get Form Responses ). all Satisf y Ġ{ ĠassertThat ( it . id ). isNotNull () Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( get Form Responses ). all Satisf y Ġ{ ĠassertThat ( it . created On ). isNotNull () Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( get Form Responses ). all Satisf y Ġ{ ĠassertThat ( it . lastModified On ). isNotNull () Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` add Ġform `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠArrange ĊĊĠĠĠĠĠĠĠ Ġ// ĠAct ĊĠĠĠĠĠĠĠ Ġval Ġminimal Pdf Bytes Ġ= ĠPdf Utils . get Minimal Pdf (). toByteArray () ĊĠĠĠĠĠĠĠ Ġval Ġadd Form Request Ġ= ĠAdd Form Request ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpdf Base 6 4 Ġ= ĠBase 6 4 . get Encoder (). encode ToString ( minimal Pdf Bytes ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval ĠhttpResponse Ġ= Ġform Client . post One ( add Form Request ) ĊĠĠĠĠĠĠĠ Ġval Ġadd Form Response Ġ= ĠhttpResponse . body () !! ĊĊĠĠĠĠĠĠĠ Ġ// ĠAssert ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . status ). isEqualTo ( HttpStatus . CREATED ) ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . contentType . get ()). isEqualTo ( MediaType . APPLICATION _ JSON _ TYPE ) ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . content Length ). is GreaterThan ( 0 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . header (" Location ")). contains ( add Form Response . id . toString ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġget Form Response Ġ= Ġform Client . getOne ( add Form Response . id ). body . get () ĊĠĠĠĠĠĠĠ ĠassertThat ( add Form Response . id ). isNotNull ĊĠĠĠĠĠĠĠ ĠassertThat ( get Form Response . id ). isEqualTo ( add Form Response . id ) ĊĠĠĠĠĠĠĠ ĠassertThat ( Base 6 4 . get Decoder (). decode ( get Form Response . pdf Base 6 4 )). isEqualTo ( minimal Pdf Bytes ) ĊĠĠĠĠĠĠĠ ĠassertThat ( get Form Response . created On ). is Close To ( LocalDateTime . now (), ĠAssertions . within ( 2 , ĠCh rono Unit . SECONDS )) ĊĠĠĠĠĠĠĠ ĠassertThat ( get Form Response . lastModified On ). is Close To ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLocalDateTime . now (), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssertions . within ( 2 , ĠCh rono Unit . SECONDS ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` add Ġinvalid Ġform `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠArrange ĊĊĠĠĠĠĠĠĠ Ġ// ĠAct ĊĠĠĠĠĠĠĠ Ġval Ġbytes Ġ= Ġ" foobar ". toByteArray () ĊĠĠĠĠĠĠĠ Ġval Ġadd Form Request Ġ= ĠAdd Form Request ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpdf Base 6 4 Ġ= ĠBase 6 4 . get Encoder (). encode ToString ( bytes ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval ĠhttpResponse Ġ= Ġwith Response On Exception Ġ{ Ġform Client . post One ( add Form Request ) Ġ} ĊĊĠĠĠĠĠĠĠ Ġ// ĠAssert ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . status ). isEqualTo ( HttpStatus . BAD _ REQUEST ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` delete Ġform `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠArrange ĊĠĠĠĠĠĠĠ Ġform Client . delete All ( basic Auth ) ĊĠĠĠĠĠĠĠ Ġval Ġminimal Pdf Bytes Ġ= ĠPdf Utils . get Minimal Pdf (). toByteArray () ĊĠĠĠĠĠĠĠ Ġval Ġadd Form Request Ġ= ĠAdd Form Request ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpdf Base 6 4 Ġ= ĠBase 6 4 . get Encoder (). encode ToString ( minimal Pdf Bytes ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġadd Form Response Ġ= Ġform Client . post One ( add Form Request ). body () !! ĊĊĠĠĠĠĠĠĠ Ġ// ĠAct ĊĠĠĠĠĠĠĠ Ġval ĠhttpResponse Ġ= Ġform Client . delete One ( add Form Response . id ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠAssert ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . status ). isEqualTo ( HttpStatus . NO _ CONTENT ) ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . content Length ). isEqualTo (- 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġget Form Responses Ġ= Ġform Client . getList ( basic Auth ). body . get () ĊĠĠĠĠĠĠĠ ĠassertThat ( get Form Responses . size ). isEqualTo ( 0 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` delete Ġform Ġwith Ġunknown Ġid `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠArrange ĊĠĠĠĠĠĠĠ Ġval Ġunknown Id Ġ= ĠUUID . randomUUID () ĊĊĠĠĠĠĠĠĠ Ġ// ĠAct ĊĠĠĠĠĠĠĠ Ġval ĠhttpResponse Ġ= Ġform Client . delete One ( unknown Id ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠAssert ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . status ). isEqualTo ( HttpStatus . NOT _ FOUND ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` delete Ġall Ġforms `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠArrange ĊĠĠĠĠĠĠĠ Ġform Client . delete All ( basic Auth ) ĊĊĠĠĠĠĠĠĠ Ġfor Ġ( iteration Ġin Ġ 1 .. 1 0 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġminimal Pdf Bytes Ġ= ĠPdf Utils . get Minimal Pdf (). toByteArray () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġadd Form Request Ġ= ĠAdd Form Request ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpdf Base 6 4 Ġ= ĠBase 6 4 . get Encoder (). encode ToString ( minimal Pdf Bytes ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġadd Form Response Ġ= Ġform Client . post One ( add Form Request ). body () !! ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġ// ĠAct ĊĠĠĠĠĠĠĠ Ġval ĠhttpResponse Ġ= Ġform Client . delete All ( basic Auth ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠAssert ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . status ). isEqualTo ( HttpStatus . NO _ CONTENT ) ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . content Length ). isEqualTo (- 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġget Form Responses Ġ= Ġform Client . getList ( basic Auth ). body . get () ĊĠĠĠĠĠĠĠ ĠassertThat ( get Form Responses . size ). isEqualTo ( 0 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Parameterized Test ĊĠĠĠ Ġ@ Method Source (" filled Form Provider ") ĊĠĠĠ Ġfun Ġ` get Ġfields Ġand Ġvalues `( test Filled Form : ĠTest DataProvider . Test Filled Form ) Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠArrange ĊĠĠĠĠĠĠĠ Ġval Ġbytes Ġ= Ġtest Filled Form . pdf Path . read Bytes () ĊĠĠĠĠĠĠĠ Ġval Ġadd Form Request Ġ= ĠAdd Form Request ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpdf Base 6 4 Ġ= ĠBase 6 4 . get Encoder (). encode ToString ( bytes ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġadd Form Response Ġ= Ġform Client . post One ( add Form Request ). body () !! ĊĊĠĠĠĠĠĠĠ Ġ// ĠAct ĊĠĠĠĠĠĠĠ Ġval ĠhttpResponse Ġ= Ġform Client . getOne ( add Form Response . id ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠAssert ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . status ). isEqualTo ( HttpStatus . OK ) ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . contentType . get ()). isEqualTo ( MediaType . APPLICATION _ JSON _ TYPE ) ĊĠĠĠĠĠĠĠ ĠassertThat ( httpResponse . content Length ). is GreaterThan ( 0 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġget Form Response Ġ= ĠhttpResponse . body . get () ĊĠĠĠĠĠĠĠ ĠassertThat ( get Form Response . id ). isNotNull ĊĠĠĠĠĠĠĠ ĠassertThat ( Base 6 4 . get Decoder (). decode ( get Form Response . pdf Base 6 4 )). isEqualTo ( bytes ) ĊĠĠĠĠĠĠĠ ĠassertThat ( get Form Response . values ). contains Exactly In Any Order Entries Of ( test Filled Form . expected Field Values ) ĊĠĠĠĠĠĠĠ ĠassertThat ( get Form Response . created On ). isNotNull ĊĠĠĠĠĠĠĠ ĠassertThat ( get Form Response . lastModified On ). isNotNull ĊĠĠĠ Ġ} Ċ Ċ // ĠĠĠ Ġ@ Test Ċ // ĠĠĠ Ġfun Ġ` update Ġform `() Ġ{ Ċ // ĠĠĠĠĠĠĠ Ġ// ĠArrange Ċ // ĠĠĠĠĠĠĠ Ġval Ġminimal Pdf Bytes Ġ= ĠPdf Utils . get Minimal Pdf (). toByteArray () Ċ // ĠĠĠĠĠĠĠ Ġval Ġform Ġ= ĠForm ( id Ġ= Ġnull , Ġpdf Ġ= Ġminimal Pdf Bytes ) Ċ // ĠĠĠĠĠĠĠ Ġval Ġadded Form Ġ= Ġservice . add ( form ) Ċ // Ċ // ĠĠĠĠĠĠĠ Ġval Ġretrieved Form Ġ= Ġservice . get ( added Form . id !! ) Ċ // Ċ // ĠĠĠĠĠĠĠ Ġ// ĠAct Ċ // ĠĠĠĠĠĠĠ Ġval Ġupdated Pdf Bytes Ġ= Ġminimal Pdf Bytes . plus (" updated ". toByteArray ()) Ċ // ĠĠĠĠĠĠĠ Ġretrieved Form . pdf Ġ= Ġupdated Pdf Bytes Ċ // ĠĠĠĠĠĠĠ Ġval Ġupdated Form Ġ= Ġservice . update ( retrie ved Form . id !! , Ġretrieved Form ) Ċ // Ċ // ĠĠĠĠĠĠĠ Ġ// ĠAssert Ċ // ĠĠĠĠĠĠĠ Ġval Ġretrieved 2 Form Ġ= Ġservice . get ( added Form . id !! ) Ċ // ĠĠĠĠĠĠĠ Ġset Of ( updated Form , Ġretrieved 2 Form ). forEach Ġ{ Ċ // ĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( it . id ). isNotNull Ċ // ĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( it . pdf ). isEqualTo ( updated Pdf Bytes ) Ċ // ĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( it . created On ). is Close To ( LocalDateTime . now (), ĠAssertions . within ( 2 , ĠCh rono Unit . SECONDS )) Ċ // ĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( it . lastModified On ). is Close To ( LocalDateTime . now (), ĠAssertions . within ( 2 , ĠCh rono Unit . SECONDS )) Ċ // ĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( it . lastModified On ). is After ( retrie ved Form . created On ) Ċ // ĠĠĠĠĠĠĠ Ġ} Ċ // ĠĠĠ Ġ} Ċ Ċ // ĠĠĠ Ġ@ Test Ċ // ĠĠĠ Ġfun Ġ` update Ġform Ġwith Ġunknown Ġid `() Ġ{ Ċ // ĠĠĠĠĠĠĠ Ġ// ĠArrange Ċ // ĠĠĠĠĠĠĠ Ġval Ġunknown Id Ġ= ĠUUID . randomUUID () Ċ // Ċ // ĠĠĠĠĠĠĠ Ġval Ġform Ġ= ĠForm ( Ċ // ĠĠĠĠĠĠĠĠĠĠĠ Ġid Ġ= Ġunknown Id , Ċ // ĠĠĠĠĠĠĠĠĠĠĠ Ġpdf Ġ= ĠPdf Utils . get Minimal Pdf (). toByteArray (), Ċ // ĠĠĠĠĠĠĠ Ġ) Ċ // Ċ // ĠĠĠĠĠĠĠ Ġ// ĠAct Ċ // ĠĠĠĠĠĠĠ Ġval Ġexception Ġ= ĠassertThrows < Form Service . Form NotFoundException > Ġ{ Ġservice . update ( unknown Id , Ġform ) Ġ} Ċ // ĠĠĠ Ġ} Ċ }