Search in sources :

Example 6 with ThingRegistry

use of org.eclipse.smarthome.core.thing.ThingRegistry in project smarthome by eclipse.

the class ThingRegistryOSGiTest method assertThatCreateThingDelegatesToRegisteredThingHandlerFactory.

@Test
public void assertThatCreateThingDelegatesToRegisteredThingHandlerFactory() {
    ThingTypeUID expectedThingTypeUID = THING_TYPE_UID;
    ThingUID expectedThingUID = new ThingUID(THING_TYPE_UID, THING1_ID);
    Configuration expectedConfiguration = new Configuration();
    ThingUID expectedBridgeUID = new ThingUID(THING_TYPE_UID, THING2_ID);
    String expectedLabel = "Test Thing";
    AsyncResultWrapper<Thing> thingResultWrapper = new AsyncResultWrapper<Thing>();
    ThingRegistry thingRegistry = getService(ThingRegistry.class);
    ThingHandlerFactory thingHandlerFactory = new BaseThingHandlerFactory() {

        @Override
        public boolean supportsThingType(@NonNull ThingTypeUID thingTypeUID) {
            return true;
        }

        @Override
        @Nullable
        protected ThingHandler createHandler(@NonNull Thing thing) {
            return null;
        }

        @Override
        @Nullable
        public Thing createThing(@NonNull ThingTypeUID thingTypeUID, @NonNull Configuration configuration, @Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) {
            assertThat(thingTypeUID, is(expectedThingTypeUID));
            assertThat(configuration, is(expectedConfiguration));
            assertThat(thingUID, is(expectedThingUID));
            assertThat(bridgeUID, is(expectedBridgeUID));
            Thing thing = ThingBuilder.create(thingTypeUID, thingUID.getId()).withBridge(bridgeUID).build();
            thingResultWrapper.set(thing);
            return thing;
        }
    };
    registerThingHandlerFactory(thingHandlerFactory);
    Thing thing = thingRegistry.createThingOfType(expectedThingTypeUID, expectedThingUID, expectedBridgeUID, expectedLabel, expectedConfiguration);
    waitForAssert(() -> {
        assertTrue(thingResultWrapper.isSet());
    });
    assertThat(thing, is(thingResultWrapper.getWrappedObject()));
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) BaseThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory) AsyncResultWrapper(org.eclipse.smarthome.test.AsyncResultWrapper) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) NonNull(org.eclipse.jdt.annotation.NonNull) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) BaseThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory) ThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory) Thing(org.eclipse.smarthome.core.thing.Thing) Nullable(org.eclipse.jdt.annotation.Nullable) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 7 with ThingRegistry

use of org.eclipse.smarthome.core.thing.ThingRegistry in project smarthome by eclipse.

the class ThingRegistryOSGiTest method assertThatThingRegistryThrowsExceptionForConfigUpdateOfNonExistingThing.

@Test(expected = IllegalArgumentException.class)
public void assertThatThingRegistryThrowsExceptionForConfigUpdateOfNonExistingThing() {
    ThingRegistry thingRegistry = getService(ThingRegistry.class);
    ThingUID thingUID = new ThingUID(THING_TYPE_UID, "binding:type:thing");
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("param", "value1");
    thingRegistry.updateConfiguration(thingUID, parameters);
}
Also used : HashMap(java.util.HashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 8 with ThingRegistry

use of org.eclipse.smarthome.core.thing.ThingRegistry in project smarthome by eclipse.

the class DiscoveryServiceRegistryOSGiTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    registerVolatileStorageService();
    thingRegistry = getService(ThingRegistry.class);
    assertNotNull(thingRegistry);
    inbox = getService(Inbox.class);
    assertNotNull(inbox);
    discoveryServiceMockForBinding1 = new DiscoveryServiceMock(new ThingTypeUID(ANY_BINDING_ID_1, ANY_THING_TYPE_1), 1);
    discoveryServiceMockForBinding2 = new ExtendedDiscoveryServiceMock(new ThingTypeUID(ANY_BINDING_ID_2, ANY_THING_TYPE_2), 3);
    discoveryServiceMockForBinding3Bridge1 = new DiscoveryServiceMockOfBridge(new ThingTypeUID(ANY_BINDING_ID_3, ANY_THING_TYPE_3), 1, BRIDGE_UID_1);
    discoveryServiceMockForBinding3Bridge2 = new DiscoveryServiceMockOfBridge(new ThingTypeUID(ANY_BINDING_ID_3, ANY_THING_TYPE_3), 1, BRIDGE_UID_2);
    discoveryServiceFaultyMock = new DiscoveryServiceMock(new ThingTypeUID(FAULTY_BINDING_ID, FAULTY_THING_TYPE), 1, true);
    extendedDiscoveryServiceMock = new ExtendedDiscoveryServiceMock(new ThingTypeUID(EXTENDED_BINDING_ID, EXTENDED_THING_TYPE), 1, true);
    serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), discoveryServiceMockForBinding1, null));
    serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), discoveryServiceMockForBinding2, null));
    serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), discoveryServiceMockForBinding3Bridge1, null));
    serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), discoveryServiceMockForBinding3Bridge2, null));
    serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), discoveryServiceFaultyMock, null));
    serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), extendedDiscoveryServiceMock, null));
    discoveryServiceRegistry = getService(DiscoveryServiceRegistry.class);
}
Also used : ExtendedDiscoveryServiceMock(org.eclipse.smarthome.config.setup.test.discovery.ExtendedDiscoveryServiceMock) DiscoveryServiceMockOfBridge(org.eclipse.smarthome.config.setup.test.discovery.DiscoveryServiceMockOfBridge) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Inbox(org.eclipse.smarthome.config.discovery.inbox.Inbox) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) ExtendedDiscoveryServiceMock(org.eclipse.smarthome.config.setup.test.discovery.ExtendedDiscoveryServiceMock) DiscoveryServiceMock(org.eclipse.smarthome.config.setup.test.discovery.DiscoveryServiceMock) Before(org.junit.Before)

Aggregations

ThingRegistry (org.eclipse.smarthome.core.thing.ThingRegistry)8 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)4 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)4 Test (org.junit.Test)4 Configuration (org.eclipse.smarthome.config.core.Configuration)3 ManagedThingProvider (org.eclipse.smarthome.core.thing.ManagedThingProvider)3 Thing (org.eclipse.smarthome.core.thing.Thing)3 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)3 Before (org.junit.Before)3 HashMap (java.util.HashMap)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 ThingProvider (org.eclipse.smarthome.core.thing.ThingProvider)2 Locale (java.util.Locale)1 Map (java.util.Map)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 HueBridgeHandler (org.eclipse.smarthome.binding.hue.handler.HueBridgeHandler)1 HueLightDiscoveryService (org.eclipse.smarthome.binding.hue.internal.discovery.HueLightDiscoveryService)1 ConfigDescriptionValidator (org.eclipse.smarthome.config.core.validation.ConfigDescriptionValidator)1 DiscoveryService (org.eclipse.smarthome.config.discovery.DiscoveryService)1 Inbox (org.eclipse.smarthome.config.discovery.inbox.Inbox)1