package Ġcom . example . server Factory API . controllers Ċ Ċ import Ġcom . example . server Factory API . request . Login Request Ċ import Ġcom . example . server Factory API . security . jwt . Jwt Utils Ċ import Ġcom . fasterxml . jackson . databind . ObjectMapper Ċ 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 . autoconfigure . web . servlet . Auto Configure MockMvc Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ import Ġorg . springframework . http . MediaType Ċ import Ġorg . springframework . security . core . context . SecurityContext Holder Ċ 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 ) Ċ @ SpringBootTest Ċ @ Auto Configure MockMvc Ċ class ĠAuth Controller Int Test Ġ{ ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġlateinit Ġvar Ġmock Mvc : ĠMock Mvc ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġlateinit Ġvar Ġmapper : ĠObjectMapper ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġlateinit Ġvar Ġjwt Utils : ĠJwt Utils ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp (){ ĊĠĠĠĠĠĠĠ ĠSecurity Context Holder . clear Context () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsuccessful Auth With User (){ ĊĠĠĠĠĠĠĠ Ġval Ġlogin Req : ĠLogin Request Ġ= ĠLogin Request (" User 1 "," User 1 2 3 4 ") ĊĠĠĠĠĠĠĠ Ġmock Mvc . perform ( MockMvc Request Builders . post ("/ api / auth / signin ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. accept ( MediaType . APPLICATION _ JSON ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. content ( mapper . writeValue AsString ( login Req ))) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( MockMvc Result Matchers . status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( MockMvc Result Matchers . content (). contentType ( MediaType . APPLICATION _ JSON )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsuccessful Auth With Admin (){ ĊĠĠĠĠĠĠĠ Ġval Ġlogin Req : ĠLogin Request Ġ= ĠLogin Request (" Admin "," Admin 1 2 3 4 ") ĊĠĠĠĠĠĠĠ Ġmock Mvc . perform ( MockMvc Request Builders . post ("/ api / auth / signin ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. accept ( MediaType . APPLICATION _ JSON ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. content ( mapper . writeValue AsString ( login Req ))) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( MockMvc Result Matchers . status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( MockMvc Result Matchers . content (). contentType ( MediaType . APPLICATION _ JSON )) ĊĊĠĠĠ Ġ} Ċ }