Search in sources :

Example 1 with ThingTypeMigrationService

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()))));
}
Also used : ThingTypeMigrationService(org.eclipse.smarthome.core.thing.ThingTypeMigrationService) ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) ThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory) Thing(org.eclipse.smarthome.core.thing.Thing) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 2 with ThingTypeMigrationService

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());
}
Also used : ThingTypeMigrationService(org.eclipse.smarthome.core.thing.ThingTypeMigrationService) ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) ThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory) Thing(org.eclipse.smarthome.core.thing.Thing) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Aggregations

Thing (org.eclipse.smarthome.core.thing.Thing)2 ThingTypeMigrationService (org.eclipse.smarthome.core.thing.ThingTypeMigrationService)2 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)2 ThingHandler (org.eclipse.smarthome.core.thing.binding.ThingHandler)2 ThingHandlerFactory (org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory)2 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)2 Test (org.junit.Test)2