/* Ċ Ġ* ĠCopyright Ġ 2 0 1 7 - 2 0 1 8 Ġ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 Ġcom . example Ċ Ċ import Ġcom . example . app . Application Ċ import Ġcom . example . data . Person Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . await ility . Await ility . await Ċ import Ġorg . hamcrest . Matchers .` is ` Ċ import Ġorg . junit . Ass ume . assume That Ċ import Ġorg . junit . BeforeClass Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . autoconfigure . web . servlet . Auto Configure MockMvc Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ import Ġorg . springframework . test . context . junit 4 . Spring Runner Ċ import Ġorg . springframework . test . web . servlet . MockMvc Ċ import Ġorg . springframework . test . web . servlet . request . MockMvc Request Builders . get Ċ import Ġorg . springframework . test . web . servlet . request . MockMvc Request Builders . post Ċ import Ġjava . util . concurrent . TimeUnit Ċ Ċ /** Ċ Ġ* ĠTests Ġto Ġverify Ġthe ĠKotlin Ġsample Ġapp . Ċ Ġ* Ċ Ġ* Ġ@ since Ġ 1 . 1 Ċ Ġ*/ Ċ @ RunWith ( Spring Runner :: class ) Ċ @ Auto Configure MockMvc Ċ @ SpringBootTest ( Ċĉ ĉ web Environment Ġ= ĠSpring Boot Test . Web Environment . RANDOM _ PORT , Ċĉ ĉ classes Ġ= Ġ[ Application :: class ], Ċĉ ĉ properties Ġ= Ġ[ Ċĉĉ ĉ " spring . datasource . password = test ", Ċĉĉ ĉ " spring . cloud . gcp . sql . instance - connection - name = spring - cloud - gcp - ci : us - central 1 : test mysql ", Ċĉĉ ĉ " spring . cloud . gcp . sql . database - name = code _ samples _ test _ db ", Ċĉĉ ĉ " spring . test . mock mvc . print = none " Ċĉ ĉ ] Ċ ) Ċ class ĠRegistration Kotlin Sample Application Integration Tests Ġ{ ĊĊ ĉ private Ġval ĠREG ISTER _ USER _ URL Ġ= Ġ"/ register Person ? firstName = Bob & lastName = Blob & email = bob @ bob . com " ĊĊ ĉ private Ġval ĠREG ISTR ANT S _ URL Ġ= Ġ"/ regist r ants " ĊĊ ĉ @ Autowired Ċ ĉ private Ġlateinit Ġvar Ġmock Mvc : ĠMock Mvc ĊĊ ĉ comp anion Ġobject Ġ{ ĊĊĉ ĉ @ BeforeClass Ċĉ ĉ @ Jvm Static Ċĉ ĉ fun Ġprepare () Ġ{ Ċĉĉ ĉ assume That < String >( Ċĉĉĉĉ ĉ " Kotlin ĠSample Ġapp Ġtests Ġare Ġdisabled . ĠPlease Ġuse Ġ'- D it . kotlin = true ' Ġto Ġenable Ġthem .", Ċĉĉĉĉ ĉ System . getProperty (" it . kotlin "), Ġ` is ` (" true ")) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Register Person Successful () Ġ{ Ċĉ ĉ this . mock Mvc . perform ( post ( REGISTER _ USER _ URL )) ĊĊĉ ĉ await (). at Most ( 6 0 , ĠTimeUnit . SECONDS ). until Assert ed Ġ{ Ċĉĉ ĉ val Ġm vc Result Ġ= Ġthis . mock Mvc Ċĉĉĉĉ ĉ . perform ( get ( REGISTR ANT S _ URL )) Ċĉĉĉĉ ĉ . andReturn () ĊĊĉĉ ĉ val Ġresult Params Ġ= Ġm vc Result . model AndView . model Map Ċĉĉ ĉ val Ġpersons List Ġ= Ġresult Params . get (" persons List ") Ġas ĠList < Person > Ċĉĉ ĉ assertThat ( persons List ). has Size ( 1 ) ĊĊĉĉ ĉ val Ġperson Ġ= Ġpersons List [ 0 ] Ċĉĉ ĉ assertThat ( person . firstName ). isEqualTo (" Bob ") Ċĉĉ ĉ assertThat ( person . lastName ). isEqualTo (" Blob ") Ċĉĉ ĉ assertThat ( person . email ). isEqualTo (" bob @ bob . com ") Ċĉ ĉ } Ċ ĉ } Ċ } Ċ