mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 13:21:53 +01:00
[persistence] Add persistence exclusion tests (#4482)
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
This commit is contained in:
parent
b31ff66bba
commit
8e4cebdec2
@ -61,7 +61,9 @@ import org.openhab.core.persistence.QueryablePersistenceService;
|
||||
import org.openhab.core.persistence.config.PersistenceAllConfig;
|
||||
import org.openhab.core.persistence.config.PersistenceConfig;
|
||||
import org.openhab.core.persistence.config.PersistenceGroupConfig;
|
||||
import org.openhab.core.persistence.config.PersistenceGroupExcludeConfig;
|
||||
import org.openhab.core.persistence.config.PersistenceItemConfig;
|
||||
import org.openhab.core.persistence.config.PersistenceItemExcludeConfig;
|
||||
import org.openhab.core.persistence.filter.PersistenceFilter;
|
||||
import org.openhab.core.persistence.filter.PersistenceThresholdFilter;
|
||||
import org.openhab.core.persistence.registry.PersistenceServiceConfiguration;
|
||||
@ -167,7 +169,7 @@ public class PersistenceManagerTest {
|
||||
|
||||
@Test
|
||||
public void appliesToItemWithItemConfig() {
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, new PersistenceItemConfig(TEST_ITEM_NAME),
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, List.of(new PersistenceItemConfig(TEST_ITEM_NAME)),
|
||||
PersistenceStrategy.Globals.UPDATE, null);
|
||||
|
||||
manager.stateUpdated(TEST_ITEM, TEST_STATE);
|
||||
@ -178,7 +180,7 @@ public class PersistenceManagerTest {
|
||||
|
||||
@Test
|
||||
public void doesNotApplyToItemWithItemConfig() {
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, new PersistenceItemConfig(TEST_ITEM_NAME),
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, List.of(new PersistenceItemConfig(TEST_ITEM_NAME)),
|
||||
PersistenceStrategy.Globals.UPDATE, null);
|
||||
|
||||
manager.stateUpdated(TEST_ITEM2, TEST_STATE);
|
||||
@ -188,7 +190,7 @@ public class PersistenceManagerTest {
|
||||
|
||||
@Test
|
||||
public void appliesToGroupItemWithItemConfig() {
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, new PersistenceItemConfig(TEST_GROUP_ITEM_NAME),
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, List.of(new PersistenceItemConfig(TEST_GROUP_ITEM_NAME)),
|
||||
PersistenceStrategy.Globals.UPDATE, null);
|
||||
|
||||
manager.stateUpdated(TEST_GROUP_ITEM, TEST_STATE);
|
||||
@ -199,7 +201,7 @@ public class PersistenceManagerTest {
|
||||
|
||||
@Test
|
||||
public void appliesToItemWithGroupConfig() {
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, new PersistenceGroupConfig(TEST_GROUP_ITEM_NAME),
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, List.of(new PersistenceGroupConfig(TEST_GROUP_ITEM_NAME)),
|
||||
PersistenceStrategy.Globals.UPDATE, null);
|
||||
|
||||
manager.stateUpdated(TEST_ITEM, TEST_STATE);
|
||||
@ -210,7 +212,7 @@ public class PersistenceManagerTest {
|
||||
|
||||
@Test
|
||||
public void doesNotApplyToItemWithGroupConfig() {
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, new PersistenceGroupConfig(TEST_GROUP_ITEM_NAME),
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, List.of(new PersistenceGroupConfig(TEST_GROUP_ITEM_NAME)),
|
||||
PersistenceStrategy.Globals.UPDATE, null);
|
||||
|
||||
manager.stateUpdated(TEST_ITEM2, TEST_STATE);
|
||||
@ -221,8 +223,8 @@ public class PersistenceManagerTest {
|
||||
|
||||
@Test
|
||||
public void appliesToItemWithAllConfig() {
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, new PersistenceAllConfig(), PersistenceStrategy.Globals.UPDATE,
|
||||
null);
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, List.of(new PersistenceAllConfig()),
|
||||
PersistenceStrategy.Globals.UPDATE, null);
|
||||
|
||||
manager.stateUpdated(TEST_ITEM, TEST_STATE);
|
||||
manager.stateUpdated(TEST_ITEM2, TEST_STATE);
|
||||
@ -235,10 +237,52 @@ public class PersistenceManagerTest {
|
||||
verifyNoMoreInteractions(persistenceServiceMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotApplyToItemWithGroupConfigAndItemExclusion() {
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, List.of(new PersistenceGroupConfig(TEST_GROUP_ITEM_NAME),
|
||||
new PersistenceItemExcludeConfig(TEST_ITEM_NAME)), PersistenceStrategy.Globals.UPDATE, null);
|
||||
|
||||
manager.stateUpdated(TEST_ITEM, TEST_STATE);
|
||||
|
||||
verifyNoMoreInteractions(persistenceServiceMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotApplyToItemWithAllConfigAndItemExclusion() {
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID,
|
||||
List.of(new PersistenceAllConfig(), new PersistenceItemExcludeConfig(TEST_ITEM_NAME)),
|
||||
PersistenceStrategy.Globals.UPDATE, null);
|
||||
|
||||
manager.stateUpdated(TEST_ITEM, TEST_STATE);
|
||||
manager.stateUpdated(TEST_ITEM2, TEST_STATE);
|
||||
manager.stateUpdated(TEST_GROUP_ITEM, TEST_STATE);
|
||||
|
||||
verify(persistenceServiceMock).store(TEST_ITEM2, null);
|
||||
verify(persistenceServiceMock).store(TEST_GROUP_ITEM, null);
|
||||
|
||||
verifyNoMoreInteractions(persistenceServiceMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotApplyToItemWithAllConfigAndGroupExclusion() {
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID,
|
||||
List.of(new PersistenceAllConfig(), new PersistenceGroupExcludeConfig(TEST_GROUP_ITEM_NAME)),
|
||||
PersistenceStrategy.Globals.UPDATE, null);
|
||||
|
||||
manager.stateUpdated(TEST_ITEM, TEST_STATE);
|
||||
manager.stateUpdated(TEST_ITEM2, TEST_STATE);
|
||||
manager.stateUpdated(TEST_GROUP_ITEM, TEST_STATE);
|
||||
|
||||
verify(persistenceServiceMock).store(TEST_ITEM2, null);
|
||||
verify(persistenceServiceMock).store(TEST_GROUP_ITEM, null);
|
||||
|
||||
verifyNoMoreInteractions(persistenceServiceMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatedStatePersistsEveryUpdate() {
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, new PersistenceAllConfig(), PersistenceStrategy.Globals.UPDATE,
|
||||
null);
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, List.of(new PersistenceAllConfig()),
|
||||
PersistenceStrategy.Globals.UPDATE, null);
|
||||
|
||||
manager.stateUpdated(TEST_ITEM, TEST_STATE);
|
||||
manager.stateUpdated(TEST_ITEM, TEST_STATE);
|
||||
@ -250,8 +294,8 @@ public class PersistenceManagerTest {
|
||||
|
||||
@Test
|
||||
public void updatedStateDoesNotPersistWithChangeStrategy() {
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, new PersistenceAllConfig(), PersistenceStrategy.Globals.CHANGE,
|
||||
null);
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, List.of(new PersistenceAllConfig()),
|
||||
PersistenceStrategy.Globals.CHANGE, null);
|
||||
|
||||
manager.stateUpdated(TEST_ITEM, TEST_STATE);
|
||||
verifyNoMoreInteractions(persistenceServiceMock);
|
||||
@ -259,8 +303,8 @@ public class PersistenceManagerTest {
|
||||
|
||||
@Test
|
||||
public void changedStatePersistsWithChangeStrategy() {
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, new PersistenceAllConfig(), PersistenceStrategy.Globals.CHANGE,
|
||||
null);
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, List.of(new PersistenceAllConfig()),
|
||||
PersistenceStrategy.Globals.CHANGE, null);
|
||||
|
||||
manager.stateChanged(TEST_ITEM, UnDefType.UNDEF, TEST_STATE);
|
||||
|
||||
@ -270,8 +314,8 @@ public class PersistenceManagerTest {
|
||||
|
||||
@Test
|
||||
public void changedStateDoesNotPersistWithUpdateStrategy() {
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, new PersistenceAllConfig(), PersistenceStrategy.Globals.UPDATE,
|
||||
null);
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, List.of(new PersistenceAllConfig()),
|
||||
PersistenceStrategy.Globals.UPDATE, null);
|
||||
|
||||
manager.stateChanged(TEST_ITEM, UnDefType.UNDEF, TEST_STATE);
|
||||
|
||||
@ -329,7 +373,7 @@ public class PersistenceManagerTest {
|
||||
return future;
|
||||
});
|
||||
|
||||
addConfiguration(TestModifiablePersistenceService.ID, new PersistenceAllConfig(),
|
||||
addConfiguration(TestModifiablePersistenceService.ID, List.of(new PersistenceAllConfig()),
|
||||
PersistenceStrategy.Globals.FORECAST, null);
|
||||
|
||||
Instant time1 = Instant.now().minusSeconds(1000);
|
||||
@ -397,9 +441,9 @@ public class PersistenceManagerTest {
|
||||
ArgumentCaptor<SchedulerRunnable> runnableCaptor = ArgumentCaptor.forClass(SchedulerRunnable.class);
|
||||
when(cronSchedulerMock.schedule(runnableCaptor.capture(), any())).thenReturn(scheduledFutureMock);
|
||||
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, new PersistenceItemConfig(TEST_ITEM3_NAME),
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, List.of(new PersistenceItemConfig(TEST_ITEM3_NAME)),
|
||||
new PersistenceCronStrategy("withoutFilter", "0 0 * * * ?"), null);
|
||||
addConfiguration(TEST_QUERYABLE_PERSISTENCE_SERVICE_ID, new PersistenceItemConfig(TEST_ITEM3_NAME),
|
||||
addConfiguration(TEST_QUERYABLE_PERSISTENCE_SERVICE_ID, List.of(new PersistenceItemConfig(TEST_ITEM3_NAME)),
|
||||
new PersistenceCronStrategy("withFilter", "0 * * * * ?"),
|
||||
new PersistenceThresholdFilter("test", BigDecimal.TEN, "", false));
|
||||
|
||||
@ -428,8 +472,8 @@ public class PersistenceManagerTest {
|
||||
when(cronSchedulerMock.schedule(any(), any())).thenReturn(scheduledFutureMock);
|
||||
|
||||
PersistenceServiceConfiguration configuration = addConfiguration(TEST_PERSISTENCE_SERVICE_ID,
|
||||
new PersistenceItemConfig(TEST_ITEM_NAME), new PersistenceCronStrategy("everyHour", "0 0 * * * ?"),
|
||||
null);
|
||||
List.of(new PersistenceItemConfig(TEST_ITEM_NAME)),
|
||||
new PersistenceCronStrategy("everyHour", "0 0 * * * ?"), null);
|
||||
|
||||
manager.onReadyMarkerAdded(new ReadyMarker("", ""));
|
||||
|
||||
@ -444,8 +488,8 @@ public class PersistenceManagerTest {
|
||||
|
||||
@Test
|
||||
public void filterAppliesOnStateUpdate() {
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, new PersistenceAllConfig(), PersistenceStrategy.Globals.UPDATE,
|
||||
new PersistenceThresholdFilter("test", BigDecimal.TEN, "", false));
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, List.of(new PersistenceAllConfig()),
|
||||
PersistenceStrategy.Globals.UPDATE, new PersistenceThresholdFilter("test", BigDecimal.TEN, "", false));
|
||||
|
||||
manager.stateUpdated(TEST_ITEM3, DecimalType.ZERO);
|
||||
manager.stateUpdated(TEST_ITEM3, DecimalType.ZERO);
|
||||
@ -459,8 +503,9 @@ public class PersistenceManagerTest {
|
||||
* Add a configuration for restoring TEST_ITEM and mock the SafeCaller
|
||||
*/
|
||||
private void setupPersistence(PersistenceConfig itemConfig) {
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, itemConfig, PersistenceStrategy.Globals.RESTORE, null);
|
||||
addConfiguration(TEST_QUERYABLE_PERSISTENCE_SERVICE_ID, itemConfig, PersistenceStrategy.Globals.RESTORE, null);
|
||||
addConfiguration(TEST_PERSISTENCE_SERVICE_ID, List.of(itemConfig), PersistenceStrategy.Globals.RESTORE, null);
|
||||
addConfiguration(TEST_QUERYABLE_PERSISTENCE_SERVICE_ID, List.of(itemConfig),
|
||||
PersistenceStrategy.Globals.RESTORE, null);
|
||||
|
||||
when(safeCallerMock.create(queryablePersistenceServiceMock, QueryablePersistenceService.class))
|
||||
.thenReturn(safeCallerBuilderMock);
|
||||
@ -473,16 +518,16 @@ public class PersistenceManagerTest {
|
||||
* Add a configuration to the manager
|
||||
*
|
||||
* @param serviceId the persistence service id
|
||||
* @param itemConfig the item configuration
|
||||
* @param itemConfigs list item configurations
|
||||
* @param strategy the strategy
|
||||
* @param filter a persistence filter
|
||||
* @return the added strategy
|
||||
*/
|
||||
private PersistenceServiceConfiguration addConfiguration(String serviceId, PersistenceConfig itemConfig,
|
||||
private PersistenceServiceConfiguration addConfiguration(String serviceId, List<PersistenceConfig> itemConfigs,
|
||||
PersistenceStrategy strategy, @Nullable PersistenceFilter filter) {
|
||||
List<PersistenceFilter> filters = filter != null ? List.of(filter) : List.of();
|
||||
|
||||
PersistenceItemConfiguration itemConfiguration = new PersistenceItemConfiguration(List.of(itemConfig), null,
|
||||
PersistenceItemConfiguration itemConfiguration = new PersistenceItemConfiguration(itemConfigs, null,
|
||||
List.of(strategy), filters);
|
||||
|
||||
List<PersistenceStrategy> strategies = PersistenceStrategy.Globals.STRATEGIES.containsValue(strategy)
|
||||
|
Loading…
Reference in New Issue
Block a user