File tree Expand file tree Collapse file tree 5 files changed +97
-0
lines changed
java/com/ericsson/ei/controller
test/java/com/ericsson/ei/controller Expand file tree Collapse file tree 5 files changed +97
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ package com .ericsson .ei .controller ;
3
+
4
+ import org .springframework .http .ResponseEntity ;
5
+ import org .springframework .web .bind .annotation .RequestMapping ;
6
+ import org .springframework .web .bind .annotation .RequestMethod ;
7
+ import org .springframework .web .bind .annotation .RestController ;
8
+
9
+
10
+ /**
11
+ * No description
12
+ * (Generated with springmvc-raml-parser v.0.10.11)
13
+ *
14
+ */
15
+ @ RestController
16
+ @ RequestMapping (value = "/auth/login" , produces = "application/json" )
17
+ public interface LoginController {
18
+
19
+
20
+ /**
21
+ * This call for getting logged in user
22
+ *
23
+ */
24
+ @ RequestMapping (value = "" , method = RequestMethod .GET )
25
+ public ResponseEntity <?> getAuthLogin ();
26
+
27
+ }
Original file line number Diff line number Diff line change
1
+ package com .ericsson .ei .controller ;
2
+
3
+ import io .swagger .annotations .Api ;
4
+ import io .swagger .annotations .ApiOperation ;
5
+ import org .springframework .http .HttpStatus ;
6
+ import org .springframework .http .ResponseEntity ;
7
+ import org .springframework .security .core .context .SecurityContextHolder ;
8
+ import org .springframework .stereotype .Component ;
9
+ import org .springframework .web .bind .annotation .CrossOrigin ;
10
+
11
+ @ Component
12
+ @ CrossOrigin
13
+ @ Api (value = "Auth" , description = "REST endpoints for authentication and authorization" )
14
+ public class LoginControllerImpl implements LoginController {
15
+
16
+ @ Override
17
+ @ CrossOrigin
18
+ @ ApiOperation (value = "To login user" , response = String .class )
19
+ public ResponseEntity <?> getAuthLogin () {
20
+ try {
21
+ String currentUser = SecurityContextHolder .getContext ().getAuthentication ().getName ();
22
+ return new ResponseEntity <>("{\" user\" :\" " + currentUser + "\" }" , HttpStatus .OK );
23
+ } catch (Exception e ) {
24
+ return new ResponseEntity <>(HttpStatus .INTERNAL_SERVER_ERROR );
25
+ }
26
+ }
27
+ }
Original file line number Diff line number Diff line change
1
+ /login :
2
+ get :
3
+ description : This call for getting logged in user
4
+ displayName : login
5
+ responses :
6
+ 200 :
7
+ body :
8
+ application/string:
Original file line number Diff line number Diff line change 33
33
/jmespathrule : !include jmespath.raml
34
34
/download : !include template.raml
35
35
/rules : !include rules.raml
36
+ /auth : !include auth.raml
Original file line number Diff line number Diff line change
1
+ package com .ericsson .ei .controller ;
2
+
3
+ import org .junit .Test ;
4
+ import org .junit .runner .RunWith ;
5
+ import org .springframework .beans .factory .annotation .Autowired ;
6
+ import org .springframework .boot .test .autoconfigure .web .servlet .AutoConfigureMockMvc ;
7
+ import org .springframework .boot .test .context .SpringBootTest ;
8
+ import org .springframework .http .MediaType ;
9
+ import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
10
+ import org .springframework .test .web .servlet .MockMvc ;
11
+ import org .springframework .test .web .servlet .request .MockMvcRequestBuilders ;
12
+
13
+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
14
+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .content ;
15
+
16
+ @ RunWith (SpringJUnit4ClassRunner .class )
17
+ @ SpringBootTest
18
+ @ AutoConfigureMockMvc
19
+ public class TestLoginControllerImpl {
20
+
21
+ @ Autowired
22
+ private MockMvc mockMvc ;
23
+
24
+ @ Test
25
+ public void testResponseStatus () throws Exception {
26
+ String responseBody = "{\" user\" :\" anonymousUser\" }" ;
27
+ mockMvc .perform (MockMvcRequestBuilders .get ("/auth/login" )
28
+ .accept (MediaType .APPLICATION_JSON_VALUE ))
29
+ .andExpect (status ().isOk ())
30
+ .andExpect (content ().string (responseBody ))
31
+ .andReturn ();
32
+ }
33
+
34
+ }
You can’t perform that action at this time.
0 commit comments