package Ġjp . ac . k cg Ċ Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . Spring ApplicationConfiguration Ċ import Ġorg . springframework . security . test . context . support . With Mock User Ċ import Ġorg . springframework . security . test . web . servlet . setup . Security MockMvc Configur ers Ċ import Ġorg . springframework . test . context . junit 4 . Spring JUnit 4 Class Runner Ċ import Ġorg . springframework . test . context . web . WebApp Configuration Ċ import Ġorg . springframework . test . web . servlet . MockMvc Ċ import Ġorg . springframework . test . web . servlet . setup . Default MockMvc Builder Ċ import Ġorg . springframework . test . web . servlet . setup . MockMvc Builders Ċ import Ġorg . springframework . web . context . Web ApplicationContext Ċ Ċ import Ġorg . springframework . security . test . web . servlet . request . Security MockMvc Request Post Processors .* Ċ import Ġorg . springframework . test . web . servlet . request . MockMvc Request Builders Ċ import Ġorg . springframework . test . web . servlet . result . MockMvc Result Matchers .* ĊĊ Ċ @ RunWith ( Spring JUnit 4 Class Runner :: class ) Ċ @ Spring ApplicationConfiguration ( classes Ġ= ĠarrayOf ( House Hold Account Book Application :: class )) Ċ @ WebApp Configuration Ċ class ĠHouse Hold Account Book Application Tests Ġ{ ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġlateinit Ġvar Ġcontext : ĠWeb ApplicationContext ĊĊĠĠĠ Ġlateinit Ġvar Ġmock : ĠMock Mvc ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġmock Ġ= ĠMock Mvc Builders ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. web AppContext Setup ( context ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. apply < Default MockMvc Builder >( Security MockMvc Configur ers . spring Security ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ With Mock User ( username Ġ= Ġ" test ") ĊĠĠĠ Ġfun Ġtop Page Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġmock . perform ( MockMvc Request Builders . get ("/ "). with ( csrf ())) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( model (). attribute Exists (" principal ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtop Page Test 2 () Ġ{ ĊĠĠĠĠĠĠĠ Ġmock . perform ( MockMvc Request Builders . get ("/ "). with ( csrf ())) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( model (). attribute DoesNotExist (" principal ")) ĊĠĠĠ Ġ} Ċ } Ċ