Search in sources :

Example 1 with FirmwareUpdateResultInfoEvent

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

the class FirmwareUpdateServiceTest method assertCancellationMessage.

private void assertCancellationMessage(String messageKey, String expectedEnglishMessage, Locale locale, int expectedEventCount) {
    when(mockLocaleProvider.getLocale()).thenReturn(locale);
    when(mockTranslationProvider.getText(any(Bundle.class), eq(messageKey), any(), eq(locale), any())).thenReturn(expectedEnglishMessage);
    Exception exception = new RuntimeException();
    doThrow(exception).when(handler3).cancel();
    firmwareUpdateService.updateFirmware(THING4_UID, FW111_EN.getVersion(), locale);
    firmwareUpdateService.cancelFirmwareUpdate(THING4_UID);
    AtomicReference<FirmwareUpdateResultInfoEvent> resultEvent = new AtomicReference<FirmwareUpdateResultInfoEvent>();
    waitForAssert(() -> {
        ArgumentCaptor<FirmwareUpdateResultInfoEvent> eventCaptor = ArgumentCaptor.forClass(FirmwareUpdateResultInfoEvent.class);
        verify(mockPublisher, 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.eclipse.smarthome.core.thing.firmware.FirmwareUpdateResultInfoEvent) AtomicReference(java.util.concurrent.atomic.AtomicReference) NoSuchElementException(java.util.NoSuchElementException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException)

Example 2 with FirmwareUpdateResultInfoEvent

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

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(expectedThingUID));
    assertThat(resultEvent.getFirmwareUpdateResultInfo().getResult(), is(FirmwareUpdateResult.CANCELED));
    assertThat(usedMessagedKey, is(cancelMessageKey));
}
Also used : FirmwareUpdateResultInfoEvent(org.eclipse.smarthome.core.thing.firmware.FirmwareUpdateResultInfoEvent) Test(org.junit.Test)

Example 3 with FirmwareUpdateResultInfoEvent

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

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

Example 4 with FirmwareUpdateResultInfoEvent

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

the class ProgressCallbackTest method assertThatUpdateResultEventIsValid.

private void assertThatUpdateResultEventIsValid(Event event, String expectedMessageKey, FirmwareUpdateResult expectedResult) {
    assertThat(event, is(instanceOf(FirmwareUpdateResultInfoEvent.class)));
    FirmwareUpdateResultInfoEvent fpiEvent = (FirmwareUpdateResultInfoEvent) event;
    assertThat(usedMessagedKey, is(expectedMessageKey));
    assertThat(fpiEvent.getFirmwareUpdateResultInfo().getThingUID(), is(expectedThingUID));
    assertThat(fpiEvent.getFirmwareUpdateResultInfo().getResult(), is(expectedResult));
}
Also used : FirmwareUpdateResultInfoEvent(org.eclipse.smarthome.core.thing.firmware.FirmwareUpdateResultInfoEvent)

Aggregations

FirmwareUpdateResultInfoEvent (org.eclipse.smarthome.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.Test)1 ExpectedException (org.junit.rules.ExpectedException)1 Bundle (org.osgi.framework.Bundle)1