package Ġcom . fre tron . vehicle Manager . repository Ċ Ċ import Ġcom . fre tron . vehicle Manager . App Constants Ċ import Ġcom . fre tron . vehicle Manager . helper . Test DataSource Ċ import Ġcom . fre tron . vehicle Manager . utils . Embedded Mongo Db Ċ import Ġcom . mongodb . Mongo Client Ċ import Ġcom . mongodb . client . Mongo Database Ċ import Ġorg . codehaus . jackson . map . ObjectMapper Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Assert . assertNotNull Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġjava . util .* Ċ Ċ class ĠVehicle Repository Should Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġembedded Mongo Db : ĠEmbedded Mongo Db ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġdatabase : ĠMongo Database ĊĠĠĠ Ġprivate Ġval ĠobjectMapper Ġ= ĠObjectMapper () ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġconfigure () Ġ{ ĊĠĠĠĠĠĠĠ Ġstart Mongo Db () ĊĠĠĠĠĠĠĠ Ġval Ġmongo Client Ġ= ĠMongo Client (" localhost ", Ġembedded Mongo Db . port ) ĊĠĠĠĠĠĠĠ Ġdatabase Ġ= Ġmongo Client . get Database (" vehicle ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun Ġclose Connections () Ġ{ ĊĠĠĠĠĠĠĠ Ġembedded Mongo Db . stop () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġstart Mongo Db () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrand Ġ= ĠRandom () ĊĠĠĠĠĠĠĠ Ġval Ġn Ġ= Ġrand . nextInt ( 9 9 ) Ġ+ Ġ 9 9 0 0 ĊĠĠĠĠĠĠĠ Ġembedded Mongo Db Ġ= ĠEmbedded Mongo Db ( n ) ĊĠĠĠĠĠĠĠ Ġembedded Mongo Db . start () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcreate Vehicle Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġclass UnderTest Ġ= ĠVehicle Repository Impl ( object Mapper , Ġdatabase , ĠApp Constants . DB _ COLLECTION _ NAME ) ĊĠĠĠĠĠĠĠ Ġval Ġvehicle Ġ= ĠTest DataSource . get Vehicle () ĊĠĠĠĠĠĠĠ Ġval Ġvehicle Created Ġ= Ġclass UnderTest . create Vehicle ( vehicle ) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( vehicle Created ) ĊĠĠĠĠĠĠĠ Ġprint ( vehicle Created . toString ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Vehicle Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġclass UnderTest Ġ= ĠVehicle Repository Impl ( object Mapper , Ġdatabase , ĠApp Constants . DB _ COLLECTION _ NAME ) ĊĠĠĠĠĠĠĠ Ġval Ġvehicle Ġ= ĠTest DataSource . get Vehicle () ĊĠĠĠĠĠĠĠ Ġvehicle . set Uuid ( UUID . randomUUID (). toString ()) ĊĠĠĠĠĠĠĠ Ġval Ġvehicle Created Ġ= Ġclass UnderTest . create Vehicle ( vehicle ) ĊĠĠĠĠĠĠĠ Ġval Ġvehicle From Db Ġ= Ġclass UnderTest . get Vehicle ( vehicle Created . get Uuid ()) ĊĠĠĠĠĠĠĠ Ġprintln ( vehicle From Db ) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( vehicle From Db ) ĊĠĠĠĠĠĠĠ Ġprint ( vehicle From Db . toString ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠgetAll Veh icles Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġclass UnderTest Ġ= ĠVehicle Repository Impl ( object Mapper , Ġdatabase , ĠApp Constants . DB _ COLLECTION _ NAME ) ĊĠĠĠĠĠĠĠ Ġval Ġvehicles Ġ= Ġclass UnderTest . getAll Veh icles () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( vehicles ) ĊĠĠĠĠĠĠĠ Ġprint ( vehicles . toString ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġupdate Vehicle Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġclass UnderTest Ġ= ĠVehicle Repository Impl ( object Mapper , Ġdatabase , ĠApp Constants . DB _ COLLECTION _ NAME ) ĊĠĠĠĠĠĠĠ Ġval Ġvehicle Ġ= ĠTest DataSource . get Vehicle () ĊĠĠĠĠĠĠĠ Ġvehicle . set Uuid ( UUID . randomUUID (). toString ()) ĊĠĠĠĠĠĠĠ Ġval Ġvehicle Created Ġ= Ġclass UnderTest . create Vehicle ( vehicle ) ĊĠĠĠĠĠĠĠ Ġval Ġupdated Vehicle Ġ= Ġclass UnderTest . update Vehicle ( vehicle Created . get Uuid (), Ġvehicle ) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( updated Vehicle ) ĊĠĠĠĠĠĠĠ Ġprint ( updated Vehicle . toString ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdelete Vehicle Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġclass UnderTest Ġ= ĠVehicle Repository Impl ( object Mapper , Ġdatabase , ĠApp Constants . DB _ COLLECTION _ NAME ) ĊĠĠĠĠĠĠĠ Ġval Ġvehicle Ġ= ĠTest DataSource . get Vehicle () ĊĠĠĠĠĠĠĠ Ġvehicle . set Uuid ( UUID . randomUUID (). toString ()) ĊĠĠĠĠĠĠĠ Ġval Ġvehicle Created Ġ= Ġclass UnderTest . create Vehicle ( vehicle ) ĊĠĠĠĠĠĠĠ Ġval Ġdeleted Vehicle Ġ= Ġclass UnderTest . delete Vehicle ( vehicle Created . get Uuid ()) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( deleted Vehicle ) ĊĠĠĠĠĠĠĠ Ġprint ( deleted Vehicle . toString ()) ĊĠĠĠ Ġ} Ċ Ċ }