Fix EphemerisManager crashing on invalid configuration (#2949)

It has been reported in the past (and in the forum) that the EphemerisManagerImpl can't handle illegal configurations. Due to dependencies in other bundles this results in the whole automation component to be unavailable.

Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
J-N-K
2022-05-05 21:25:30 +02:00
committed by GitHub
parent 53a072d685
commit de1f850e10
2 changed files with 60 additions and 47 deletions
@@ -67,6 +67,21 @@ public class EphemerisManagerImplOSGiTest extends JavaOSGiTest {
entry(CONFIG_COUNTRY, Locale.GERMANY.getCountry())));
}
@Test
public void testEphemerisManagerFixesIllegalCharacters() {
ephemerisManager.modified(Map.ofEntries(entry(CONFIG_DAYSET_PREFIX + CONFIG_DAYSET_WEEKEND, "\"( \"MONDAY\"")));
assertTrue(ephemerisManager.daysets.containsKey(CONFIG_DAYSET_WEEKEND));
}
@Test
public void testEphemerisManagerDoesNotCrashOnIllegalName() {
ephemerisManager.modified(Map.ofEntries(entry(CONFIG_DAYSET_PREFIX + CONFIG_DAYSET_WEEKEND, "Mondax")));
// assertion only to check if no exception occurs
assertFalse(ephemerisManager.daysets.isEmpty());
}
@Test
public void testEphemerisManagerLoadedProperly() {
assertTrue(ephemerisManager.daysets.containsKey(CONFIG_DAYSET_WEEKEND));
@@ -77,20 +92,14 @@ public class EphemerisManagerImplOSGiTest extends JavaOSGiTest {
}
@Test
public void testConfigurtationDaysetWeekendFailed() {
assertThrows(IllegalArgumentException.class,
() -> ephemerisManager.modified(Map.of(CONFIG_DAYSET_PREFIX + CONFIG_DAYSET_WEEKEND, "Foo,Bar")));
}
@Test
public void testConfigurtationDaysetWeekendIterable() {
public void testConfigurationDaysetWeekendIterable() {
ephemerisManager.modified(Map.of(CONFIG_DAYSET_PREFIX + CONFIG_DAYSET_WEEKEND, List.of("Saturday", "Sunday")));
assertTrue(ephemerisManager.daysets.containsKey(CONFIG_DAYSET_WEEKEND));
assertEquals(Set.of(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY), ephemerisManager.daysets.get(CONFIG_DAYSET_WEEKEND));
}
@Test
public void testConfigurtationDaysetWeekendListAsString() {
public void testConfigurationDaysetWeekendListAsString() {
ephemerisManager.modified(Map.of(CONFIG_DAYSET_PREFIX + CONFIG_DAYSET_WEEKEND, List.of("Saturday", "Sunday")));
assertTrue(ephemerisManager.daysets.containsKey(CONFIG_DAYSET_WEEKEND));
assertEquals(Set.of(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY), ephemerisManager.daysets.get(CONFIG_DAYSET_WEEKEND));