Skip to content

Commit 0d3ddb2

Browse files
Abigael-JTelliVM
andauthored
issue_541: Added a check and tests for empty string and null string json object (#553)
* Added a check and tests for empty string and null string properties so that fromjson() does translate and return a null * Update src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/FilterTypes.java Co-authored-by: elliVM <[email protected]> * set helper methods to private and run spotless --------- Co-authored-by: elliVM <[email protected]>
1 parent 9e192ef commit 0d3ddb2

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

src/main/java/com/teragrep/pth_10/steps/teragrep/bloomfilter/FilterTypes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private String sizesJsonString() {
123123
final String BLOOM_NUMBER_OF_FIELDS_CONFIG_ITEM = "dpl.pth_06.bloom.db.fields";
124124
if (config.hasPath(BLOOM_NUMBER_OF_FIELDS_CONFIG_ITEM)) {
125125
jsonString = config.getString(BLOOM_NUMBER_OF_FIELDS_CONFIG_ITEM);
126-
if (jsonString == null || jsonString.isEmpty()) {
126+
if (jsonString == null || jsonString.isEmpty() || "null".equals(jsonString)) {
127127
throw new RuntimeException("Bloom filter size fields was not configured.");
128128
}
129129
}

src/test/java/com/teragrep/pth_10/steps/teragrep/bloomfilter/FilterTypesTest.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,26 @@ public void testSortedMapMethod() {
105105

106106
}
107107

108+
@Test
109+
public void testSortedMapMethodWithEmptyStringJSON() {
110+
Config config = ConfigFactory.parseProperties(emptyStringProperties());
111+
FilterTypes filterTypes = new FilterTypes(config);
112+
Exception exception = assertThrows(RuntimeException.class, () -> {
113+
filterTypes.sortedMap();
114+
});
115+
Assertions.assertEquals("Bloom filter size fields was not configured.", exception.getMessage());
116+
}
117+
118+
@Test
119+
public void testSortedMapMethodWithNullStringJSON() {
120+
Config config = ConfigFactory.parseProperties(nullStringProperties());
121+
FilterTypes filterTypes = new FilterTypes(config);
122+
Exception exception = assertThrows(RuntimeException.class, () -> {
123+
filterTypes.sortedMap();
124+
});
125+
Assertions.assertEquals("Bloom filter size fields was not configured.", exception.getMessage());
126+
}
127+
108128
@Test
109129
public void testBitSizeMapMethod() {
110130
Config config = ConfigFactory.parseProperties(defaultProperties());
@@ -209,7 +229,7 @@ public void testEqualsVerifier() {
209229
EqualsVerifier.forClass(FilterTypes.class).withNonnullFields("config").verify();
210230
}
211231

212-
public Properties defaultProperties() {
232+
private Properties defaultProperties() {
213233
Properties properties = new Properties();
214234
properties.put("dpl.pth_10.bloom.db.username", username);
215235
properties.put("dpl.pth_10.bloom.db.password", password);
@@ -222,4 +242,22 @@ public Properties defaultProperties() {
222242
);
223243
return properties;
224244
}
245+
246+
private Properties emptyStringProperties() {
247+
Properties properties = new Properties();
248+
properties.put("dpl.pth_10.bloom.db.username", username);
249+
properties.put("dpl.pth_10.bloom.db.password", password);
250+
properties.put("dpl.pth_06.bloom.db.url", connectionUrl);
251+
properties.put("dpl.pth_06.bloom.db.fields", "");
252+
return properties;
253+
}
254+
255+
private Properties nullStringProperties() {
256+
Properties properties = new Properties();
257+
properties.put("dpl.pth_10.bloom.db.username", username);
258+
properties.put("dpl.pth_10.bloom.db.password", password);
259+
properties.put("dpl.pth_06.bloom.db.url", connectionUrl);
260+
properties.put("dpl.pth_06.bloom.db.fields", "null");
261+
return properties;
262+
}
225263
}

0 commit comments

Comments
 (0)