16
16
package example .springdata .rest .security ;
17
17
18
18
import static org .hamcrest .CoreMatchers .*;
19
- import static org .hamcrest .MatcherAssert .assertThat ;
19
+ import static org .hamcrest .MatcherAssert .* ;
20
20
import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .*;
21
21
import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .*;
22
22
import static org .springframework .test .web .servlet .setup .MockMvcBuilders .*;
25
25
26
26
import org .junit .jupiter .api .BeforeEach ;
27
27
import org .junit .jupiter .api .Test ;
28
+
28
29
import org .springframework .beans .factory .annotation .Autowired ;
29
30
import org .springframework .boot .test .context .SpringBootTest ;
30
31
import org .springframework .hateoas .MediaTypes ;
42
43
*
43
44
* @author Greg Turnquist
44
45
* @author Oliver Gierke
46
+ * @author Divya Srivastava
45
47
*/
46
48
@ SpringBootTest
47
- public class UrlLevelSecurityTests {
49
+ class UrlLevelSecurityTests {
48
50
49
- static final String PAYLOAD = "{\" firstName\" : \" Saruman\" , \" lastName\" : \" the White\" , " + "\" title\" : \" Wizard\" }" ;
51
+ private static final String PAYLOAD = "{\" firstName\" : \" Saruman\" , \" lastName\" : \" the White\" , "
52
+ + "\" title\" : \" Wizard\" }" ;
50
53
51
54
@ Autowired WebApplicationContext context ;
52
55
@ Autowired FilterChainProxy filterChain ;
53
56
54
- MockMvc mvc ;
57
+ private MockMvc mvc ;
55
58
56
59
@ BeforeEach
57
- public void setUp () {
60
+ void setUp () {
58
61
59
62
this .mvc = webAppContextSetup (context ).addFilters (filterChain ).build ();
60
63
61
64
SecurityContextHolder .clearContext ();
62
65
}
63
66
64
67
@ Test
65
- public void allowsAccessToRootResource () throws Exception {
68
+ void allowsAccessToRootResource () throws Exception {
66
69
67
70
mvc .perform (get ("/" ).//
68
71
accept (MediaTypes .HAL_JSON )).//
@@ -71,7 +74,7 @@ public void allowsAccessToRootResource() throws Exception {
71
74
}
72
75
73
76
@ Test
74
- public void rejectsPostAccessToCollectionResource () throws Exception {
77
+ void rejectsPostAccessToCollectionResource () throws Exception {
75
78
76
79
mvc .perform (post ("/employees" ).//
77
80
content (PAYLOAD ).//
@@ -80,7 +83,7 @@ public void rejectsPostAccessToCollectionResource() throws Exception {
80
83
}
81
84
82
85
@ Test
83
- public void allowsGetRequestsButRejectsPostForUser () throws Exception {
86
+ void allowsGetRequestsButRejectsPostForUser () throws Exception {
84
87
85
88
HttpHeaders headers = new HttpHeaders ();
86
89
headers .add (HttpHeaders .ACCEPT , MediaTypes .HAL_JSON_VALUE );
@@ -98,7 +101,7 @@ public void allowsGetRequestsButRejectsPostForUser() throws Exception {
98
101
}
99
102
100
103
@ Test
101
- public void allowsPostRequestForAdmin () throws Exception {
104
+ void allowsPostRequestForAdmin () throws Exception {
102
105
103
106
HttpHeaders headers = new HttpHeaders ();
104
107
headers .set (HttpHeaders .ACCEPT , MediaTypes .HAL_JSON_VALUE );
0 commit comments