use of org.eclipse.smarthome.core.thing.firmware.FirmwareUpdateProgressInfoEvent in project smarthome by eclipse.
the class ProgressCallbackTest method assertThatProgressInfoEventIsValid.
private void assertThatProgressInfoEventIsValid(Event event, ProgressStep expectedStep, boolean expectedPending, Integer expectedProgress) {
assertThat(event, is(instanceOf(FirmwareUpdateProgressInfoEvent.class)));
FirmwareUpdateProgressInfoEvent fpiEvent = (FirmwareUpdateProgressInfoEvent) event;
assertThat(fpiEvent.getProgressInfo().getThingUID(), is(expectedThingUID));
assertThat(fpiEvent.getProgressInfo().getFirmwareVersion(), is(expectedFirmware.getVersion()));
assertThat(fpiEvent.getProgressInfo().getProgressStep(), is(expectedStep));
assertThat(fpiEvent.getProgressInfo().getProgress(), is(expectedProgress));
assertThat(fpiEvent.getProgressInfo().isPending(), (is(expectedPending)));
}
use of org.eclipse.smarthome.core.thing.firmware.FirmwareUpdateProgressInfoEvent 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]));
}
}
Aggregations