use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class FirmwareUpdateServiceTest method firmwareStatusPropagatedRegularly.
@Test
public void firmwareStatusPropagatedRegularly() throws Exception {
assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V111));
assertThat(thing2.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V112));
updateConfig(1, 0, TimeUnit.SECONDS);
waitForAssert(() -> {
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(mockPublisher, times(3)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw112);
assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), upToDateInfo);
assertFirmwareStatusInfoEvent(THING3_UID, eventCaptor.getAllValues().get(2), unknownInfo);
});
mockPublisher = mock(EventPublisher.class);
firmwareUpdateService.setEventPublisher(mockPublisher);
FirmwareProvider firmwareProvider2 = mock(FirmwareProvider.class);
when(firmwareProvider2.getFirmware(eq(FWALPHA_EN.getUID()), any(Locale.class))).thenReturn(null);
when(firmwareProvider2.getFirmwares(any(ThingTypeUID.class), any(Locale.class))).thenAnswer(invocation -> {
ThingTypeUID thingTypeUID = (ThingTypeUID) invocation.getArguments()[0];
if (THING_TYPE_UID_WITHOUT_FW.equals(thingTypeUID) || THING_TYPE_UID2.equals(thingTypeUID)) {
return Collections.emptySet();
} else {
return Collections.singleton(FW113_EN);
}
});
firmwareRegistry.addFirmwareProvider(firmwareProvider2);
waitForAssert(() -> {
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(mockPublisher, times(2)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw113);
assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), updateExecutableInfoFw113);
});
mockPublisher = mock(EventPublisher.class);
firmwareUpdateService.setEventPublisher(mockPublisher);
firmwareRegistry.removeFirmwareProvider(firmwareProvider2);
waitForAssert(() -> {
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(mockPublisher, times(2)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw112);
assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), upToDateInfo);
});
}
use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class FirmwareUpdateServiceTest method testBackgroundTransfer.
@Test
public void testBackgroundTransfer() throws Exception {
Map<String, String> props = new HashMap<>();
props.put(Thing.PROPERTY_FIRMWARE_VERSION, V111);
Thing thing4 = ThingBuilder.create(THING_TYPE_UID3, THING4_ID).withProperties(props).build();
FirmwareUpdateBackgroundTransferHandler handler4 = mock(FirmwareUpdateBackgroundTransferHandler.class);
when(handler4.getThing()).thenReturn(thing4);
doAnswer(invocation -> {
return updateExecutable.get();
}).when(handler4).isUpdateExecutable();
doAnswer(invocation -> {
Firmware firmware = (Firmware) invocation.getArguments()[0];
thing4.setProperty(Thing.PROPERTY_FIRMWARE_VERSION, firmware.getVersion());
updateExecutable.set(false);
return null;
}).when(handler4).updateFirmware(any(Firmware.class), any(ProgressCallback.class));
firmwareUpdateService.addFirmwareUpdateHandler(handler4);
doAnswer(invocation -> {
try {
Thread.sleep(25);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
updateExecutable.set(true);
return null;
}).when(handler4).transferFirmware(any(Firmware.class));
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING4_UID), is(unknownInfo));
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(mockPublisher, times(1)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING4_UID, eventCaptor.getAllValues().get(eventCaptor.getAllValues().size() - 1), unknownInfo);
FirmwareProvider firmwareProvider2 = mock(FirmwareProvider.class);
when(firmwareProvider2.getFirmware(eq(FW120_EN.getUID()), any(Locale.class))).thenReturn(FW120_EN);
when(firmwareProvider2.getFirmwares(any(ThingTypeUID.class), any(Locale.class))).thenAnswer(invocation -> {
ThingTypeUID thingTypeUID = (ThingTypeUID) invocation.getArguments()[0];
if (THING_TYPE_UID3.equals(thingTypeUID)) {
return Collections.singleton(FW120_EN);
} else {
return Collections.emptySet();
}
});
firmwareRegistry.addFirmwareProvider(firmwareProvider2);
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING4_UID), is(updateAvailableInfo));
verify(mockPublisher, times(2)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING4_UID, eventCaptor.getAllValues().get(eventCaptor.getAllValues().size() - 1), updateAvailableInfo);
waitForAssert(() -> {
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING4_UID), is(updateExecutableInfoFw120));
verify(mockPublisher, times(3)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING4_UID, eventCaptor.getAllValues().get(eventCaptor.getAllValues().size() - 1), updateExecutableInfoFw120);
});
firmwareUpdateService.updateFirmware(THING4_UID, FW120_EN.getUID(), null);
waitForAssert(() -> {
assertThat(thing4.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V120));
});
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING4_UID), is(upToDateInfo));
verify(mockPublisher, times(4)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING4_UID, eventCaptor.getAllValues().get(eventCaptor.getAllValues().size() - 1), upToDateInfo);
assertThat(handler4.isUpdateExecutable(), is(false));
}
use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class ThingManagerOSGiJavaTest method testCreateChannelBuilder.
@Test
public void testCreateChannelBuilder() throws Exception {
registerThingTypeProvider();
registerChannelTypeProvider();
AtomicReference<ThingHandlerCallback> thc = new AtomicReference<>();
ThingHandlerFactory thingHandlerFactory = new BaseThingHandlerFactory() {
@Override
public boolean supportsThingType(@NonNull ThingTypeUID thingTypeUID) {
return true;
}
@Override
@Nullable
protected ThingHandler createHandler(@NonNull Thing thing) {
ThingHandler mockHandler = mock(ThingHandler.class);
doAnswer(a -> {
thc.set((ThingHandlerCallback) a.getArguments()[0]);
return null;
}).when(mockHandler).setCallback(any(ThingHandlerCallback.class));
when(mockHandler.getThing()).thenReturn(THING);
return mockHandler;
}
};
registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
new Thread((Runnable) () -> managedThingProvider.add(THING)).start();
waitForAssert(() -> {
assertNotNull(thc.get());
});
ChannelBuilder channelBuilder = thc.get().createChannelBuilder(new ChannelUID(THING_UID, "test"), CHANNEL_TYPE_UID);
Channel channel = channelBuilder.build();
assertThat(channel.getLabel(), is("Test Label"));
assertThat(channel.getDescription(), is("Test Description"));
assertThat(channel.getAcceptedItemType(), is("Switch"));
assertThat(channel.getDefaultTags().size(), is(1));
assertThat(channel.getDefaultTags().iterator().next(), is("Test Tag"));
}
use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class FirmwareTest method testNotModelRestrictedFirmwareIsSuitableForThingWithSameThingType.
@Test
public void testNotModelRestrictedFirmwareIsSuitableForThingWithSameThingType() {
Firmware firmware = new Firmware.Builder(new FirmwareUID(new ThingTypeUID("binding:thingTypeA"), "version")).build();
Thing thing = ThingBuilder.create(new ThingTypeUID("binding:thingTypeA"), "thing").build();
assertThat(firmware.isSuitableFor(thing), is(true));
}
use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class FirmwareUpdateServiceTest method testPrerequisiteVersionCheck.
@Test
public void testPrerequisiteVersionCheck() {
FirmwareProvider firmwareProvider2 = mock(FirmwareProvider.class);
when(firmwareProvider2.getFirmware(any(FirmwareUID.class), any(Locale.class))).thenAnswer(invocation -> {
FirmwareUID firmwareUID = (FirmwareUID) invocation.getArguments()[0];
if (FW111_FIX_EN.getUID().equals(firmwareUID)) {
return FW111_FIX_EN;
} else if (FW113_EN.getUID().equals(firmwareUID)) {
return FW113_EN;
} else {
return null;
}
});
when(firmwareProvider2.getFirmwares(any(ThingTypeUID.class), any(Locale.class))).thenAnswer(invocation -> {
ThingTypeUID thingTypeUID = (ThingTypeUID) invocation.getArguments()[0];
if (THING_TYPE_UID_WITHOUT_FW.equals(thingTypeUID) || THING_TYPE_UID2.equals(thingTypeUID)) {
return Collections.emptySet();
} else {
return Stream.of(FW111_FIX_EN, FW113_EN).collect(Collectors.toSet());
}
});
firmwareRegistry.addFirmwareProvider(firmwareProvider2);
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw113));
firmwareUpdateService.updateFirmware(THING1_UID, FW111_FIX_EN.getUID(), 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.getUID(), null);
waitForAssert(() -> {
assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V113));
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(upToDateInfo));
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING2_UID), is(updateExecutableInfoFw113));
});
firmwareUpdateService.updateFirmware(THING2_UID, FW113_EN.getUID(), null);
waitForAssert(() -> {
assertThat(thing2.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V113));
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING2_UID), is(upToDateInfo));
});
}
Aggregations