|
1 | 1 | /**
|
2 |
| - * This Source Code Form is subject to the terms of the Mozilla Public |
3 |
| - * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 |
| - * file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 2 | + * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of |
| 3 | + * the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. |
5 | 4 | *
|
6 |
| - * Copyright (c) 2017-2020 VMware, Inc. or its affiliates. All rights reserved. |
| 5 | + * <p>Copyright (c) 2017-2023 VMware, Inc. or its affiliates. All rights reserved. |
7 | 6 | */
|
8 |
| - |
9 | 7 | package com.rabbitmq.examples;
|
10 | 8 |
|
11 |
| -import org.junit.Test; |
12 |
| -import org.junit.runner.RunWith; |
| 9 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; |
| 10 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; |
| 11 | + |
| 12 | +import org.junit.jupiter.api.Test; |
13 | 13 | import org.springframework.beans.factory.annotation.Autowired;
|
14 | 14 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
15 |
| -import org.springframework.test.context.junit4.SpringRunner; |
16 | 15 | import org.springframework.test.web.servlet.MockMvc;
|
17 | 16 |
|
18 |
| -import static org.assertj.core.api.Assertions.*; |
19 |
| -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; |
20 |
| -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; |
21 |
| - |
22 |
| -@RunWith(SpringRunner.class) |
23 | 17 | @WebMvcTest(AuthBackendHttpController.class)
|
24 | 18 | public class AuthBackendHttpControllerTest {
|
25 | 19 |
|
26 |
| - @Autowired |
27 |
| - private MockMvc mvc; |
28 |
| - |
29 |
| - @Test public void authenticationAuthorisation() throws Exception { |
30 |
| - this.mvc.perform(get("/auth/user").param("username", "guest").param("password", "guest")) |
31 |
| - .andExpect(status().isOk()).andExpect(content().string("allow administrator management")); |
| 20 | + @Autowired private MockMvc mvc; |
32 | 21 |
|
33 |
| - this.mvc.perform(get("/auth/user").param("username", "guest").param("password", "wrong")) |
34 |
| - .andExpect(status().isOk()).andExpect(content().string("deny")); |
| 22 | + @Test |
| 23 | + public void authenticationAuthorisation() throws Exception { |
| 24 | + this.mvc |
| 25 | + .perform(get("/auth/user").param("username", "guest").param("password", "guest")) |
| 26 | + .andExpect(status().isOk()) |
| 27 | + .andExpect(content().string("allow administrator management")); |
35 | 28 |
|
36 |
| - this.mvc.perform(get("/auth/vhost").param("username", "guest").param("vhost", "/")) |
37 |
| - .andExpect(status().isOk()).andExpect(content().string("allow")); |
| 29 | + this.mvc |
| 30 | + .perform(get("/auth/user").param("username", "guest").param("password", "wrong")) |
| 31 | + .andExpect(status().isOk()) |
| 32 | + .andExpect(content().string("deny")); |
38 | 33 |
|
39 |
| - this.mvc.perform(get("/auth/resource") |
40 |
| - .param("username", "guest") |
41 |
| - .param("vhost", "/") |
42 |
| - .param("resource", "exchange") |
43 |
| - .param("name", "amq.topic") |
44 |
| - .param("permission", "write")) |
45 |
| - .andExpect(status().isOk()).andExpect(content().string("allow")); |
| 34 | + this.mvc |
| 35 | + .perform(get("/auth/vhost").param("username", "guest").param("vhost", "/")) |
| 36 | + .andExpect(status().isOk()) |
| 37 | + .andExpect(content().string("allow")); |
46 | 38 |
|
47 |
| - this.mvc.perform(get("/auth/topic") |
48 |
| - .param("username", "guest") |
49 |
| - .param("vhost", "/") |
50 |
| - .param("resource", "exchange") |
51 |
| - .param("name", "amq.topic") |
52 |
| - .param("permission", "write") |
53 |
| - .param("routing_key","a.b")) |
54 |
| - .andExpect(status().isOk()).andExpect(content().string("allow")); |
| 39 | + this.mvc |
| 40 | + .perform( |
| 41 | + get("/auth/resource") |
| 42 | + .param("username", "guest") |
| 43 | + .param("vhost", "/") |
| 44 | + .param("resource", "exchange") |
| 45 | + .param("name", "amq.topic") |
| 46 | + .param("permission", "write")) |
| 47 | + .andExpect(status().isOk()) |
| 48 | + .andExpect(content().string("allow")); |
55 | 49 |
|
56 |
| - this.mvc.perform(get("/auth/topic") |
57 |
| - .param("username", "guest") |
58 |
| - .param("vhost", "/") |
59 |
| - .param("resource", "exchange") |
60 |
| - .param("name", "amq.topic") |
61 |
| - .param("permission", "write") |
62 |
| - .param("routing_key","b.b")) |
63 |
| - .andExpect(status().isOk()).andExpect(content().string("deny")); |
64 |
| - } |
| 50 | + this.mvc |
| 51 | + .perform( |
| 52 | + get("/auth/topic") |
| 53 | + .param("username", "guest") |
| 54 | + .param("vhost", "/") |
| 55 | + .param("resource", "exchange") |
| 56 | + .param("name", "amq.topic") |
| 57 | + .param("permission", "write") |
| 58 | + .param("routing_key", "a.b")) |
| 59 | + .andExpect(status().isOk()) |
| 60 | + .andExpect(content().string("allow")); |
65 | 61 |
|
| 62 | + this.mvc |
| 63 | + .perform( |
| 64 | + get("/auth/topic") |
| 65 | + .param("username", "guest") |
| 66 | + .param("vhost", "/") |
| 67 | + .param("resource", "exchange") |
| 68 | + .param("name", "amq.topic") |
| 69 | + .param("permission", "write") |
| 70 | + .param("routing_key", "b.b")) |
| 71 | + .andExpect(status().isOk()) |
| 72 | + .andExpect(content().string("deny")); |
| 73 | + } |
66 | 74 | }
|
0 commit comments