use of org.eclipse.smarthome.core.thing.ThingTypeMigrationService in project smarthome by eclipse.
the class ThingManagerOSGiTest method thingManagerChangesTheThingType.
@Test
@SuppressWarnings("null")
public void thingManagerChangesTheThingType() {
registerThingTypeProvider();
ThingHandler thingHandler = mock(ThingHandler.class);
when(thingHandler.getThing()).thenReturn(thing);
ThingHandlerFactory thingHandlerFactory = mock(ThingHandlerFactory.class);
when(thingHandlerFactory.supportsThingType(any(ThingTypeUID.class))).thenReturn(true);
when(thingHandlerFactory.registerHandler(any(Thing.class))).thenReturn(thingHandler);
registerService(thingHandlerFactory);
managedThingProvider.add(thing);
assertThat(thing.getThingTypeUID().getAsString(), is(equalTo(THING_TYPE_UID.getAsString())));
ThingTypeUID newThingTypeUID = new ThingTypeUID("binding:type2");
ThingTypeMigrationService migrator = getService(ThingTypeMigrationService.class);
assertThat(migrator, is(not(nullValue())));
migrator.migrateThingType(thing, newThingTypeUID, thing.getConfiguration());
waitForAssert(() -> assertThat(thing.getThingTypeUID().getAsString(), is(equalTo(newThingTypeUID.getAsString()))));
}
use of org.eclipse.smarthome.core.thing.ThingTypeMigrationService in project smarthome by eclipse.
the class ThingManagerOSGiTest method thingManagerDoesNotChangeTheThingTypeWhenNewThingTypeIsNotRegistered.
@Test(expected = RuntimeException.class)
@SuppressWarnings("null")
public void thingManagerDoesNotChangeTheThingTypeWhenNewThingTypeIsNotRegistered() {
ThingHandler thingHandler = mock(ThingHandler.class);
when(thingHandler.getThing()).thenReturn(thing);
ThingHandlerFactory thingHandlerFactory = mock(ThingHandlerFactory.class);
when(thingHandlerFactory.supportsThingType(any(ThingTypeUID.class))).thenReturn(true);
when(thingHandlerFactory.registerHandler(any(Thing.class))).thenReturn(thingHandler);
registerService(thingHandlerFactory);
managedThingProvider.add(thing);
assertThat(thing.getThingTypeUID().getAsString(), is(equalTo(THING_TYPE_UID.getAsString())));
ThingTypeUID newThingTypeUID = new ThingTypeUID("binding:type2");
ThingTypeMigrationService migrator = getService(ThingTypeMigrationService.class);
assertThat(migrator, is(not(null)));
migrator.migrateThingType(thing, newThingTypeUID, thing.getConfiguration());
}
Aggregations