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]));
}
}
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));
}
Aggregations