use of org.openhab.core.events.Event in project openhab-core by openhab.
the class ExpireManagerTest method testCancelExpiry.
@Test
void testCancelExpiry() throws InterruptedException, ItemNotFoundException {
Item testItem = new SwitchItem(ITEMNAME);
when(itemRegistryMock.getItem(ITEMNAME)).thenReturn(testItem);
when(metadataRegistryMock.get(METADATA_KEY)).thenReturn(config("1s,ON"));
Event event = ItemEventFactory.createCommandEvent(ITEMNAME, OnOffType.OFF);
expireManager.receive(event);
Thread.sleep(500L);
event = ItemEventFactory.createCommandEvent(ITEMNAME, OnOffType.ON);
expireManager.receive(event);
Thread.sleep(2000L);
verify(eventPublisherMock, never()).post(any());
}
use of org.openhab.core.events.Event in project openhab-core by openhab.
the class ExpireManagerTest method testStateExpiryWithCustomState.
@Test
void testStateExpiryWithCustomState() throws InterruptedException, ItemNotFoundException {
Item testItem = new SwitchItem(ITEMNAME);
when(itemRegistryMock.getItem(ITEMNAME)).thenReturn(testItem);
when(metadataRegistryMock.get(METADATA_KEY)).thenReturn(config("1s,state=OFF"));
Event event = ItemEventFactory.createCommandEvent(ITEMNAME, OnOffType.ON);
expireManager.receive(event);
verify(eventPublisherMock, never()).post(any());
Thread.sleep(2500L);
verify(eventPublisherMock).post(eq(ItemEventFactory.createStateEvent(ITEMNAME, OnOffType.OFF, ExpireManager.EVENT_SOURCE)));
}
use of org.openhab.core.events.Event in project openhab-core by openhab.
the class ExpireManagerTest method testMetadataChange.
@Test
void testMetadataChange() throws InterruptedException, ItemNotFoundException {
Metadata md = new Metadata(METADATA_KEY, "1s", null);
when(metadataRegistryMock.get(METADATA_KEY)).thenReturn(md);
Event event = ItemEventFactory.createCommandEvent(ITEMNAME, OnOffType.ON);
expireManager.receive(event);
verify(eventPublisherMock, never()).post(any());
Thread.sleep(2500L);
verify(eventPublisherMock).post(eq(ItemEventFactory.createStateEvent(ITEMNAME, UnDefType.UNDEF, ExpireManager.EVENT_SOURCE)));
when(metadataRegistryMock.get(METADATA_KEY)).thenReturn(null);
expireManager.metadataChangeListener.removed(md);
reset(eventPublisherMock);
event = ItemEventFactory.createCommandEvent(ITEMNAME, OnOffType.ON);
expireManager.receive(event);
verify(eventPublisherMock, never()).post(any());
Thread.sleep(2500L);
verify(eventPublisherMock, never()).post(any());
}
use of org.openhab.core.events.Event in project openhab-core by openhab.
the class ExpireManagerTest method testDefaultStateExpiry.
@Test
void testDefaultStateExpiry() throws InterruptedException {
when(metadataRegistryMock.get(METADATA_KEY)).thenReturn(new Metadata(METADATA_KEY, "1s", null));
Event event = ItemEventFactory.createCommandEvent(ITEMNAME, OnOffType.ON);
expireManager.receive(event);
verify(eventPublisherMock, never()).post(any());
Thread.sleep(2500L);
verify(eventPublisherMock).post(eq(ItemEventFactory.createStateEvent(ITEMNAME, UnDefType.UNDEF, ExpireManager.EVENT_SOURCE)));
}
use of org.openhab.core.events.Event in project openhab-core by openhab.
the class ExpireManagerTest method testIgnoreStateUpdateExtendsExpiryOnStateChange.
@Test
void testIgnoreStateUpdateExtendsExpiryOnStateChange() throws InterruptedException, ItemNotFoundException {
Item testItem = new NumberItem(ITEMNAME);
when(itemRegistryMock.getItem(ITEMNAME)).thenReturn(testItem);
when(metadataRegistryMock.get(METADATA_KEY)).thenReturn(config("2s", Map.of(ExpireConfig.CONFIG_IGNORE_STATE_UPDATES, true)));
Event event = ItemEventFactory.createCommandEvent(ITEMNAME, new DecimalType(1));
expireManager.receive(event);
Thread.sleep(1500L);
event = ItemEventFactory.createStateChangedEvent(ITEMNAME, new DecimalType(2), new DecimalType(1));
expireManager.receive(event);
Thread.sleep(1500L);
verify(eventPublisherMock, never()).post(any());
Thread.sleep(2000L);
verify(eventPublisherMock, times(1)).post(any());
}
Aggregations