package Ġcom . example . authentication module Ċ Ċ import Ġcom . example . authentication module . base . Implementation Test Ċ import Ġcom . example . authentication module . base . Test Properties Ċ import Ġcom . example . authentication module . base . TestUtil . Companion . getResource As Text Ċ import Ġcom . example . authentication module . core . authorization . devices . fit bit . Fit bit DataSource Ċ import Ġcom . example . authentication module . core . common . ac ces spar ams . Access Params Ċ import Ġcom . example . authentication module . core . common . ac ces spar ams . OAuth 2 Access Params Ċ import Ġcom . example . authentication module . core . common . util . serializer . Configured ObjectMapper Ċ import Ġcom . example . authentication module . implementation . repository . Mongo Access Params Repository Ċ import Ġcom . fasterxml . jackson . databind . JsonNode Ċ import Ġio . vertx . core . Vert x Ċ import Ġio . vertx . junit 5 . Vert x TestContext Ċ import Ġorg . junit . jupiter . api . Assertions .* Ċ import Ġorg . junit . jupiter . api . DisplayName Ċ import Ġorg . junit . jupiter . api . Test Ċ Ċ /** Ċ Ġ* ĠIntegration Ġtests Ġfor Ġ[ Mongo Access Params Repository ] Ċ Ġ*/ Ċ class ĠMongo Access Param Repository Test Ġ: ĠImplementation Test () Ġ{ ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġparams Can Be Inserted ( test Context : ĠVert x TestContext ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠuserId Ġ= Ġ" upsert Test " ĊĠĠĠĠĠĠĠ Ġval Ġaccess Params Ġ= Ġget Mock Fit bit Access Params ( userId ) ĊĠĠĠĠĠĠĠ Ġval Ġrepository Ġ= Ġmain Vert icle . access Params Repository ĊĊĠĠĠĠĠĠĠ Ġrepository . upsert ( access Params ) ĊĠĠĠĠĠĠĠ Ġrepository . upsert ( getMock Fit bit Access Params (" dummy 1 ")) ĊĠĠĠĠĠĠĠ Ġrepository . upsert ( getMock Fit bit Access Params (" dummy 2 ")) ĊĊĠĠĠĠĠĠĠ Ġtest Context . complete Now () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġparams Can Be Retrie ved ( test Context : ĠVert x TestContext ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠuserId Ġ= Ġ" params Can Be Retrie ved " ĊĠĠĠĠĠĠĠ Ġval Ġaccess Params Ġ= Ġget Mock Fit bit Access Params ( userId ) Ġas ĠOAuth 2 Access Params ĊĠĠĠĠĠĠĠ Ġval Ġrepository Ġ= Ġmain Vert icle . access Params Repository ĊĊĠĠĠĠĠĠĠ Ġrepository . upsert ( access Params ) ĊĠĠĠĠĠĠĠ Ġrepository . upsert ( getMock Fit bit Access Params (" dummy 1 ")) ĊĠĠĠĠĠĠĠ Ġrepository . upsert ( getMock Fit bit Access Params (" dummy 2 ")) ĊĠĠĠĠĠĠĠ ĠThread . sleep ( 3 0 0 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġqueried Params Ġ= Ġrepository . get Latest By Internal Or External UserId And DataSource Id ( userId , ĠFit bit DataSource . DATA _ SOURCE _ ID ) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( quer ied Params ) ĊĠĠĠĠĠĠĠ Ġqueried Params Ġas ĠOAuth 2 Access Params ĊĠĠĠĠĠĠĠ ĠassertEquals ( access Params . id , Ġqueried Params . id ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( access Params . internal UserId , Ġqueried Params . internal UserId ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( access Params . params , Ġqueried Params . params ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( access Params . dataSource Id , Ġqueried Params . dataSource Id ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( access Params . external UserId , Ġqueried Params . external UserId ) ĊĊĠĠĠĠĠĠĠ Ġtest Context . complete Now () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġnull Is Returned When Not Present ( test Context : ĠVert x TestContext ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠuserId Ġ= Ġ" params Can Be Retrie ved " ĊĠĠĠĠĠĠĠ Ġval Ġaccess Params Ġ= Ġget Mock Fit bit Access Params ( userId ) Ġas ĠOAuth 2 Access Params ĊĠĠĠĠĠĠĠ Ġval Ġrepository Ġ= Ġmain Vert icle . access Params Repository ĊĊĠĠĠĠĠĠĠ Ġrepository . upsert ( access Params ) ĊĠĠĠĠĠĠĠ ĠThread . sleep ( 3 0 0 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġqueried Params Ġ= Ġrepository . get Latest By Internal Or External UserId And DataSource Id (" dummy ", ĠFit bit DataSource . DATA _ SOURCE _ ID ) ĊĠĠĠĠĠĠĠ ĠassertNull ( quer ied Params ) ĊĊĠĠĠĠĠĠĠ Ġtest Context . complete Now () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġparams Can Be Qu er ied For Ex istence ( test Context : ĠVert x TestContext ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠuserId Ġ= Ġ" params Can Be Qu er ied For Ex istence " ĊĠĠĠĠĠĠĠ Ġval Ġaccess Params Ġ= Ġget Mock Fit bit Access Params ( userId ) Ġas ĠOAuth 2 Access Params ĊĠĠĠĠĠĠĠ Ġval Ġrepository Ġ= Ġmain Vert icle . access Params Repository ĊĊĠĠĠĠĠĠĠ Ġrepository . upsert ( access Params ) ĊĠĠĠĠĠĠĠ Ġrepository . upsert ( getMock Fit bit Access Params (" dummy 1 ")) ĊĠĠĠĠĠĠĠ Ġrepository . upsert ( getMock Fit bit Access Params (" dummy 2 ")) ĊĠĠĠĠĠĠĠ ĠThread . sleep ( 3 0 0 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġexists Ġ= Ġrepository . exists By Internal Or External UserId And DataSource Id ( userId , ĠFit bit DataSource . DATA _ SOURCE _ ID ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( exists ) ĊĊĠĠĠĠĠĠĠ Ġtest Context . complete Now () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġnot Existing Params Return False For Ex istence ( test Context : ĠVert x TestContext ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠuserId Ġ= Ġ" params Can Be Qu er ied For Ex istence " ĊĠĠĠĠĠĠĠ Ġval Ġaccess Params Ġ= Ġget Mock Fit bit Access Params ( userId ) Ġas ĠOAuth 2 Access Params ĊĠĠĠĠĠĠĠ Ġval Ġrepository Ġ= Ġmain Vert icle . access Params Repository ĊĊĠĠĠĠĠĠĠ Ġrepository . upsert ( access Params ) ĊĠĠĠĠĠĠĠ ĠThread . sleep ( 3 0 0 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġexists Ġ= Ġrepository . exists By Internal Or External UserId And DataSource Id (" dummy ", ĠFit bit DataSource . DATA _ SOURCE _ ID ) ĊĠĠĠĠĠĠĠ ĠassertFalse ( exists ) ĊĊĠĠĠĠĠĠĠ Ġtest Context . complete Now () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Mock Fit bit Access Params ( internal UserId : ĠString ): ĠAccess Params Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġaccess Params : ĠJsonNode Ġ= ĠConfig ured ObjectMapper . instance . read Tree ( getResource As Text ("/ fit bit / fit bit _ access _ params . json ")) ĊĠĠĠĠĠĠĠ Ġreturn ĠOAuth 2 Access Params ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinternal UserId Ġ= Ġinternal UserId , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠdataSource Id Ġ= ĠFit bit DataSource . DATA _ SOURCE _ ID , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġparams Ġ= Ġaccess Params , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġexternal UserId Ġ= ĠTest Properties . FIT BIT _ TEST _ USER _ EXTERNAL _ ID ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊ Ċ }