use of org.openhab.core.thing.firmware.FirmwareStatusInfo in project openhab-core by openhab.
the class FirmwareUpdateServiceTest method testUpdateFirmwareError.
@Test
public void testUpdateFirmwareError() {
doAnswer(invocation -> {
ProgressCallback progressCallback = (ProgressCallback) invocation.getArguments()[1];
progressCallback.defineSequence(SEQUENCE);
progressCallback.next();
progressCallback.next();
progressCallback.next();
progressCallback.next();
try {
progressCallback.next();
} catch (NoSuchElementException e) {
fail("Unexcepted exception thrown");
}
return null;
}).when(handler1Mock).updateFirmware(any(Firmware.class), any(ProgressCallback.class));
final FirmwareStatusInfo updateExecutableInfoFw112 = createUpdateExecutableInfo(thing1.getUID(), V112);
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw112));
assertResultInfoEvent(THING1_UID, FW112_EN, "unexpected-handler-error", Locale.ENGLISH, "english", 1);
assertResultInfoEvent(THING1_UID, FW112_EN, "unexpected-handler-error", Locale.GERMAN, "deutsch", 2);
assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V111.toString()));
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw112));
}
use of org.openhab.core.thing.firmware.FirmwareStatusInfo in project openhab-core by openhab.
the class FirmwareUpdateServiceTest method testPrerequisiteVersionCheckIllegalVersion.
@Test
public void testPrerequisiteVersionCheckIllegalVersion() {
when(firmwareRegistryMock.getFirmware(any(Thing.class), any(String.class))).thenAnswer(invocation -> {
String firmwareVersion = (String) invocation.getArguments()[1];
if (V111_FIX.equals(firmwareVersion)) {
return FW111_FIX_EN;
} else if (V113.equals(firmwareVersion)) {
return FW113_EN;
} else {
return null;
}
});
when(firmwareRegistryMock.getFirmwares(any(Thing.class))).thenAnswer(invocation -> {
Thing thing = (Thing) invocation.getArguments()[0];
if (THING_TYPE_UID_WITHOUT_FW.equals(thing.getThingTypeUID()) || THING_TYPE_UID2.equals(thing.getThingTypeUID())) {
return Collections.emptySet();
} else {
Supplier<TreeSet<Firmware>> supplier = () -> new TreeSet<>();
return Stream.of(FW111_FIX_EN, FW113_EN).collect(Collectors.toCollection(supplier));
}
});
when(firmwareRegistryMock.getFirmware(any(Thing.class), eq(V113))).thenReturn(FW113_EN);
final FirmwareStatusInfo updateExecutableInfoFw113 = createUpdateExecutableInfo(thing1.getUID(), V113);
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw113));
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> firmwareUpdateService.updateFirmware(THING1_UID, V113, null));
assertThat(exception.getMessage(), is(String.format("Firmware %s is not suitable for thing with UID %s.", FW113_EN, THING1_UID)));
}
use of org.openhab.core.thing.firmware.FirmwareStatusInfo in project openhab-core by openhab.
the class FirmwareUpdateServiceTest method testGetFirmwareStatusInfoEventsOnlySentOnce.
@Test
public void testGetFirmwareStatusInfoEventsOnlySentOnce() {
final FirmwareStatusInfo updateExecutableInfoFw112 = createUpdateExecutableInfo(thing1.getUID(), V112);
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw112));
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw112));
// verify that the corresponding events are sent
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventPublisherMock, times(1)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw112);
}
use of org.openhab.core.thing.firmware.FirmwareStatusInfo in project openhab-core by openhab.
the class FirmwareUpdateServiceTest method testGetFirmwareStatusInfoNoFirmwareProvider.
@Test
public void testGetFirmwareStatusInfoNoFirmwareProvider() {
final FirmwareStatusInfo unknownInfo = createUnknownInfo(thing3.getUID());
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING3_UID), is(unknownInfo));
// verify that the corresponding events are sent
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventPublisherMock, times(1)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING3_UID, eventCaptor.getValue(), unknownInfo);
}
use of org.openhab.core.thing.firmware.FirmwareStatusInfo in project openhab-core by openhab.
the class FirmwareUpdateServiceTest method testPrerequisiteVersionCheck.
@Test
public void testPrerequisiteVersionCheck() {
when(firmwareRegistryMock.getFirmware(any(Thing.class), any(String.class), any())).thenAnswer(invocation -> {
String version = (String) invocation.getArguments()[1];
if (V111_FIX.equals(version)) {
return FW111_FIX_EN;
} else if (V113.equals(version)) {
return FW113_EN;
} else {
return null;
}
});
Answer<?> firmwaresAnswer = invocation -> {
Thing thing = (Thing) invocation.getArguments()[0];
if (THING_TYPE_UID_WITHOUT_FW.equals(thing.getThingTypeUID()) || THING_TYPE_UID2.equals(thing.getThingTypeUID())) {
return Collections.emptySet();
} else {
Supplier<TreeSet<Firmware>> supplier = () -> new TreeSet<>();
return Stream.of(FW111_FIX_EN, FW113_EN).collect(Collectors.toCollection(supplier));
}
};
when(firmwareRegistryMock.getFirmwares(any(Thing.class), any())).thenAnswer(firmwaresAnswer);
when(firmwareRegistryMock.getFirmwares(any(Thing.class))).thenAnswer(firmwaresAnswer);
when(firmwareRegistryMock.getFirmware(any(Thing.class), eq(V111_FIX))).thenReturn(FW111_FIX_EN);
when(firmwareRegistryMock.getFirmware(any(Thing.class), eq(V113))).thenReturn(FW113_EN);
final FirmwareStatusInfo updateExecutableInfoFw113 = createUpdateExecutableInfo(thing1.getUID(), V113);
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw113));
firmwareUpdateService.updateFirmware(THING1_UID, FW111_FIX_EN.getVersion(), null);
waitForAssert(() -> {
assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V111_FIX));
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw113));
});
firmwareUpdateService.updateFirmware(THING1_UID, FW113_EN.getVersion(), null);
final FirmwareStatusInfo upToDateInfo1 = createUpToDateInfo(thing1.getUID());
final FirmwareStatusInfo updateExecutableInfoFw1132 = createUpdateExecutableInfo(thing2.getUID(), V113);
waitForAssert(() -> {
assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V113));
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(upToDateInfo1));
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING2_UID), is(updateExecutableInfoFw1132));
});
firmwareUpdateService.updateFirmware(THING2_UID, FW113_EN.getVersion(), null);
final FirmwareStatusInfo upToDateInfo2 = createUpToDateInfo(thing2.getUID());
waitForAssert(() -> {
assertThat(thing2.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V113));
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING2_UID), is(upToDateInfo2));
});
}
Aggregations