Search in sources :

Example 51 with Event

use of org.openhab.core.events.Event in project openhab-core by openhab.

the class FirmwareUpdateServiceTest method firmwareStatusPropagatedRegularly.

@Test
public void firmwareStatusPropagatedRegularly() throws Exception {
    final FirmwareStatusInfo unknownInfo = createUnknownInfo(thing3.getUID());
    final FirmwareStatusInfo upToDateInfo = createUpToDateInfo(thing2.getUID());
    final FirmwareStatusInfo updateExecutableInfoFw112 = createUpdateExecutableInfo(thing1.getUID(), V112);
    assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V111));
    assertThat(thing2.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V112));
    updateConfig(1, 0, TimeUnit.SECONDS);
    waitForAssert(() -> {
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(eventPublisherMock, times(3)).post(eventCaptor.capture());
        assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw112);
        assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), upToDateInfo);
        assertFirmwareStatusInfoEvent(THING3_UID, eventCaptor.getAllValues().get(2), unknownInfo);
    });
    reset(eventPublisherMock);
    // Simulate addition of extra firmware provider
    when(firmwareRegistryMock.getFirmware(eq(thing2), eq(VALPHA))).thenReturn(null);
    when(firmwareRegistryMock.getFirmwares(any(Thing.class))).thenAnswer(invocation -> {
        Thing thing = (Thing) invocation.getArguments()[0];
        if (THING_TYPE_UID_WITHOUT_FW.equals(thing.getThingTypeUID()) || THING_TYPE_UID2.equals(thing.getThingTypeUID())) {
            return Collections.emptySet();
        } else {
            return Set.of(FW113_EN);
        }
    });
    waitForAssert(() -> {
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(eventPublisherMock, times(2)).post(eventCaptor.capture());
        FirmwareStatusInfo updateExecutableInfoFw113 = createUpdateExecutableInfo(thing1.getUID(), V113);
        assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw113);
        updateExecutableInfoFw113 = createUpdateExecutableInfo(thing2.getUID(), V113);
        assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), updateExecutableInfoFw113);
    });
    reset(eventPublisherMock);
    // Simulate removed firmware provider - get back everything as it was initially
    initialFirmwareRegistryMocking();
    waitForAssert(() -> {
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(eventPublisherMock, times(2)).post(eventCaptor.capture());
        assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw112);
        assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), upToDateInfo);
    });
}
Also used : FirmwareStatusInfo(org.openhab.core.thing.firmware.FirmwareStatusInfo) FirmwareUpdateResultInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent) FirmwareStatusInfoEvent(org.openhab.core.thing.firmware.FirmwareStatusInfoEvent) FirmwareUpdateProgressInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateProgressInfoEvent) Event(org.openhab.core.events.Event) Thing(org.openhab.core.thing.Thing) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 52 with Event

use of org.openhab.core.events.Event in project openhab-core by openhab.

the class FirmwareUpdateServiceTest method testUpdateFirmware.

@Test
public void testUpdateFirmware() {
    final FirmwareStatusInfo upToDateInfo = createUpToDateInfo(thing1.getUID());
    final FirmwareStatusInfo updateExecutableInfoFw112 = createUpdateExecutableInfo(thing1.getUID(), V112);
    assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw112));
    firmwareUpdateService.updateFirmware(THING1_UID, V112, null);
    waitForAssert(() -> {
        assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V112.toString()));
    });
    assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(upToDateInfo));
    // verify that the corresponding events are sent
    ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventPublisherMock, times(2)).post(eventCaptor.capture());
    assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw112);
    assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(1), upToDateInfo);
}
Also used : FirmwareStatusInfo(org.openhab.core.thing.firmware.FirmwareStatusInfo) FirmwareUpdateResultInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent) FirmwareStatusInfoEvent(org.openhab.core.thing.firmware.FirmwareStatusInfoEvent) FirmwareUpdateProgressInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateProgressInfoEvent) Event(org.openhab.core.events.Event) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 53 with Event

use of org.openhab.core.events.Event in project openhab-core by openhab.

the class FirmwareUpdateServiceTest method testUpdateFirmwareDowngrade.

@Test
public void testUpdateFirmwareDowngrade() {
    final FirmwareStatusInfo upToDateInfo = createUpToDateInfo(thing2.getUID());
    final FirmwareStatusInfo updateExecutableInfoFw112 = createUpdateExecutableInfo(thing2.getUID(), V112);
    assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING2_UID), is(upToDateInfo));
    firmwareUpdateService.updateFirmware(THING2_UID, V111, null);
    waitForAssert(() -> {
        assertThat(thing2.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V111.toString()));
    });
    assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING2_UID), is(updateExecutableInfoFw112));
    // verify that the corresponding events are sent
    ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventPublisherMock, times(2)).post(eventCaptor.capture());
    assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(0), upToDateInfo);
    assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), updateExecutableInfoFw112);
}
Also used : FirmwareStatusInfo(org.openhab.core.thing.firmware.FirmwareStatusInfo) FirmwareUpdateResultInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent) FirmwareStatusInfoEvent(org.openhab.core.thing.firmware.FirmwareStatusInfoEvent) FirmwareUpdateProgressInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateProgressInfoEvent) Event(org.openhab.core.events.Event) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 54 with Event

use of org.openhab.core.events.Event in project openhab-core by openhab.

the class AddonEventFactory method createEventByType.

@Override
protected Event createEventByType(String eventType, String topic, String payload, @Nullable String source) throws Exception {
    if (topic.endsWith(ADDON_FAILURE_EVENT_TOPIC_POSTFIX)) {
        String[] properties = deserializePayload(payload, String[].class);
        Event event = new AddonEvent(topic, payload, properties[0], properties[1]);
        return event;
    } else {
        String id = deserializePayload(payload, String.class);
        Event event = new AddonEvent(topic, payload, id);
        return event;
    }
}
Also used : Event(org.openhab.core.events.Event)

Example 55 with Event

use of org.openhab.core.events.Event in project openhab-core by openhab.

the class ExpireManagerTest method testIgnoreStateUpdateDoesNotExtendExpiryOnStateUpdate.

@Test
void testIgnoreStateUpdateDoesNotExtendExpiryOnStateUpdate() 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.createStateEvent(ITEMNAME, new DecimalType(1));
    expireManager.receive(event);
    Thread.sleep(1500L);
    verify(eventPublisherMock, times(1)).post(any());
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) SwitchItem(org.openhab.core.library.items.SwitchItem) NumberItem(org.openhab.core.library.items.NumberItem) Item(org.openhab.core.items.Item) StringItem(org.openhab.core.library.items.StringItem) Event(org.openhab.core.events.Event) DecimalType(org.openhab.core.library.types.DecimalType) Test(org.junit.jupiter.api.Test)

Aggregations

Event (org.openhab.core.events.Event)120 Test (org.junit.jupiter.api.Test)93 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)58 EventSubscriber (org.openhab.core.events.EventSubscriber)46 ItemCommandEvent (org.openhab.core.items.events.ItemCommandEvent)38 Nullable (org.eclipse.jdt.annotation.Nullable)28 SwitchItem (org.openhab.core.library.items.SwitchItem)28 EventPublisher (org.openhab.core.events.EventPublisher)27 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)25 BeforeEach (org.junit.jupiter.api.BeforeEach)22 Item (org.openhab.core.items.Item)22 Set (java.util.Set)21 Rule (org.openhab.core.automation.Rule)20 RuleStatusInfoEvent (org.openhab.core.automation.events.RuleStatusInfoEvent)20 EventFilter (org.openhab.core.events.EventFilter)20 NumberItem (org.openhab.core.library.items.NumberItem)18 LinkedList (java.util.LinkedList)17 List (java.util.List)17 ArrayList (java.util.ArrayList)16 Configuration (org.openhab.core.config.core.Configuration)16