package Ġde . m cell a . spring . learn tool . export Ċ Ċ import Ġde . m cell a . spring . learn tool . UnitTest Ċ import Ġde . m cell a . spring . learn tool . workspace . Workspace Ċ import Ġde . m cell a . spring . learn tool . workspace . exceptions . Workspace Not Exists Exception Ċ import Ġjava . io . File Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . experimental . categories . Category Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Mockito Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . autoconfigure . web . client . Auto Configure Web Client Ċ import Ġorg . springframework . boot . test . autoconfigure . web . servlet . Web Mvc Test Ċ import Ġorg . springframework . boot . test . mock . mockito . Mock Bean Ċ import Ġorg . springframework . http . MediaType Ċ 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 Ċ import Ġorg . springframework . test . web . servlet . result . MockMvc Result Matchers Ċ Ċ @ RunWith ( Spring Runner :: class ) Ċ @ Category ( UnitTest :: class ) Ċ @ Web Mvc Test ( Export Controller :: class ) Ċ @ Auto Configure Web Client Ċ class ĠExport Controller Test Ġ{ ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmock Mvc : ĠMock Mvc ĊĊĠĠĠ Ġ@ Mock Bean ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġexport Service : ĠExport Service ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname , Ġwhen Ġsending Ġa ĠGET ĠREST Ġrequest Ġto Ġthe Ġexport Ġendpoint Ġand Ġthe ĠWorkspace Ġexists , Ġthen Ġthe Ġexport Backup Ġmethod Ġof ĠExport Service Ġis Ġcalled Ġand Ġa Ġbackup Ġfile Ġis Ġreturned `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġbackup Ġ= ĠFile . create TempFile (" backup ", Ġ". zip ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( export Service . export Backup ( workspace )). thenReturn ( backup ) ĊĊĠĠĠĠĠĠĠ Ġmock Mvc . perform ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠMock Mvc Request Builders . get ("/ api / workspaces /${ workspace . name }/ export ") ĊĠĠĠĠĠĠĠ Ġ). andExpect ( MockMvc Result Matchers . status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( MockMvc Result Matchers . content (). contentType ( MediaType . APPLICATION _ OCT ET _ STREAM _ VALUE )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( MockMvc Result Matchers . content (). bytes ( backup . read Bytes ())) ĊĊĠĠĠĠĠĠĠ ĠMockito . verify ( export Service ). export Backup ( workspace ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname , Ġwhen Ġsending Ġa ĠGET ĠREST Ġrequest Ġto Ġthe Ġexport Ġendpoint Ġand Ġthe ĠWorkspace Ġdoes Ġnot Ġexist , Ġthen Ġa ĠNOT _ FOUND Ġhttp Ġstatus Ġresponse Ġis Ġreturned `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( export Service . export Backup ( workspace )). then Throw ( Workspace Not Exists Exception ( workspace )) ĊĊĠĠĠĠĠĠĠ Ġmock Mvc . perform ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠMock Mvc Request Builders . get ("/ api / workspaces /${ workspace . name }/ export ") ĊĠĠĠĠĠĠĠ Ġ). andExpect ( MockMvc Result Matchers . status (). is NotFound ) ĊĠĠĠ Ġ} Ċ } Ċ