1+ /**
2+ * MIT License
3+ *
4+ * Copyright (c) 2017, 2018 SourceLab.org (https://github.com/Crim/kafka-webview/)
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in all
14+ * copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ * SOFTWARE.
23+ */
24+
25+ package org .sourcelab .kafka .webview .ui .controller .configuration .view ;
26+
27+ import org .junit .Test ;
28+ import org .junit .runner .RunWith ;
29+ import org .sourcelab .kafka .webview .ui .controller .configuration .AbstractMvcTest ;
30+ import org .sourcelab .kafka .webview .ui .model .Filter ;
31+ import org .sourcelab .kafka .webview .ui .model .View ;
32+ import org .sourcelab .kafka .webview .ui .tools .FilterTestTools ;
33+ import org .sourcelab .kafka .webview .ui .tools .ViewTestTools ;
34+ import org .springframework .beans .factory .annotation .Autowired ;
35+ import org .springframework .boot .test .autoconfigure .web .servlet .AutoConfigureMockMvc ;
36+ import org .springframework .boot .test .context .SpringBootTest ;
37+ import org .springframework .test .context .junit4 .SpringRunner ;
38+ import org .springframework .transaction .annotation .Transactional ;
39+
40+ import static org .hamcrest .Matchers .containsString ;
41+ import static org .springframework .security .test .web .servlet .request .SecurityMockMvcRequestPostProcessors .user ;
42+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
43+ import static org .springframework .test .web .servlet .result .MockMvcResultHandlers .print ;
44+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .content ;
45+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
46+
47+ @ RunWith (SpringRunner .class )
48+ @ SpringBootTest
49+ @ AutoConfigureMockMvc
50+ public class ViewConfigControllerTest extends AbstractMvcTest {
51+
52+ @ Autowired
53+ private FilterTestTools filterTestTools ;
54+
55+ @ Autowired
56+ private ViewTestTools viewTestTools ;
57+
58+ /**
59+ * Test cannot load pages w/o admin role.
60+ */
61+ @ Test
62+ @ Transactional
63+ public void test_withoutAdminRole () throws Exception {
64+ testUrlWithOutAdminRole ("/configuration/view" , false );
65+ testUrlWithOutAdminRole ("/configuration/view/create" , false );
66+ testUrlWithOutAdminRole ("/configuration/view/edit/1" , false );
67+ testUrlWithOutAdminRole ("/configuration/view/update" , true );
68+ testUrlWithOutAdminRole ("/configuration/view/delete/1" , true );
69+ }
70+
71+ /**
72+ * Smoke test the View Index page.
73+ */
74+ @ Test
75+ @ Transactional
76+ public void testIndex () throws Exception {
77+ // Create some dummy filters
78+ final View view1 = viewTestTools .createView ("View 1" );
79+ final View view2 = viewTestTools .createView ("View 2" );
80+
81+ // Hit index.
82+ mockMvc
83+ .perform (get ("/configuration/view" ).with (user (adminUserDetails )))
84+ .andDo (print ())
85+ .andExpect (status ().isOk ())
86+ // Validate view 1
87+ .andExpect (content ().string (containsString (view1 .getName ())))
88+
89+ // Validate view 2
90+ .andExpect (content ().string (containsString (view2 .getName ())));
91+ }
92+
93+ /**
94+ * Smoke test the View create page.
95+ */
96+ @ Test
97+ @ Transactional
98+ public void testCreate () throws Exception {
99+ // Hit index.
100+ mockMvc
101+ .perform (get ("/configuration/view/create" ).with (user (adminUserDetails )))
102+ .andDo (print ())
103+ .andExpect (status ().isOk ())
104+
105+ // Validate submit button seems to show up.
106+ .andExpect (content ().string (containsString ("type=\" submit\" " )));
107+ }
108+
109+ /**
110+ * Quick and dirty smoke test the View create page when we have a filter with options.
111+ */
112+ @ Test
113+ @ Transactional
114+ public void testRegressionCreateViewWhenFilterExistsWithOptions () throws Exception {
115+ // Create filter that has filter options
116+ final String name = "SearchStringFilter" + System .currentTimeMillis ();
117+ final Filter filter = filterTestTools .createFilterFromTestPlugins (name , "examples.filter.StringSearchFilter" );
118+
119+ // Hit index.
120+ mockMvc
121+ .perform (get ("/configuration/view/create" ).with (user (adminUserDetails )))
122+ .andDo (print ())
123+ .andExpect (status ().isOk ())
124+
125+ // Validate submit button seems to show up.
126+ .andExpect (content ().string (containsString ("type=\" submit\" " )));
127+ }
128+ }
0 commit comments