package Ġio . piv otal . services . mock Ċ Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ import Ġorg . springframework . boot . test . rule . Output Capture Ċ import Ġorg . springframework . boot . test . web . client . Test Rest Template Ċ import Ġorg . springframework . boot . test . web . client . get For Entity Ċ import Ġorg . springframework . http . Http Entity Ċ import Ġorg . springframework . http . HttpHeaders Ċ import Ġorg . springframework . http . MediaType Ċ import Ġorg . springframework . test . context . junit 4 . Spring Runner Ċ Ċ @ RunWith ( Spring Runner :: class ) Ċ @ SpringBootTest ( web Environment Ġ= ĠSpring Boot Test . Web Environment . RANDOM _ PORT ) Ċ class ĠMain Controller Test Ġ{ ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġlateinit Ġvar Ġrest Template : ĠTest Rest Template ĊĊĠĠĠ Ġval Ġcapture Ġ= ĠOutput Capture () ĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġfun Ġcapture (): ĠOutput Capture Ġ= Ġcapture ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠgetLast Body () Ġ{ ĊĠĠĠĠĠĠĠ Ġvar Ġheaders Ġ= ĠHttp Headers () ĊĠĠĠĠĠĠĠ Ġheaders . contentType Ġ= ĠMediaType . APPLICATION _ JSON ĊĠĠĠĠĠĠĠ Ġval Ġentity Ġ= ĠHttp Entity < String >(" {\" Hello \": Ġ\" Sim on \" }", Ġheaders ) ĊĠĠĠĠĠĠĠ Ġrest Template . post For Location ("/ bs / post / last ", Ġentity ) ĊĠĠĠĠĠĠĠ Ġval Ġlast Request Ġ= Ġrest Template . get For Entity < String > ("/ last ") ĊĠĠĠĠĠĠĠ ĠassertThat ( last Request . body . toString ()). contains (" Content - Type ") ĊĠĠĠĠĠĠĠ ĠassertThat ( last Request . body . toString ()). contains (" application / json ; charset = UTF - 8 ") ĊĠĠĠĠĠĠĠ ĠassertThat ( last Request . body . toString ()). contains ("/ bs / post / last ") ĊĠĠĠĠĠĠĠ ĠassertThat ( last Request . body . toString ()). contains ("{ & quot ; Hello & quot ;: Ġ& quot ; Sim on & quot ;} ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġlog Get And Return () Ġ{ ĊĠĠĠĠĠĠĠ Ġrest Template . get For Entity < String > ("/ bs / get / it ? what = nothing ") ĊĠĠĠĠĠĠĠ ĠassertThat ( capture . toString ()). contains (" Get ĠRequest ĠPath :") ĊĠĠĠĠĠĠĠ ĠassertThat ( capture . toString ()). contains ("/ bs / get / it ") ĊĠĠĠĠĠĠĠ ĠassertThat ( capture . toString ()). contains (" Get ĠRequest ĠQuery :") ĊĠĠĠĠĠĠĠ ĠassertThat ( capture . toString ()). contains (" what = nothing ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġlog Post And Return () Ġ{ ĊĠĠĠĠĠĠĠ Ġvar Ġheaders Ġ= ĠHttp Headers () ĊĠĠĠĠĠĠĠ Ġheaders . contentType Ġ= ĠMediaType . APPLICATION _ JSON ĊĠĠĠĠĠĠĠ Ġval Ġentity Ġ= ĠHttp Entity < String >(" {\" Hello \": Ġ\" B rad \" }", Ġheaders ) ĊĠĠĠĠĠĠĠ Ġrest Template . post For Location ("/ bs / post ", Ġentity ) ĊĠĠĠĠĠĠĠ ĠassertThat ( capture . toString ()). contains (" Post ĠRequest ĠPath :") ĊĠĠĠĠĠĠĠ ĠassertThat ( capture . toString ()). contains ("/ bs / post ") ĊĠĠĠĠĠĠĠ ĠassertThat ( capture . toString ()). contains ("{ \" Hello \": Ġ\" B rad \" }") ĊĠĠĠĠĠĠĠ ĠassertThat ( capture . toString ()). contains (" Content - Type =[ application / json ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġlog Put And Return () Ġ{ ĊĠĠĠĠĠĠĠ Ġrest Template . put ("/ bs / put ", Ġ"{\" Hello \": Ġ\" Ty son \" }") ĊĠĠĠĠĠĠĠ ĠassertThat ( capture . toString ()). contains (" Put ĠRequest ĠPath :") ĊĠĠĠĠĠĠĠ ĠassertThat ( capture . toString ()). contains ("/ bs / put ") ĊĠĠĠĠĠĠĠ ĠassertThat ( capture . toString ()). contains ("{ \" Hello \": Ġ\" Ty son \" }") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġlog Patch And Return () Ġ{ ĊĠĠĠĠĠĠĠ Ġrest Template . post For Object ("/ bs / patch ? _ method = patch ", Ġ"{\" Hello \": Ġ\" B ella \" }", String :: class . java ) ĊĠĠĠĠĠĠĠ ĠassertThat ( capture . toString ()). contains (" Patch ĠRequest ĠPath :") ĊĠĠĠĠĠĠĠ ĠassertThat ( capture . toString ()). contains ("/ bs / patch ") ĊĠĠĠĠĠĠĠ ĠassertThat ( capture . toString ()). contains ("{ \" Hello \": Ġ\" B ella \" }") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġlog Delete And Return () Ġ{ ĊĠĠĠĠĠĠĠ Ġrest Template . delete ("/ bs / delete ") ĊĠĠĠĠĠĠĠ ĠassertThat ( capture . toString ()). contains (" Delete ĠRequest ĠPath :") ĊĠĠĠĠĠĠĠ ĠassertThat ( capture . toString ()). contains ("/ bs / delete ") ĊĠĠĠ Ġ} Ċ }