use of org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent in project openhab-core by openhab.
the class ProgressCallbackTest method assertThatUpdateResultEventIsValid.
private void assertThatUpdateResultEventIsValid(Event event, @Nullable String expectedMessageKey, FirmwareUpdateResult expectedResult) {
assertThat(event, is(instanceOf(FirmwareUpdateResultInfoEvent.class)));
FirmwareUpdateResultInfoEvent fpiEvent = (FirmwareUpdateResultInfoEvent) event;
assertThat(usedMessagedKey, is(expectedMessageKey));
assertThat(fpiEvent.getFirmwareUpdateResultInfo().getThingUID(), is(EXPECTED_THING_UID));
assertThat(fpiEvent.getFirmwareUpdateResultInfo().getResult(), is(expectedResult));
}
use of org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent in project openhab-core by openhab.
the class ProgressCallbackTest method assertThatCallingCancelResultsInAFirmwareUpdateResultInfoEvent.
@Test
public void assertThatCallingCancelResultsInAFirmwareUpdateResultInfoEvent() {
sut.defineSequence(ProgressStep.DOWNLOADING, ProgressStep.TRANSFERRING);
sut.canceled();
assertThat(postedEvents.size(), is(1));
assertThat(postedEvents.get(0), is(instanceOf(FirmwareUpdateResultInfoEvent.class)));
FirmwareUpdateResultInfoEvent resultEvent = (FirmwareUpdateResultInfoEvent) postedEvents.get(0);
assertThat(resultEvent.getFirmwareUpdateResultInfo().getThingUID(), is(EXPECTED_THING_UID));
assertThat(resultEvent.getFirmwareUpdateResultInfo().getResult(), is(FirmwareUpdateResult.CANCELED));
assertThat(usedMessagedKey, is(CANCEL_MESSAGE_KEY));
}
use of org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent in project openhab-core by openhab.
the class FirmwareUpdateServiceTest method assertFailedFirmwareUpdate.
private void assertFailedFirmwareUpdate(ThingUID thingUID, Event event, String expectedErrorMessage) {
assertThat(event, is(instanceOf(FirmwareUpdateResultInfoEvent.class)));
FirmwareUpdateResultInfoEvent firmwareUpdateResultInfoEvent = (FirmwareUpdateResultInfoEvent) event;
assertThat(firmwareUpdateResultInfoEvent.getTopic(), containsString(THING1_UID.getAsString()));
assertThat(firmwareUpdateResultInfoEvent.getFirmwareUpdateResultInfo().getThingUID(), is(THING1_UID));
assertThat(firmwareUpdateResultInfoEvent.getFirmwareUpdateResultInfo().getResult(), is(FirmwareUpdateResult.ERROR));
assertThat(firmwareUpdateResultInfoEvent.getFirmwareUpdateResultInfo().getErrorMessage(), is(expectedErrorMessage));
}
use of org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent in project openhab-core by openhab.
the class FirmwareUpdateServiceTest method assertCancellationMessage.
private void assertCancellationMessage(String messageKey, String expectedEnglishMessage, Locale locale, int expectedEventCount) {
when(localeProviderMock.getLocale()).thenReturn(locale);
when(translationProviderMock.getText(any(Bundle.class), eq(messageKey), any(), eq(locale), any())).thenReturn(expectedEnglishMessage);
Exception exception = new RuntimeException();
doThrow(exception).when(handler3Mock).cancel();
firmwareUpdateService.updateFirmware(THING4_UID, FW111_EN.getVersion(), locale);
firmwareUpdateService.cancelFirmwareUpdate(THING4_UID);
AtomicReference<FirmwareUpdateResultInfoEvent> resultEvent = new AtomicReference<>();
waitForAssert(() -> {
ArgumentCaptor<FirmwareUpdateResultInfoEvent> eventCaptor = ArgumentCaptor.forClass(FirmwareUpdateResultInfoEvent.class);
verify(eventPublisherMock, times(expectedEventCount)).post(eventCaptor.capture());
assertEquals(expectedEventCount, eventCaptor.getAllValues().size());
resultEvent.set(eventCaptor.getAllValues().get(eventCaptor.getAllValues().size() - 1));
});
assertThat(resultEvent.get().getFirmwareUpdateResultInfo().getThingUID(), is(THING4_UID));
assertThat(resultEvent.get().getFirmwareUpdateResultInfo().getResult(), is(FirmwareUpdateResult.ERROR));
assertThat(resultEvent.get().getFirmwareUpdateResultInfo().getErrorMessage(), is(expectedEnglishMessage));
}
Aggregations