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\">"));
}
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."));
}
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;
}
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()));
}
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);
}
Aggregations