/* Ċ Ġ* ĠCopyright Ġ 2 0 1 9 - 2 0 2 1 Ġthe Ġoriginal Ġauthor Ġor Ġauthors . Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠ Ġhttps :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ package Ġexample . spring data . mongodb . people ; Ċ Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . autoconfigure . data . mongo . Data Mongo Test Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ import Ġorg . springframework . data . mongodb . core . Mongo Operations Ċ import Ġorg . springframework . data . mongodb . core . drop Collection Ċ import Ġorg . springframework . data . mongodb . core . find Ċ import Ġorg . springframework . data . mongodb . core . insert Ċ import Ġorg . springframework . data . mongodb . core . query . Criteria Ċ import Ġorg . springframework . data . mongodb . core . query . Query Ċ import Ġorg . springframework . data . mongodb . core . query . isEqualTo Ċ import Ġorg . springframework . data . mongodb . core . query . regex Ċ import Ġorg . springframework . test . context . junit 4 . Spring Runner Ċ Ċ /** Ċ Ġ* ĠTests Ġshowing Ġthe ĠMongo ĠCriteria ĠDSL . Ċ Ġ* Ċ Ġ* Ġ@ author ĠCh ristop h ĠSt ro bl Ċ Ġ*/ Ċ @ Data Mongo Test Ċ class ĠMongo Dsl Tests Ġ{ ĊĊ ĉ @ Autowired Ċ ĉ late init Ġvar Ġoperations : ĠMongo Operations ĊĊ ĉ @ BeforeEach Ċ ĉ fun Ġbefore () Ġ{ Ċĉ ĉ operations . drop Collection < Person >() Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġ` simple Ġtype - safe Ġfind `() Ġ{ ĊĊĉ ĉ operations . insert < Person >(). one ( Person (" Ty r ion ", Ġ" L ann ister ")) Ċĉ ĉ operations . insert < Person >(). one ( Person (" C erse i ", Ġ" L ann ister ")) ĊĊĉ ĉ val Ġpeople Ġ= Ġoperations . find < Person >( Query ( Person :: firstname Ġis EqualTo Ġ" Ty r ion ")) Ċĉ ĉ assertThat ( people ). has Size ( 1 ). extract ing (" firstname "). contains Only (" Ty r ion ") Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġ` more Ġcomplex Ġtype - safe Ġfind `() Ġ{ ĊĊĉ ĉ operations . insert < Person >(). one ( Person (" Ty r ion ", Ġ" L ann ister ")) Ċĉ ĉ operations . insert < Person >(). one ( Person (" C erse i ", Ġ" L ann ister ")) ĊĊĉ ĉ val Ġpeople Ġ= Ġoperations . find < Person >( Query ( Ġ// Ċĉĉĉ ĉ Criteria (). and Operator ( Person :: lastname Ġis EqualTo Ġ" L ann ister ", ĠPerson :: firstname Ġregex Ġ"^ C er .* ") Ġ// Ċĉ ĉ )) Ċĉ ĉ assertThat ( people ). has Size ( 1 ). extract ing (" firstname "). contains Only (" C erse i ") Ċ ĉ } Ċ } Ċ