Search in sources :

Example 1 with FirmwareStatusInfoEvent

use of org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfoEvent in project smarthome by eclipse.

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.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfoEvent)

Example 2 with FirmwareStatusInfoEvent

use of org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfoEvent in project smarthome by eclipse.

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(handler1).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(mockPublisher, 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) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ProgressCallback(org.eclipse.smarthome.core.thing.binding.firmware.ProgressCallback) Locale(java.util.Locale) Map(java.util.Map) Thing(org.eclipse.smarthome.core.thing.Thing) After(org.junit.After) FirmwareUpdateHandler(org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler) Bundle(org.osgi.framework.Bundle) TranslationProvider(org.eclipse.smarthome.core.i18n.TranslationProvider) FirmwareRegistry(org.eclipse.smarthome.core.thing.firmware.FirmwareRegistry) EventPublisher(org.eclipse.smarthome.core.events.EventPublisher) Collectors(java.util.stream.Collectors) FirmwareUpdateResultInfoEvent(org.eclipse.smarthome.core.thing.firmware.FirmwareUpdateResultInfoEvent) List(java.util.List) Stream(java.util.stream.Stream) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) Mock(org.mockito.Mock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Firmware(org.eclipse.smarthome.core.thing.binding.firmware.Firmware) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) TreeSet(java.util.TreeSet) FirmwareUpdateBackgroundTransferHandler(org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateBackgroundTransferHandler) FirmwareUpdateResult(org.eclipse.smarthome.core.thing.firmware.FirmwareUpdateResult) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) FirmwareStatusInfo(org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo) SafeCaller(org.eclipse.smarthome.core.common.SafeCaller) FirmwareUpdateService(org.eclipse.smarthome.core.thing.firmware.FirmwareUpdateService) NoSuchElementException(java.util.NoSuchElementException) ExpectedException(org.junit.rules.ExpectedException) Hashtable(java.util.Hashtable) Before(org.junit.Before) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) FirmwareUpdateProgressInfoEvent(org.eclipse.smarthome.core.thing.firmware.FirmwareUpdateProgressInfoEvent) BundleResolver(org.eclipse.smarthome.core.util.BundleResolver) ConfigDescriptionValidator(org.eclipse.smarthome.config.core.validation.ConfigDescriptionValidator) IOException(java.io.IOException) Test(org.junit.Test) Constants(org.eclipse.smarthome.core.thing.firmware.Constants) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) FirmwareStatusInfoEvent(org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfoEvent) LocaleProvider(org.eclipse.smarthome.core.i18n.LocaleProvider) ProgressStep(org.eclipse.smarthome.core.thing.binding.firmware.ProgressStep) Assert(org.junit.Assert) Event(org.eclipse.smarthome.core.events.Event) Collections(java.util.Collections) FirmwareStatusInfo(org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo) ProgressCallback(org.eclipse.smarthome.core.thing.binding.firmware.ProgressCallback) AtomicReference(java.util.concurrent.atomic.AtomicReference) FirmwareUpdateResultInfoEvent(org.eclipse.smarthome.core.thing.firmware.FirmwareUpdateResultInfoEvent) FirmwareUpdateProgressInfoEvent(org.eclipse.smarthome.core.thing.firmware.FirmwareUpdateProgressInfoEvent) FirmwareStatusInfoEvent(org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfoEvent) Event(org.eclipse.smarthome.core.events.Event) FirmwareUpdateProgressInfoEvent(org.eclipse.smarthome.core.thing.firmware.FirmwareUpdateProgressInfoEvent) List(java.util.List) ArrayList(java.util.ArrayList) Firmware(org.eclipse.smarthome.core.thing.binding.firmware.Firmware) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Aggregations

FirmwareStatusInfoEvent (org.eclipse.smarthome.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 Hashtable (java.util.Hashtable)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)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 ConfigDescriptionValidator (org.eclipse.smarthome.config.core.validation.ConfigDescriptionValidator)1 SafeCaller (org.eclipse.smarthome.core.common.SafeCaller)1 Event (org.eclipse.smarthome.core.events.Event)1