Search in sources :

Example 1 with FirmwareStatusInfoEvent

use of org.openhab.core.thing.firmware.FirmwareStatusInfoEvent in project openhab-core by openhab.

the class FirmwareUpdateServiceTest method testEvents.

@Test
public void testEvents() {
    doAnswer(invocation -> {
        Firmware firmware = (Firmware) invocation.getArguments()[0];
        ProgressCallback progressCallback = (ProgressCallback) invocation.getArguments()[1];
        progressCallback.defineSequence(SEQUENCE);
        progressCallback.next();
        progressCallback.next();
        progressCallback.next();
        progressCallback.next();
        thing1.setProperty(Thing.PROPERTY_FIRMWARE_VERSION, firmware.getVersion());
        return null;
    }).when(handler1Mock).updateFirmware(any(Firmware.class), any(ProgressCallback.class));
    // getFirmwareStatusInfo() method will internally generate and post one FirmwareStatusInfoEvent event.
    final FirmwareStatusInfo updateExecutableInfoFw112 = createUpdateExecutableInfo(thing1.getUID(), V112);
    assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw112));
    firmwareUpdateService.updateFirmware(THING1_UID, FW112_EN.getVersion(), null);
    AtomicReference<List<Event>> events = new AtomicReference<>(new ArrayList<>());
    ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
    waitForAssert(() -> {
        // Wait for four FirmwareUpdateProgressInfoEvents plus one FirmwareStatusInfoEvent event.
        verify(eventPublisherMock, atLeast(SEQUENCE.length + 1)).post(eventCaptor.capture());
    });
    events.get().addAll(eventCaptor.getAllValues());
    List<Event> list = events.get().stream().filter(event -> event instanceof FirmwareUpdateProgressInfoEvent).collect(Collectors.toList());
    assertTrue(list.size() >= SEQUENCE.length);
    for (int i = 0; i < SEQUENCE.length; i++) {
        FirmwareUpdateProgressInfoEvent event = (FirmwareUpdateProgressInfoEvent) list.get(i);
        assertThat(event.getTopic(), containsString(THING1_UID.getAsString()));
        assertThat(event.getProgressInfo().getThingUID(), is(THING1_UID));
        assertThat(event.getProgressInfo().getProgressStep(), is(SEQUENCE[i]));
    }
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ProgressCallback(org.openhab.core.thing.binding.firmware.ProgressCallback) FirmwareUpdateResultInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent) SafeCaller(org.openhab.core.common.SafeCaller) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Locale(java.util.Locale) Map(java.util.Map) FirmwareUpdateService(org.openhab.core.thing.firmware.FirmwareUpdateService) ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder) Bundle(org.osgi.framework.Bundle) EventPublisher(org.openhab.core.events.EventPublisher) FirmwareRegistry(org.openhab.core.thing.firmware.FirmwareRegistry) BundleResolver(org.openhab.core.util.BundleResolver) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) FirmwareUpdateHandler(org.openhab.core.thing.binding.firmware.FirmwareUpdateHandler) Set(java.util.Set) FirmwareUpdateBackgroundTransferHandler(org.openhab.core.thing.binding.firmware.FirmwareUpdateBackgroundTransferHandler) TranslationProvider(org.openhab.core.i18n.TranslationProvider) Collectors(java.util.stream.Collectors) Firmware(org.openhab.core.thing.binding.firmware.Firmware) Test(org.junit.jupiter.api.Test) List(java.util.List) LocaleProvider(org.openhab.core.i18n.LocaleProvider) Stream(java.util.stream.Stream) FirmwareStatusInfoEvent(org.openhab.core.thing.firmware.FirmwareStatusInfoEvent) FirmwareUpdateProgressInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateProgressInfoEvent) FirmwareStatusInfo(org.openhab.core.thing.firmware.FirmwareStatusInfo) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Strictness(org.mockito.quality.Strictness) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) Mock(org.mockito.Mock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ConfigDescriptionValidator(org.openhab.core.config.core.validation.ConfigDescriptionValidator) Answer(org.mockito.stubbing.Answer) Thing(org.openhab.core.thing.Thing) ArgumentCaptor(org.mockito.ArgumentCaptor) Map.entry(java.util.Map.entry) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NoSuchElementException(java.util.NoSuchElementException) FirmwareUpdateResult(org.openhab.core.thing.firmware.FirmwareUpdateResult) ThingUID(org.openhab.core.thing.ThingUID) Event(org.openhab.core.events.Event) Constants(org.openhab.core.thing.firmware.Constants) IOException(java.io.IOException) ProgressStep(org.openhab.core.thing.binding.firmware.ProgressStep) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest) Assertions(org.junit.jupiter.api.Assertions) Collections(java.util.Collections) FirmwareStatusInfo(org.openhab.core.thing.firmware.FirmwareStatusInfo) ProgressCallback(org.openhab.core.thing.binding.firmware.ProgressCallback) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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) FirmwareUpdateProgressInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateProgressInfoEvent) List(java.util.List) ArrayList(java.util.ArrayList) Firmware(org.openhab.core.thing.binding.firmware.Firmware) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 2 with FirmwareStatusInfoEvent

use of org.openhab.core.thing.firmware.FirmwareStatusInfoEvent in project openhab-core by openhab.

the class FirmwareUpdateServiceTest method assertFirmwareStatusInfoEvent.

private void assertFirmwareStatusInfoEvent(ThingUID thingUID, Event event, FirmwareStatusInfo expectedInfo) {
    assertThat(event, is(instanceOf(FirmwareStatusInfoEvent.class)));
    FirmwareStatusInfoEvent firmwareStatusInfoEvent = (FirmwareStatusInfoEvent) event;
    assertThat(firmwareStatusInfoEvent.getTopic(), containsString(thingUID.getAsString()));
    assertThat(firmwareStatusInfoEvent.getFirmwareStatusInfo().getThingUID(), is(thingUID));
    assertThat(firmwareStatusInfoEvent.getFirmwareStatusInfo(), is(expectedInfo));
}
Also used : FirmwareStatusInfoEvent(org.openhab.core.thing.firmware.FirmwareStatusInfoEvent)

Aggregations

FirmwareStatusInfoEvent (org.openhab.core.thing.firmware.FirmwareStatusInfoEvent)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Map.entry (java.util.Map.entry)1 NoSuchElementException (java.util.NoSuchElementException)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)1 CoreMatchers (org.hamcrest.CoreMatchers)1