Search in sources :

Example 1 with InboxUpdatedEvent

use of org.openhab.core.config.discovery.inbox.events.InboxUpdatedEvent in project openhab-core by openhab.

the class PersistentInboxTest method testEmittedUpdatedResultIsReadFromStorage.

@Test
public void testEmittedUpdatedResultIsReadFromStorage() {
    DiscoveryResult result = DiscoveryResultBuilder.create(THING_UID).withProperty("foo", 3).build();
    EventPublisher eventPublisher = mock(EventPublisher.class);
    inbox.setEventPublisher(eventPublisher);
    // 
    when(storageMock.get(THING_UID.toString())).thenReturn(// 
    result).thenReturn(DiscoveryResultBuilder.create(THING_UID).withProperty("foo", "bar").build());
    inbox.activate();
    inbox.add(result);
    // 1st call checks existence of the result in the storage (returns the original result)
    // 2nd call retrieves the stored instance before the event gets emitted
    // (modified due to storage mock configuration)
    verify(storageMock, times(2)).get(THING_UID.toString());
    ArgumentCaptor<InboxUpdatedEvent> eventCaptor = ArgumentCaptor.forClass(InboxUpdatedEvent.class);
    verify(eventPublisher).post(eventCaptor.capture());
    assertThat(eventCaptor.getValue().getDiscoveryResult().properties, hasEntry("foo", "bar"));
}
Also used : DiscoveryResult(org.openhab.core.config.discovery.DiscoveryResult) EventPublisher(org.openhab.core.events.EventPublisher) InboxUpdatedEvent(org.openhab.core.config.discovery.inbox.events.InboxUpdatedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)1 DiscoveryResult (org.openhab.core.config.discovery.DiscoveryResult)1 InboxUpdatedEvent (org.openhab.core.config.discovery.inbox.events.InboxUpdatedEvent)1 EventPublisher (org.openhab.core.events.EventPublisher)1