Skip to content

Commit 833c573

Browse files
authored
[ISSUE43] - Fix bug in view config controller when creating new view (#50)
* [ISSUE43] - Fix bug in view config controller when creating new view * Bump release version to 1.0.1
1 parent 83b3afa commit 833c573

File tree

10 files changed

+185
-14
lines changed

10 files changed

+185
-14
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
The format is based on [Keep a Changelog](http://keepachangelog.com/)
33
and this project adheres to [Semantic Versioning](http://semver.org/).
44

5-
## 1.x.x (Unreleased)
5+
## 1.0.1 (01/17/2018)
66
- Add Dockerfile / Dockerhub images.
7+
- [Issue#49](https://github.com/SourceLabOrg/kafka-webview/issues/49) Fix bug in View create when a Filter has configurable options.
78

89
## 1.0.0 (01/06/2018)
910
- Initial release!

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ WORKDIR /app
1010

1111
# Download latest distribution inside image
1212
# Extract package into /app stripping top level directory contained within the zip.
13-
RUN wget https://github.com/SourceLabOrg/kafka-webview/releases/download/v1.0.0/kafka-webview-ui-1.0.0-bin.zip && unzip -d /app kafka-webview-ui-*-bin.zip && rm -f /app/kafka-webview-ui-*-bin.zip && f=`ls` && mv /app/*/* /app && rmdir $f && rm -f /app/kafka-webview-ui-*-sources.jar && rm -f /app/kafka-webview-ui-*-javadoc.jar && apk add --update bash && rm -rf /var/cache/apk/*
13+
RUN wget https://github.com/SourceLabOrg/kafka-webview/releases/download/v1.0.1/kafka-webview-ui-1.0.1-bin.zip && unzip -d /app kafka-webview-ui-*-bin.zip && rm -f /app/kafka-webview-ui-*-bin.zip && f=`ls` && mv /app/*/* /app && rmdir $f && rm -f /app/kafka-webview-ui-*-sources.jar && rm -f /app/kafka-webview-ui-*-javadoc.jar && apk add --update bash && rm -rf /var/cache/apk/*
1414

1515
# Create volume to persist data
1616
VOLUME /app/data

kafka-webview-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.sourcelab</groupId>
77
<artifactId>kafka-webview</artifactId>
8-
<version>1.0.0</version>
8+
<version>1.0.1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>kafka-webview-plugin</artifactId>

kafka-webview-ui/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<parent>
66
<artifactId>kafka-webview</artifactId>
77
<groupId>org.sourcelab</groupId>
8-
<version>1.0.0</version>
8+
<version>1.0.1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>kafka-webview-ui</artifactId>
12-
<version>1.0.0</version>
12+
<version>1.0.1</version>
1313

1414
<!-- Module Description and Ownership -->
1515
<name>Kafka WebView UI</name>

kafka-webview-ui/src/main/java/org/sourcelab/kafka/webview/ui/configuration/SecurityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected void configure(final HttpSecurity http) throws Exception {
109109
}
110110

111111
@Override
112-
public void configure(AuthenticationManagerBuilder auth) throws Exception {
112+
public void configure(final AuthenticationManagerBuilder auth) throws Exception {
113113
auth
114114
// Define our custom user details service.
115115
.userDetailsService(new CustomUserDetailsService(userRepository))

kafka-webview-ui/src/main/java/org/sourcelab/kafka/webview/ui/controller/configuration/view/ViewConfigController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public String createViewForm(final ViewForm viewForm, final Model model) {
129129

130130
// Retrieve all filters
131131
model.addAttribute("filterList", filterRepository.findAllByOrderByNameAsc());
132+
model.addAttribute("filterParameters", new HashMap<Long, Map<String, String>>());
132133

133134
if (viewForm.getClusterId() != null) {
134135
// Lets load the topics now

kafka-webview-ui/src/test/java/org/sourcelab/kafka/webview/ui/controller/configuration/filter/FilterConfigControllerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public void test_withoutAdminRole() throws Exception {
7070
@Transactional
7171
public void testIndex() throws Exception {
7272
// Create some dummy filters
73-
final Filter filter1 = filterTestTools.createFiler("Filter1");
74-
final Filter filter2 = filterTestTools.createFiler("Filter2");
73+
final Filter filter1 = filterTestTools.createFilter("Filter1");
74+
final Filter filter2 = filterTestTools.createFilter("Filter2");
7575

7676
// Hit index.
7777
mockMvc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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+
}

kafka-webview-ui/src/test/java/org/sourcelab/kafka/webview/ui/tools/FilterTestTools.java

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,77 @@
2424

2525
package org.sourcelab.kafka.webview.ui.tools;
2626

27+
import org.sourcelab.kafka.webview.ui.manager.plugin.PluginFactory;
2728
import org.sourcelab.kafka.webview.ui.model.Filter;
29+
import org.sourcelab.kafka.webview.ui.plugin.filter.RecordFilter;
2830
import org.sourcelab.kafka.webview.ui.repository.FilterRepository;
2931
import org.springframework.beans.factory.annotation.Autowired;
3032
import org.springframework.stereotype.Component;
3133

34+
import java.io.IOException;
35+
import java.io.InputStream;
36+
import java.nio.file.Files;
37+
import java.nio.file.Path;
38+
3239
/**
3340
* Helpful tools for Filters in tests.
3441
*/
3542
@Component
3643
public class FilterTestTools {
3744
private final FilterRepository filterRepository;
45+
private final PluginFactory<RecordFilter> recordFilterPluginFactory;
3846

3947
@Autowired
40-
public FilterTestTools(final FilterRepository filterRepository) {
48+
public FilterTestTools(final FilterRepository filterRepository, final PluginFactory<RecordFilter> recordFilterPluginFactory) {
4149
this.filterRepository = filterRepository;
50+
this.recordFilterPluginFactory = recordFilterPluginFactory;
51+
}
52+
53+
/**
54+
* Utility for creating Filters.
55+
* @param name Name of the filter.
56+
* @return Persisted Filter.
57+
*/
58+
public Filter createFilter(final String name) {
59+
return createFilter(name, name, name + ".jar", "{\"key\": \"value\"}");
4260
}
4361

4462
/**
4563
* Utility for creating Filters.
4664
* @param name Name of the filter.
65+
* @param classPath Classpath of filter.
66+
* @param jarName name of the resulting jar.
67+
* @param options Json formatted string of options.
4768
* @return Persisted Filter.
4869
*/
49-
public Filter createFiler(final String name) {
70+
public Filter createFilter(final String name, final String classPath, final String jarName, final String options) {
5071
final Filter filter = new Filter();
5172
filter.setName(name);
52-
filter.setClasspath("com.example." + name);
53-
filter.setJar(name + ".jar");
54-
filter.setOptions("{\"key\": \"value\"}");
73+
filter.setClasspath(classPath);
74+
filter.setJar(jarName);
75+
filter.setOptions(options);
5576
filterRepository.save(filter);
5677

5778
return filter;
5879
}
80+
81+
/**
82+
* Using the testPlugins.jar from test resources, create a filter.
83+
* @param name Name of the filter.
84+
* @param classPath Classpath to filter within the testPlugins.jar
85+
* @return Persisted Filter.
86+
* @throws IOException on file copy issues.
87+
*/
88+
public Filter createFilterFromTestPlugins(final String name, final String classPath) throws IOException {
89+
final String jarFileName = name + ".jar";
90+
final Path outputPath = recordFilterPluginFactory.getPathForJar(jarFileName);
91+
92+
// Copy plugin file over
93+
try (final InputStream fileInputStream = getClass().getClassLoader().getResourceAsStream("testDeserializer/testPlugins.jar")) {
94+
Files.createDirectories(outputPath.getParent().toAbsolutePath());
95+
Files.copy(fileInputStream, outputPath);
96+
}
97+
98+
return createFilter(name, classPath, jarFileName, "{}");
99+
}
59100
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>org.sourcelab</groupId>
88
<artifactId>kafka-webview</artifactId>
99
<packaging>pom</packaging>
10-
<version>1.0.0</version>
10+
<version>1.0.1</version>
1111

1212
<!-- Define submodules -->
1313
<modules>

0 commit comments

Comments
 (0)