Skip to content

Commit 7aa4f1a

Browse files
committed
add unit test
1 parent 66997f7 commit 7aa4f1a

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

src/test/java/edu/harvard/iq/dataverse/util/SystemConfigTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,55 @@ void testGetTabularIngestSizeLimitsWithSingleInvalidValue() {
202202
assertEquals(1, result.size());
203203
assertEquals(0L, (long) result.get(SystemConfig.TABULAR_INGEST_SIZE_LIMITS_DEFAULT_KEY));
204204
}
205+
206+
@Test
207+
public void testGetHarvestingClientRequestIntervals() {
208+
209+
// Test with setting not set will return default 0.0
210+
// given
211+
doReturn(null).when(settingsService).getValueForKey(SettingsServiceBean.Key.HarvestingClientCallRateLimit);
212+
// when
213+
Map<String, Float> result = systemConfig.getHarvestingClientRequestIntervals();
214+
// then
215+
assertEquals(1, result.size());
216+
assertEquals(0, result.get(SystemConfig.DEFAULT_KEY));
217+
218+
// Test with good client
219+
String value = "{\"harvarddv\": 0.9, \"default\": 0.0}";
220+
// given
221+
doReturn(value).when(settingsService).getValueForKey(SettingsServiceBean.Key.HarvestingClientCallRateLimit);
222+
// when
223+
result = systemConfig.getHarvestingClientRequestIntervals();
224+
// then
225+
assertEquals(2, result.size());
226+
assertTrue(result.containsKey("harvarddv"));
227+
assertTrue(result.containsKey("default"));
228+
assertEquals(0.9F, systemConfig.getHarvestingClientRequestInterval("harvarddv"));
229+
assertEquals(0.0F, systemConfig.getHarvestingClientRequestInterval("notFoundSoDefault"));
230+
231+
// Test with missing default will create default 0.0
232+
value = "{\"harvarddv\": 0.9}";
233+
// given
234+
doReturn(value).when(settingsService).getValueForKey(SettingsServiceBean.Key.HarvestingClientCallRateLimit);
235+
// when
236+
result = systemConfig.getHarvestingClientRequestIntervals();
237+
// then
238+
assertEquals(2, result.size());
239+
assertTrue(result.containsKey("default"));
240+
assertEquals(0.0F, systemConfig.getHarvestingClientRequestInterval("default"));
241+
242+
// Test with invalid JSON (value as string instead of float) will default setting to default 0.0
243+
value = "{\"harvarddv1\": 0.9, \"harvarddv2\": \"string\"}";
244+
// given
245+
doReturn(value).when(settingsService).getValueForKey(SettingsServiceBean.Key.HarvestingClientCallRateLimit);
246+
// when
247+
result = systemConfig.getHarvestingClientRequestIntervals();
248+
// then
249+
assertEquals(1, result.size());
250+
assertTrue(result.containsKey("default"));
251+
assertTrue(!result.containsKey("harvarddv1"));
252+
assertTrue(!result.containsKey("harvarddv2"));
253+
}
205254

206255
@ParameterizedTest
207256
@ValueSource(strings = {"", "{ invalid: }"})

0 commit comments

Comments
 (0)