org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory Java Examples

The following examples show how to use org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private void registerHandler(Thing thing, ThingHandlerFactory thingHandlerFactory) {
    Lock lock = getLockForThing(thing.getUID());
    try {
        lock.lock();
        if (!isHandlerRegistered(thing)) {
            if (!hasBridge(thing)) {
                doRegisterHandler(thing, thingHandlerFactory);
            } else {
                Bridge bridge = getBridge(thing.getBridgeUID());
                if (bridge != null && ThingHandlerHelper.isHandlerInitialized(bridge)) {
                    doRegisterHandler(thing, thingHandlerFactory);
                } else {
                    setThingStatus(thing,
                            buildStatusInfo(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED));
                }
            }
        } else {
            logger.debug("Attempt to register a handler twice for thing {} at the same time will be ignored.",
                    thing.getUID());
        }
    } finally {
        lock.unlock();
    }
}
 
Example #2
Source File: ThingManagerOSGiTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example #3
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private void registerAndInitializeHandler(final Thing thing, final ThingHandlerFactory thingHandlerFactory) {
    if (thingHandlerFactory != null) {
        String bsn = getBundleName(thingHandlerFactory);
        if (loadedXmlThingTypes.contains(bsn)) {
            registerHandler(thing, thingHandlerFactory);
            initializeHandler(thing);
        } else {
            logger.debug(
                    "Not registering a handler at this point. The thing types of bundle {} are not fully loaded yet.",
                    bsn);
        }
    } else {
        logger.debug("Not registering a handler at this point. No handler factory for thing '{}' found.",
                thing.getUID());
    }
}
 
Example #4
Source File: ThingManagerTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testThingHandlerFactoryLifecycle() {
    ThingHandlerFactory mockFactory1 = mock(ThingHandlerFactory.class);
    ThingHandlerFactory mockFactory2 = mock(ThingHandlerFactory.class);

    ThingManagerImpl thingManager = new ThingManagerImpl();
    thingManager.setBundleResolver(mockBundleResolver);
    thingManager.setThingRegistry(thingRegistry);
    thingManager.setReadyService(mockReadyService);
    thingManager.thingAdded(mockThing, null);

    // ensure usage is delayed until activation
    thingManager.addThingHandlerFactory(mockFactory1);
    verify(mockFactory1, times(0)).supportsThingType(any());
    thingManager.activate(mockComponentContext);
    verify(mockFactory1, atLeastOnce()).supportsThingType(any());

    // ensure it is directly used
    thingManager.addThingHandlerFactory(mockFactory2);
    verify(mockFactory2, atLeastOnce()).supportsThingType(any());
}
 
Example #5
Source File: ThingManagerOSGiTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void thingManagerCallsUnregisterHandlerForRemovedThing() {
    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);
    managedThingProvider.remove(thing.getUID());

    waitForAssert(() -> verify(thingHandlerFactory, times(1)).removeThing(thing.getUID()));
    waitForAssert(() -> verify(thingHandlerFactory, times(1)).unregisterHandler(thing));
}
 
Example #6
Source File: ThingManagerOSGiTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void thingManagerHandlesThingStatusUpdateUninitializedWithAnExceptionCorrectly() {
    String exceptionMessage = "Some runtime exception occurred!";

    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))).thenThrow(new RuntimeException(exceptionMessage));

    registerService(thingHandlerFactory);

    managedThingProvider.add(thing);

    ThingStatusInfo statusInfo = ThingStatusInfoBuilder
            .create(ThingStatus.UNINITIALIZED, ThingStatusDetail.HANDLER_REGISTERING_ERROR)
            .withDescription(exceptionMessage).build();
    assertThat(thing.getStatusInfo(), is(statusInfo));
}
 
Example #7
Source File: DynamicThingUpdateOSGITest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private ThingHandlerFactory createThingHandlerFactory() {
    ThingHandlerFactory thingHandlerFactory = new BaseThingHandlerFactory() {

        @Override
        public boolean supportsThingType(@NonNull ThingTypeUID thingTypeUID) {
            return THING_TYPE_UID.equals(thingTypeUID);
        }

        @Override
        protected @Nullable ThingHandler createHandler(@NonNull Thing thing) {
            thingHandler = createThingHandler(thing);
            return thingHandler;
        }
    };
    return thingHandlerFactory;
}
 
Example #8
Source File: DynamicThingUpdateOSGITest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    registerVolatileStorageService();

    ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
    when(thingTypeProvider.getThingType(eq(THING_TYPE_UID), any())).thenReturn(THING_TYPE);
    registerService(thingTypeProvider);

    inbox = getService(Inbox.class);
    managedThingProvider = getService(ManagedThingProvider.class);

    assertEquals(0, inbox.getAll().size());

    ThingHandlerFactory thingHandlerFactory = createThingHandlerFactory();
    registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
}
 
Example #9
Source File: ThingRegistryImpl.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Thing createThingOfType(ThingTypeUID thingTypeUID, ThingUID thingUID, ThingUID bridgeUID, String label,
        Configuration configuration) {
    logger.debug("Creating thing for type '{}'.", thingTypeUID);
    for (ThingHandlerFactory thingHandlerFactory : thingHandlerFactories) {
        if (thingHandlerFactory.supportsThingType(thingTypeUID)) {
            Thing thing = thingHandlerFactory.createThing(thingTypeUID, configuration, thingUID, bridgeUID);
            if (thing == null) {
                logger.warn(
                        "Cannot create thing of type '{}'. Binding '{}' says it supports it, but it could not be created.",
                        thingTypeUID, thingHandlerFactory.getClass().getName());
            } else {
                thing.setLabel(label);
                return thing;
            }
        }
    }
    logger.warn("Cannot create thing. No binding found that supports creating a thing of type '{}'.", thingTypeUID);
    return null;
}
 
Example #10
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private void doRegisterHandler(final Thing thing, final ThingHandlerFactory thingHandlerFactory) {
    logger.debug("Calling '{}.registerHandler()' for thing '{}'.", thingHandlerFactory.getClass().getSimpleName(),
            thing.getUID());
    try {
        ThingHandler thingHandler = thingHandlerFactory.registerHandler(thing);
        thingHandler.setCallback(ThingManagerImpl.this.thingHandlerCallback);
        thing.setHandler(thingHandler);
        thingHandlers.put(thing.getUID(), thingHandler);
        synchronized (thingHandlersByFactory) {
            thingHandlersByFactory.computeIfAbsent(thingHandlerFactory, unused -> new HashSet<>())
                    .add(thingHandler);
        }
    } catch (Exception ex) {
        ThingStatusInfo statusInfo = buildStatusInfo(ThingStatus.UNINITIALIZED,
                ThingStatusDetail.HANDLER_REGISTERING_ERROR,
                ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage());
        setThingStatus(thing, statusInfo);
        logger.error("Exception occurred while calling thing handler factory '{}': {}", thingHandlerFactory,
                ex.getMessage(), ex);
    }
}
 
Example #11
Source File: GenericThingProviderTest4.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private void prepareThingWithShutDownBundle() {
    updateModel();
    registerThingTypeProvider();
    finishLoading();
    registerService(hueThingHandlerFactory, ThingHandlerFactory.class.getName());
    assertThatAllIsGood();
    unload();
    unregisterService(ThingHandlerFactory.class.getName());

    waitForAssert(() -> {
        assertThat(thingRegistry.getAll().size(), is(1));
        Thing myBridge = thingRegistry.getAll().stream()
                .filter(t -> "Xhue:Xbridge:myBridge".equals(t.getUID().getAsString())).findFirst().get();
        assertThat(myBridge.getStatus(), is(equalTo(ThingStatus.UNINITIALIZED)));
        assertThat(myBridge.getHandler(), is(nullValue()));
    });
    removeReadyMarker();
}
 
Example #12
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void thingRemoved(final Thing thing, ThingTrackerEvent thingTrackerEvent) {
    logger.debug("Thing '{}' is no longer tracked by ThingManager.", thing.getUID());

    ThingHandler thingHandler = thingHandlers.get(thing.getUID());
    if (thingHandler != null) {
        final ThingHandlerFactory thingHandlerFactory = findThingHandlerFactory(thing.getThingTypeUID());
        if (thingHandlerFactory != null) {
            unregisterAndDisposeHandler(thingHandlerFactory, thing, thingHandler);
            if (thingTrackerEvent == ThingTrackerEvent.THING_REMOVED) {
                safeCaller.create(thingHandlerFactory, ThingHandlerFactory.class).build()
                        .removeThing(thing.getUID());
            }
        } else {
            logger.warn("Cannot unregister handler. No handler factory for thing '{}' found.", thing.getUID());
        }
    }

    this.things.remove(thing);
}
 
Example #13
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private void unregisterAndDisposeChildHandlers(Bridge bridge, ThingHandlerFactory thingHandlerFactory) {
    addThingsToBridge(bridge);
    for (Thing child : bridge.getThings()) {
        ThingHandler handler = child.getHandler();
        if (handler != null) {
            logger.debug("Unregister and dispose child '{}' of bridge '{}'.", child.getUID(), bridge.getUID());
            unregisterAndDisposeHandler(thingHandlerFactory, child, handler);
        }
    }
}
 
Example #14
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private void unregisterAndDisposeHandler(ThingHandlerFactory thingHandlerFactory, Thing thing,
        ThingHandler handler) {
    if (isBridge(thing)) {
        unregisterAndDisposeChildHandlers((Bridge) thing, thingHandlerFactory);
    }
    disposeHandler(thing, handler);
    unregisterHandler(thing, thingHandlerFactory);
}
 
Example #15
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Activate
protected synchronized void activate(ComponentContext componentContext) {
    readyService.registerTracker(this, new ReadyMarkerFilter().withType(XML_THING_TYPE));
    for (ThingHandlerFactory factory : thingHandlerFactories) {
        handleThingHandlerFactoryAddition(getBundleName(factory));
    }
    thingRegistry.addThingTracker(this);
    active = true;
}
 
Example #16
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
protected synchronized void addThingHandlerFactory(ThingHandlerFactory thingHandlerFactory) {
    logger.debug("Thing handler factory '{}' added", thingHandlerFactory.getClass().getSimpleName());
    thingHandlerFactories.add(thingHandlerFactory);
    if (active) {
        handleThingHandlerFactoryAddition(getBundleName(thingHandlerFactory));
    }
}
 
Example #17
Source File: GenericThingProviderMultipleBundlesTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setup() {
    thingProvider = new GenericThingProvider();

    Bundle bundle = mock(Bundle.class);
    when(bundle.getSymbolicName()).thenReturn(BUNDLE_NAME);
    BundleResolver bundleResolver = mock(BundleResolver.class);
    when(bundleResolver.resolveBundle(any(Class.class))).thenReturn(bundle);

    thingProvider.setBundleResolver(bundleResolver);

    ModelRepository modelRepository = mock(ModelRepository.class);

    ThingModel thingModel = mock(ThingModel.class);
    EList<ModelThing> dslThings = createModelBridge();
    when(thingModel.getThings()).thenReturn(dslThings);
    when(modelRepository.getModel(TEST_MODEL_THINGS)).thenReturn(thingModel);

    thingProvider.setModelRepository(modelRepository);

    // configure bridgeHandlerFactory to accept the bridge type UID and create a bridge:
    bridgeHandlerFactory = mock(ThingHandlerFactory.class);
    when(bridgeHandlerFactory.supportsThingType(BRIDGE_TYPE_UID)).thenReturn(true);
    when(bridgeHandlerFactory.createThing(eq(BRIDGE_TYPE_UID), any(Configuration.class), eq(BRIDGE_UID), eq(null)))
            .thenReturn(BridgeBuilder.create(BRIDGE_TYPE_UID, BRIDGE_ID).build());
    thingProvider.addThingHandlerFactory(bridgeHandlerFactory);

    // configure thingHandlerFactory to accept the thing type UID and create a thing:
    thingHandlerFactory = mock(ThingHandlerFactory.class);
    when(thingHandlerFactory.supportsThingType(THING_TYPE_UID)).thenReturn(true);
    when(thingHandlerFactory.createThing(eq(THING_TYPE_UID), any(Configuration.class), eq(THING_UID),
            eq(BRIDGE_UID))).thenReturn(ThingBuilder.create(THING_TYPE_UID, THING_ID).build());
    thingProvider.addThingHandlerFactory(thingHandlerFactory);
}
 
Example #18
Source File: ThingStatusInfoI18nLocalizationServiceOSGiTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
    LocaleProvider localeProvider = getService(LocaleProvider.class);
    assertThat(localeProvider, is(notNullValue()));
    defaultLocale = localeProvider.getLocale();

    new DefaultLocaleSetter(getService(ConfigurationAdmin.class)).setDefaultLocale(Locale.ENGLISH);
    waitForAssert(() -> assertThat(localeProvider.getLocale(), is(Locale.ENGLISH)));

    registerVolatileStorageService();

    SimpleThingHandlerFactory simpleThingHandlerFactory = new SimpleThingHandlerFactory();
    ComponentContext componentContext = mock(ComponentContext.class);
    when(componentContext.getBundleContext()).thenReturn(bundleContext);
    simpleThingHandlerFactory.activate(componentContext);
    registerService(simpleThingHandlerFactory, ThingHandlerFactory.class.getName());

    thing = ThingBuilder.create(new ThingTypeUID("aaa:bbb"), "ccc").build();

    managedThingProvider = getService(ManagedThingProvider.class);
    assertThat(managedThingProvider, is(notNullValue()));

    managedThingProvider.add(thing);

    waitForAssert(() -> assertThat(thing.getStatus(), is(ThingStatus.ONLINE)));

    testBundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
    assertThat(testBundle, is(notNullValue()));

    thingStatusInfoI18nLocalizationService = getService(ThingStatusInfoI18nLocalizationService.class);
    assertThat(thingStatusInfoI18nLocalizationService, is(notNullValue()));

    thingStatusInfoI18nLocalizationService.setBundleResolver(new BundleResolverImpl());
}
 
Example #19
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private void unregisterHandler(Thing thing, ThingHandlerFactory thingHandlerFactory) {
    Lock lock = getLockForThing(thing.getUID());
    try {
        lock.lock();
        if (isHandlerRegistered(thing)) {
            doUnregisterHandler(thing, thingHandlerFactory);
        }
    } finally {
        lock.unlock();
    }
}
 
Example #20
Source File: ThingManagerOSGiTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void thingManagerHandlesThingStatusUpdatesUninitializedAndInitializingCorrectly() {
    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);

    final ThingStatusInfo uninitializedNone = ThingStatusInfoBuilder
            .create(ThingStatus.UNINITIALIZED, ThingStatusDetail.NONE).build();
    assertThat(thing.getStatusInfo(), is(uninitializedNone));

    managedThingProvider.add(thing);

    final ThingStatusInfo initializingNone = ThingStatusInfoBuilder
            .create(ThingStatus.INITIALIZING, ThingStatusDetail.NONE).build();
    waitForAssert(() -> assertThat(thing.getStatusInfo(), is(initializingNone)));

    unregisterService(thingHandlerFactory);

    final ThingStatusInfo uninitializedHandlerMissing = ThingStatusInfoBuilder
            .create(ThingStatus.UNINITIALIZED, ThingStatusDetail.HANDLER_MISSING_ERROR).build();
    waitForAssert(() -> assertThat(thing.getStatusInfo(), is(uninitializedHandlerMissing)));
}
 
Example #21
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private ThingHandlerFactory findThingHandlerFactory(ThingTypeUID thingTypeUID) {
    for (ThingHandlerFactory factory : thingHandlerFactories) {
        if (factory.supportsThingType(thingTypeUID)) {
            return factory;
        }
    }
    return null;
}
 
Example #22
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private ThingHandlerFactory getThingHandlerFactory(Thing thing) {
    ThingHandlerFactory thingHandlerFactory = findThingHandlerFactory(thing.getThingTypeUID());
    if (thingHandlerFactory != null) {
        return thingHandlerFactory;
    }
    logger.debug("Not registering a handler at this point since no handler factory for thing '{}' found.",
            thing.getUID());
    return null;
}
 
Example #23
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private void handleThingHandlerFactoryRemoval(ThingHandlerFactory thingHandlerFactory) {
    final Set<ThingHandler> handlers;
    synchronized (thingHandlersByFactory) {
        handlers = thingHandlersByFactory.remove(thingHandlerFactory);
    }
    if (handlers != null) {
        for (ThingHandler thingHandler : handlers) {
            final Thing thing = thingHandler.getThing();
            if (isHandlerRegistered(thing)) {
                unregisterAndDisposeHandler(thingHandlerFactory, thing, thingHandler);
            }
        }
    }
}
 
Example #24
Source File: GenericThingProviderTest4.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithUpdateFactoryLoaded() {
    assertThat(thingRegistry.getAll().size(), is(0));
    updateModel();
    assertThat(thingRegistry.getAll().size(), is(0));
    registerService(hueThingHandlerFactory, ThingHandlerFactory.class.getName());
    assertThat(thingRegistry.getAll().size(), is(0));
    registerThingTypeProvider();
    finishLoading();
    assertThatAllIsGood();
}
 
Example #25
Source File: GenericThingProviderTest4.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithFactoryUpdateLoaded() {
    assertThat(thingRegistry.getAll().size(), is(0));
    registerService(hueThingHandlerFactory, ThingHandlerFactory.class.getName());
    assertThat(thingRegistry.getAll().size(), is(0));
    updateModel();
    assertThat(thingRegistry.getAll().size(), is(0));
    registerThingTypeProvider();
    finishLoading();
    assertThatAllIsGood();
}
 
Example #26
Source File: GenericThingProviderTest4.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithLoadedFactoryUpdate() {
    assertThat(thingRegistry.getAll().size(), is(0));
    registerThingTypeProvider();
    finishLoading();
    assertThat(thingRegistry.getAll().size(), is(0));
    registerService(hueThingHandlerFactory, ThingHandlerFactory.class.getName());
    assertThat(thingRegistry.getAll().size(), is(0));
    updateModel();
    assertThatAllIsGood();
}
 
Example #27
Source File: GenericThingProviderTest4.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithLoadedUpdateFactory() {
    assertThat(thingRegistry.getAll().size(), is(0));
    registerThingTypeProvider();
    finishLoading();
    assertThat(thingRegistry.getAll().size(), is(0));
    updateModel();
    assertThat(thingRegistry.getAll().size(), is(0));
    registerService(hueThingHandlerFactory, ThingHandlerFactory.class.getName());
    assertThatAllIsGood();
}
 
Example #28
Source File: GenericThingProviderTest4.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithFactoryLoadedUpdate() {
    assertThat(thingRegistry.getAll().size(), is(0));
    registerService(hueThingHandlerFactory, ThingHandlerFactory.class.getName());
    assertThat(thingRegistry.getAll().size(), is(0));
    registerThingTypeProvider();
    finishLoading();
    assertThat(thingRegistry.getAll().size(), is(0));
    updateModel();
    assertThatAllIsGood();
}
 
Example #29
Source File: GenericThingProviderTest4.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithUpdateLoadedFactory() {
    assertThat(thingRegistry.getAll().size(), is(0));
    updateModel();
    assertThat(thingRegistry.getAll().size(), is(0));
    registerThingTypeProvider();
    finishLoading();
    assertThat(thingRegistry.getAll().size(), is(0));
    registerService(hueThingHandlerFactory, ThingHandlerFactory.class.getName());
    assertThatAllIsGood();
}
 
Example #30
Source File: GenericThingProviderTest4.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("null")
public void assertThatThingHandlersAreManagedCorrectlyOnUpdateWithFactoryLoaded() {
    prepareThingWithShutDownBundle();

    bridgeInitializeCounter = 0;
    registerService(hueThingHandlerFactory, ThingHandlerFactory.class.getName());
    registerThingTypeProvider();
    assertThat(thingRegistry.get(new ThingUID("Xhue:Xbridge:myBridge")).getHandler(), is(nullValue()));
    finishLoading();
    waitForAssert(() -> assertThat(bridgeInitializeCounter >= 1, is(true)));
    assertThatAllIsGood();
}