Search in sources :

Example 16 with ThingRegistry

use of org.openhab.core.thing.ThingRegistry in project openhab-addons by openhab.

the class AccountOverviewServletTest method whenAccountOverviewServletIsCalledAndBridgesArePresentThenThePageDisplaysInformationAboutThem.

@Test
public void whenAccountOverviewServletIsCalledAndBridgesArePresentThenThePageDisplaysInformationAboutThem() throws Exception {
    // given:
    Configuration configuration1 = mock(Configuration.class);
    when(configuration1.get(MieleCloudBindingConstants.CONFIG_PARAM_LOCALE)).thenReturn("de");
    when(configuration1.get(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL)).thenReturn("openhab@openhab.org");
    Bridge bridge1 = mock(Bridge.class);
    when(bridge1.getThingTypeUID()).thenReturn(MieleCloudBindingConstants.THING_TYPE_BRIDGE);
    when(bridge1.getUID()).thenReturn(MieleCloudBindingIntegrationTestConstants.BRIDGE_THING_UID);
    when(bridge1.getStatus()).thenReturn(ThingStatus.ONLINE);
    when(bridge1.getStatusInfo()).thenReturn(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
    when(bridge1.getConfiguration()).thenReturn(configuration1);
    Configuration configuration2 = mock(Configuration.class);
    when(configuration2.get(MieleCloudBindingConstants.CONFIG_PARAM_LOCALE)).thenReturn("en");
    when(configuration2.get(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL)).thenReturn("everyone@openhab.org");
    Bridge bridge2 = mock(Bridge.class);
    when(bridge2.getThingTypeUID()).thenReturn(MieleCloudBindingConstants.THING_TYPE_BRIDGE);
    when(bridge2.getUID()).thenReturn(new ThingUID(MieleCloudBindingConstants.THING_TYPE_BRIDGE, "test"));
    when(bridge2.getStatus()).thenReturn(ThingStatus.OFFLINE);
    when(bridge2.getStatusInfo()).thenReturn(new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Error message"));
    when(bridge2.getConfiguration()).thenReturn(configuration2);
    ThingRegistry thingRegistry = mock(ThingRegistry.class);
    when(thingRegistry.stream()).thenAnswer(invocation -> Stream.of(bridge1, bridge2));
    ReflectionUtil.setPrivate(getAccountOverviewServlet(), "thingRegistry", thingRegistry);
    // when:
    Website accountOverviewSite = getCrawler().doGetRelative("/mielecloud");
    // then:
    assertTrue(accountOverviewSite.contains("The following bridges are paired"));
    assertTrue(accountOverviewSite.contains("openhab@openhab.org"));
    assertTrue(accountOverviewSite.contains("mielecloud:account:genesis"));
    assertTrue(accountOverviewSite.contains("<span class=\"status online\">"));
    assertTrue(accountOverviewSite.contains("everyone@openhab.org"));
    assertTrue(accountOverviewSite.contains("mielecloud:account:test"));
    assertTrue(accountOverviewSite.contains("<span class=\"status offline\">"));
}
Also used : Configuration(org.openhab.core.config.core.Configuration) ThingUID(org.openhab.core.thing.ThingUID) Website(org.openhab.binding.mielecloud.internal.util.Website) ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) Bridge(org.openhab.core.thing.Bridge) ThingRegistry(org.openhab.core.thing.ThingRegistry) AbstractConfigFlowTest(org.openhab.binding.mielecloud.internal.util.AbstractConfigFlowTest) Test(org.junit.jupiter.api.Test)

Example 17 with ThingRegistry

use of org.openhab.core.thing.ThingRegistry in project openhab-addons by openhab.

the class CreateBridgeServletTest method whenBridgeReconfigurationFailsDueToMissingBridgeThenAWarningIsShownOnTheSuccessPage.

@Test
public void whenBridgeReconfigurationFailsDueToMissingBridgeThenAWarningIsShownOnTheSuccessPage() throws Exception {
    // given:
    MieleCloudConfigService configService = getService(MieleCloudConfigService.class);
    assertNotNull(configService);
    CreateBridgeServlet createBridgeServlet = configService.getCreateBridgeServlet();
    assertNotNull(createBridgeServlet);
    Inbox inbox = mock(Inbox.class);
    when(inbox.add(any())).thenReturn(false);
    setPrivate(Objects.requireNonNull(createBridgeServlet), "inbox", inbox);
    ThingRegistry thingRegistry = mock(ThingRegistry.class);
    when(thingRegistry.get(any())).thenReturn(null);
    setPrivate(Objects.requireNonNull(createBridgeServlet), "thingRegistry", thingRegistry);
    // when:
    Website website = getCrawler().doGetRelative("/mielecloud/createBridgeThing?" + CreateBridgeServlet.BRIDGE_UID_PARAMETER_NAME + "=" + MieleCloudBindingIntegrationTestConstants.BRIDGE_THING_UID.getAsString() + "&" + CreateBridgeServlet.EMAIL_PARAMETER_NAME + "=" + MieleCloudBindingIntegrationTestConstants.EMAIL);
    // then:
    assertTrue(website.contains("Pairing successful!"));
    assertTrue(website.contains("Could not auto reconfigure the bridge. Bridge thing or thing handler is not available. Please try the configuration flow again."));
}
Also used : Website(org.openhab.binding.mielecloud.internal.util.Website) MieleCloudConfigService(org.openhab.binding.mielecloud.internal.config.MieleCloudConfigService) Inbox(org.openhab.core.config.discovery.inbox.Inbox) ThingRegistry(org.openhab.core.thing.ThingRegistry) AbstractConfigFlowTest(org.openhab.binding.mielecloud.internal.util.AbstractConfigFlowTest) Test(org.junit.jupiter.api.Test)

Example 18 with ThingRegistry

use of org.openhab.core.thing.ThingRegistry in project openhab-addons by openhab.

the class AbstractMieleThingHandlerTest method createThingHandler.

protected AbstractMieleThingHandler createThingHandler(ThingTypeUID thingTypeUid, ThingUID thingUid, Class<? extends AbstractMieleThingHandler> expectedHandlerClass, String deviceIdentifier) {
    ThingRegistry registry = getThingRegistry();
    List<Channel> channels = createChannelsForThingHandler(thingTypeUid, thingUid);
    Thing thing = ThingBuilder.create(thingTypeUid, thingUid).withConfiguration(new Configuration(Collections.singletonMap(MieleCloudBindingConstants.CONFIG_PARAM_DEVICE_IDENTIFIER, deviceIdentifier))).withBridge(getBridge().getUID()).withChannels(channels).withLabel("DA-6996").build();
    assertNotNull(thing);
    registry.add(thing);
    waitForAssert(() -> {
        ThingHandler handler = thing.getHandler();
        assertNotNull(handler);
        assertTrue(expectedHandlerClass.isAssignableFrom(handler.getClass()), "Handler type is wrong");
    });
    createItemsForChannels(thing);
    linkChannelsToItems(thing);
    ThingHandler handler = thing.getHandler();
    assertNotNull(handler);
    AbstractMieleThingHandler mieleThingHandler = (AbstractMieleThingHandler) Objects.requireNonNull(handler);
    waitForAssert(() -> {
        try {
            assertNotNull(ReflectionUtil.invokePrivate(mieleThingHandler, "getBridge"));
        } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException e) {
            throw new RuntimeException(e);
        }
        assertNotNull(getBridge().getThing(thingUid));
    });
    return mieleThingHandler;
}
Also used : Configuration(org.openhab.core.config.core.Configuration) Channel(org.openhab.core.thing.Channel) ThingHandler(org.openhab.core.thing.binding.ThingHandler) ThingRegistry(org.openhab.core.thing.ThingRegistry) Thing(org.openhab.core.thing.Thing)

Example 19 with ThingRegistry

use of org.openhab.core.thing.ThingRegistry in project openhab-addons by openhab.

the class HueDeviceDiscoveryServiceOSGiTest method setUp.

@BeforeEach
public void setUp() {
    registerVolatileStorageService();
    thingRegistry = getService(ThingRegistry.class, ThingRegistry.class);
    assertThat(thingRegistry, is(notNullValue()));
    Configuration configuration = new Configuration();
    configuration.put(HOST, "1.2.3.4");
    configuration.put(USER_NAME, "testUserName");
    configuration.put(PROPERTY_SERIAL_NUMBER, "testSerialNumber");
    hueBridge = (Bridge) thingRegistry.createThingOfType(BRIDGE_THING_TYPE_UID, BRIDGE_THING_UID, null, "Bridge", configuration);
    assertThat(hueBridge, is(notNullValue()));
    thingRegistry.add(hueBridge);
    hueBridgeHandler = getThingHandler(hueBridge, HueBridgeHandler.class);
    assertThat(hueBridgeHandler, is(notNullValue()));
    discoveryService = getService(DiscoveryService.class, HueDeviceDiscoveryService.class);
    assertThat(discoveryService, is(notNullValue()));
}
Also used : Configuration(org.openhab.core.config.core.Configuration) HueBridgeHandler(org.openhab.binding.hue.internal.handler.HueBridgeHandler) HueDeviceDiscoveryService(org.openhab.binding.hue.internal.discovery.HueDeviceDiscoveryService) DiscoveryService(org.openhab.core.config.discovery.DiscoveryService) HueDeviceDiscoveryService(org.openhab.binding.hue.internal.discovery.HueDeviceDiscoveryService) ThingRegistry(org.openhab.core.thing.ThingRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 20 with ThingRegistry

use of org.openhab.core.thing.ThingRegistry in project openhab-addons by openhab.

the class NtpOSGiTest method setUp.

@BeforeEach
public void setUp() {
    VolatileStorageService volatileStorageService = new VolatileStorageService();
    registerService(volatileStorageService);
    managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
    assertNotNull(managedThingProvider);
    thingRegistry = getService(ThingRegistry.class);
    assertNotNull(thingRegistry);
    itemRegistry = getService(ItemRegistry.class);
    assertNotNull(itemRegistry);
    channelTypeUID = new ChannelTypeUID(NtpBindingConstants.BINDING_ID + ":channelType");
    channelTypeProvider = mock(ChannelTypeProvider.class);
    when(channelTypeProvider.getChannelType(any(ChannelTypeUID.class), any(Locale.class))).thenReturn(ChannelTypeBuilder.state(channelTypeUID, "label", CoreItemFactory.SWITCH).build());
    registerService(channelTypeProvider);
}
Also used : Locale(java.util.Locale) ThingProvider(org.openhab.core.thing.ThingProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ChannelTypeProvider(org.openhab.core.thing.type.ChannelTypeProvider) VolatileStorageService(org.openhab.core.test.storage.VolatileStorageService) ItemRegistry(org.openhab.core.items.ItemRegistry) ThingRegistry(org.openhab.core.thing.ThingRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ThingRegistry (org.openhab.core.thing.ThingRegistry)29 Thing (org.openhab.core.thing.Thing)18 Test (org.junit.jupiter.api.Test)17 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)14 ThingUID (org.openhab.core.thing.ThingUID)13 ManagedThingProvider (org.openhab.core.thing.ManagedThingProvider)11 Configuration (org.openhab.core.config.core.Configuration)9 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)9 BeforeEach (org.junit.jupiter.api.BeforeEach)8 ThingHandler (org.openhab.core.thing.binding.ThingHandler)7 Nullable (org.eclipse.jdt.annotation.Nullable)6 ThingHandlerFactory (org.openhab.core.thing.binding.ThingHandlerFactory)6 Bridge (org.openhab.core.thing.Bridge)5 ThingProvider (org.openhab.core.thing.ThingProvider)5 ItemChannelLink (org.openhab.core.thing.link.ItemChannelLink)5 Item (org.openhab.core.items.Item)4 NumberItem (org.openhab.core.library.items.NumberItem)4 VolatileStorageService (org.openhab.core.test.storage.VolatileStorageService)4 Locale (java.util.Locale)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3