package Ġcom . github . kot l inte le gram bot . network . apic lient Ċ Ċ import Ġcom . github . kot l inte le gram bot . entities . Telegram File Ċ import Ġcom . github . kot l inte le gram bot . test utils . getFile AsString From Resources Ċ import Ġcom . github . kot l inte le gram bot . test utils . getFile From Resources Ċ import Ġcom . github . kot l inte le gram bot . test utils . multipart Boundary Ċ import Ġjunit . framework . TestCase . assertEquals Ċ import Ġokhttp 3 . mock webserver . Mock Response Ċ import Ġorg . junit . jupiter . api . Test Ċ Ċ class ĠSet Webhook IT Ġ: ĠApi Client IT () Ġ{ ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġinternal Ġfun Ġ` set Webhook Ġwithout Ġcertificate `() Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven Any Mock ed Response () ĊĊĠĠĠĠĠĠĠ Ġwhen Webhook IsSet Without Certificate () ĊĊĠĠĠĠĠĠĠ Ġthen Set Webhook Request Without Certificate Is Correct () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġinternal Ġfun Ġ` set Webhook Ġwithout Ġcertificate Ġbut Ġwith Ġip Ġaddress `() Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven Any Mock ed Response () ĊĊĠĠĠĠĠĠĠ Ġwhen Webhook IsSet Without Certificate And With IpAddress () ĊĊĠĠĠĠĠĠĠ Ġthen Set Webhook Request Without Certificate And With IpAddress Is Correct () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġinternal Ġfun Ġ` set Webhook Ġwith Ġcertificate Ġas Ġfile `() Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven Any Mock ed Response () ĊĊĠĠĠĠĠĠĠ Ġwhen Webhook IsSet With Certificate As File () ĊĊĠĠĠĠĠĠĠ Ġthen Set Webhook Request With Certificate As File Is Correct () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġinternal Ġfun Ġ` set Webhook Ġwith Ġcertificate Ġas Ġfile Ġand Ġwith Ġip Ġaddress `() Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven Any Mock ed Response () ĊĊĠĠĠĠĠĠĠ Ġwhen Webhook IsSet With Certificate As File And With IpAddress () ĊĊĠĠĠĠĠĠĠ Ġthen Set Webhook Request With Certificate As File And With IpAddress Is Correct () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġinternal Ġfun Ġ` set Webhook Ġwith Ġcertificate Ġas Ġfile Ġid `() Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven Any Mock ed Response () ĊĊĠĠĠĠĠĠĠ Ġwhen Webhook IsSet With Certificate As File Id () ĊĊĠĠĠĠĠĠĠ Ġthen Set Webhook Request With Certificate As File Id Is Correct () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġinternal Ġfun Ġ` set Webhook Ġwith Ġcertificate Ġas Ġfile Ġid Ġand Ġwith Ġip Ġaddress `() Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven Any Mock ed Response () ĊĊĠĠĠĠĠĠĠ Ġwhen Webhook IsSet With Certificate As File Id And With IpAddress () ĊĊĠĠĠĠĠĠĠ Ġthen Set Webhook Request With Certificate As File Id And With IpAddress Is Correct () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġinternal Ġfun Ġ` set Webhook Ġwith Ġcertificate Ġas Ġfile Ġurl `() Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven Any Mock ed Response () ĊĊĠĠĠĠĠĠĠ Ġwhen Webhook IsSet With Certificate As File Url () ĊĊĠĠĠĠĠĠĠ Ġthen Set Webhook Request With Certificate As File Url Is Correct () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġinternal Ġfun Ġ` set Webhook Ġwith Ġcertificate Ġas Ġfile Ġurl Ġand Ġwith Ġip Ġaddress `() Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven Any Mock ed Response () ĊĊĠĠĠĠĠĠĠ Ġwhen Webhook IsSet With Certificate As File Url And With IpAddress () ĊĊĠĠĠĠĠĠĠ Ġthen Set Webhook Request With Certificate As File Url And With IpAddress Is Correct () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġgiven Any Mock ed Response () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmocked Response Ġ= ĠMock Response () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Response Code ( 2 0 0 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Body ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ""" { ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ| " ok ": Ġtrue , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ| " result ": Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ| } """. trim Margin () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġmock WebServer . enqueue ( mocked Response ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġwhen Webhook IsSet Without Certificate () Ġ{ ĊĠĠĠĠĠĠĠ Ġsut . set Webhook ( url Ġ= ĠANY _ WEB HOOK _ URL ). execute () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġwhen Webhook IsSet Without Certificate And With IpAddress () Ġ{ ĊĠĠĠĠĠĠĠ Ġsut . set Webhook ( url Ġ= ĠANY _ WEB HOOK _ URL , Ġip Address Ġ= ĠANY _ IP _ ADDRESS ). execute () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġwhen Webhook IsSet With Certificate As File () Ġ{ ĊĠĠĠĠĠĠĠ Ġsut . set Webhook ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġurl Ġ= ĠANY _ WEB HOOK _ URL , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcertificate Ġ= ĠTelegram File . By File ( getFile From Resources < Set Webhook IT >(" certificate . pem ")) ĊĠĠĠĠĠĠĠ Ġ). execute () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġwhen Webhook IsSet With Certificate As File And With IpAddress () Ġ{ ĊĠĠĠĠĠĠĠ Ġsut . set Webhook ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġurl Ġ= ĠANY _ WEB HOOK _ URL , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcertificate Ġ= ĠTelegram File . By File ( getFile From Resources < Set Webhook IT >(" certificate . pem ")), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġip Address Ġ= ĠANY _ IP _ ADDRESS ĊĠĠĠĠĠĠĠ Ġ). execute () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġwhen Webhook IsSet With Certificate As File Id () Ġ{ ĊĠĠĠĠĠĠĠ Ġsut . set Webhook ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġurl Ġ= ĠANY _ WEB HOOK _ URL , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcertificate Ġ= ĠTelegram File . By File Id ( ANY _ FILE _ ID ) ĊĠĠĠĠĠĠĠ Ġ). execute () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġwhen Webhook IsSet With Certificate As File Id And With IpAddress () Ġ{ ĊĠĠĠĠĠĠĠ Ġsut . set Webhook ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġurl Ġ= ĠANY _ WEB HOOK _ URL , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcertificate Ġ= ĠTelegram File . By File Id ( ANY _ FILE _ ID ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġip Address Ġ= ĠANY _ IP _ ADDRESS ĊĠĠĠĠĠĠĠ Ġ). execute () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġwhen Webhook IsSet With Certificate As File Url () Ġ{ ĊĠĠĠĠĠĠĠ Ġsut . set Webhook ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġurl Ġ= ĠANY _ WEB HOOK _ URL , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcertificate Ġ= ĠTelegram File . By Url ( ANY _ FILE _ URL ) ĊĠĠĠĠĠĠĠ Ġ). execute () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġwhen Webhook IsSet With Certificate As File Url And With IpAddress () Ġ{ ĊĠĠĠĠĠĠĠ Ġsut . set Webhook ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġurl Ġ= ĠANY _ WEB HOOK _ URL , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcertificate Ġ= ĠTelegram File . By Url ( ANY _ FILE _ URL ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġip Address Ġ= ĠANY _ IP _ ADDRESS ĊĠĠĠĠĠĠĠ Ġ). execute () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġthen Set Webhook Request Without Certificate Is Correct () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= Ġmock WebServer . take Request () ĊĠĠĠĠĠĠĠ Ġval Ġrequest Body Ġ= Ġrequest . body . read Utf 8 () ĊĠĠĠĠĠĠĠ ĠassertEquals (" url = https % 3 A % 2 F % 2 F webhook . telegram . io ", Ġrequest Body ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġthen Set Webhook Request Without Certificate And With IpAddress Is Correct () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= Ġmock WebServer . take Request () ĊĠĠĠĠĠĠĠ Ġval Ġrequest Body Ġ= Ġrequest . body . read Utf 8 () ĊĠĠĠĠĠĠĠ ĠassertEquals (" url = https % 3 A % 2 F % 2 F webhook . telegram . io & ip _ address =$ ANY _ IP _ ADDRESS ", Ġrequest Body ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġthen Set Webhook Request With Certificate As File Is Correct () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= Ġmock WebServer . take Request () ĊĠĠĠĠĠĠĠ Ġval Ġmultipart Boundary Ġ= Ġrequest . multipart Boundary ĊĠĠĠĠĠĠĠ Ġval Ġrequest Body Ġ= Ġrequest . body . read Utf 8 (). trim Indent () ĊĠĠĠĠĠĠĠ Ġval Ġexpected RequestBody Ġ= ĠString . format ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠgetFile AsString From Resources < Set Webhook IT >(" set Webhook Multipart With Certificate RequestBody . txt "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmultipart Boundary ĊĠĠĠĠĠĠĠ Ġ). trim Indent () ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected RequestBody , Ġrequest Body ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġthen Set Webhook Request With Certificate As File And With IpAddress Is Correct () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= Ġmock WebServer . take Request () ĊĠĠĠĠĠĠĠ Ġval Ġmultipart Boundary Ġ= Ġrequest . multipart Boundary ĊĠĠĠĠĠĠĠ Ġval Ġrequest Body Ġ= Ġrequest . body . read Utf 8 (). trim Indent () ĊĠĠĠĠĠĠĠ Ġval Ġexpected RequestBody Ġ= ĠString . format ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠgetFile AsString From Resources < Set Webhook IT >(" set Webhook Multipart With Certificate And With IpAddress RequestBody . txt "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmultipart Boundary , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠANY _ IP _ ADDRESS ĊĠĠĠĠĠĠĠ Ġ). trim Indent () ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected RequestBody , Ġrequest Body ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġthen Set Webhook Request With Certificate As File Id Is Correct () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= Ġmock WebServer . take Request () ĊĠĠĠĠĠĠĠ Ġval Ġrequest Body Ġ= Ġrequest . body . read Utf 8 () ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" url = https % 3 A % 2 F % 2 F webhook . telegram . io & certificate = ru ka File Id 1 2 1 4 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrequest Body ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġthen Set Webhook Request With Certificate As File Id And With IpAddress Is Correct () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= Ġmock WebServer . take Request () ĊĠĠĠĠĠĠĠ Ġval Ġrequest Body Ġ= Ġrequest . body . read Utf 8 () ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" url = https % 3 A % 2 F % 2 F webhook . telegram . io & certificate = ru ka File Id 1 2 1 4 & ip _ address =$ ANY _ IP _ ADDRESS ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrequest Body ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġthen Set Webhook Request With Certificate As File Url Is Correct () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= Ġmock WebServer . take Request () ĊĠĠĠĠĠĠĠ Ġval Ġrequest Body Ġ= Ġrequest . body . read Utf 8 () ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" url = https % 3 A % 2 F % 2 F webhook . telegram . io & certificate = https % 3 A % 2 F % 2 F www . my cert . es % 2 F ru ka ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrequest Body ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġthen Set Webhook Request With Certificate As File Url And With IpAddress Is Correct () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= Ġmock WebServer . take Request () ĊĠĠĠĠĠĠĠ Ġval Ġrequest Body Ġ= Ġrequest . body . read Utf 8 () ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" url = https % 3 A % 2 F % 2 F webhook . telegram . io & certificate = https % 3 A % 2 F % 2 F www . my cert . es % 2 F ru ka & ip _ address =$ ANY _ IP _ ADDRESS ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrequest Body ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠANY _ WEB HOOK _ URL Ġ= Ġ" https :// webhook . telegram . io " ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠANY _ FILE _ ID Ġ= Ġ" ru ka File Id 1 2 1 4 " ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠANY _ FILE _ URL Ġ= Ġ" https :// www . my cert . es / ru ka " ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠANY _ IP _ ADDRESS Ġ= Ġ" 2 1 4 . 8 8 . 2 0 9 . 1 1 3 " ĊĠĠĠ Ġ} Ċ } Ċ