Search in sources :

Example 1 with FirmwareUpdateResultInfoEvent

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));
}
Also used : FirmwareUpdateResultInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent)

Example 2 with FirmwareUpdateResultInfoEvent

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));
}
Also used : FirmwareUpdateResultInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent) Test(org.junit.jupiter.api.Test)

Example 3 with FirmwareUpdateResultInfoEvent

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));
}
Also used : FirmwareUpdateResultInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent)

Example 4 with FirmwareUpdateResultInfoEvent

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));
}
Also used : Bundle(org.osgi.framework.Bundle) FirmwareUpdateResultInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent) AtomicReference(java.util.concurrent.atomic.AtomicReference) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException)

Aggregations

FirmwareUpdateResultInfoEvent (org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent)4 IOException (java.io.IOException)1 NoSuchElementException (java.util.NoSuchElementException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.jupiter.api.Test)1 Bundle (org.osgi.framework.Bundle)1