use of org.openhab.core.thing.ThingRegistry in project openhab-addons by openhab.
the class MieleHandlerFactoryTest method setUp.
@BeforeEach
public void setUp() throws Exception {
registerVolatileStorageService();
thingRegistry = getService(ThingRegistry.class, ThingRegistry.class);
assertNotNull(thingRegistry, "Thing registry is missing");
// Ensure the MieleWebservice is not initialized.
MieleHandlerFactory factory = getService(ThingHandlerFactory.class, MieleHandlerFactory.class);
assertNotNull(factory);
// Assume an access token has already been stored
AccessTokenResponse accessTokenResponse = new AccessTokenResponse();
accessTokenResponse.setAccessToken(ACCESS_TOKEN);
OAuthClientService oAuthClientService = mock(OAuthClientService.class);
when(oAuthClientService.getAccessTokenResponse()).thenReturn(accessTokenResponse);
OAuthFactory oAuthFactory = mock(OAuthFactory.class);
when(oAuthFactory.getOAuthClientService(MieleCloudBindingIntegrationTestConstants.EMAIL)).thenReturn(oAuthClientService);
OpenHabOAuthTokenRefresher tokenRefresher = getService(OAuthTokenRefresher.class, OpenHabOAuthTokenRefresher.class);
assertNotNull(tokenRefresher);
setPrivate(Objects.requireNonNull(tokenRefresher), "oauthFactory", oAuthFactory);
}
use of org.openhab.core.thing.ThingRegistry in project openhab-addons by openhab.
the class NeeoDeviceDefinitions method save.
/**
* Saves the current definitions to the {@link #file}. Any {@link IOException} will be logged and ignored.
*/
public void save() {
logger.debug("Saving devices to {}", file.toPath());
try {
// ensure full path exists
file.getParentFile().mkdirs();
final List<NeeoDevice> devices = new ArrayList<>();
// filter for only things that are still valid
final ThingRegistry thingRegistry = context.getThingRegistry();
for (NeeoDevice device : uidToDevice.values()) {
if (NeeoConstants.NEEOIO_BINDING_ID.equalsIgnoreCase(device.getUid().getBindingId())) {
devices.add(device);
} else {
if (thingRegistry.get(device.getUid().asThingUID()) != null) {
devices.add(device);
}
}
}
final String json = gson.toJson(devices);
final byte[] contents = json.getBytes(StandardCharsets.UTF_8);
Files.write(file.toPath(), contents);
} catch (IOException e) {
logger.debug("IOException writing {}: {}", file.toPath(), e.getMessage(), e);
}
}
use of org.openhab.core.thing.ThingRegistry in project openhab-addons by openhab.
the class CreateBridgeServletTest method whenBridgeReconfigurationFailsDueToMissingBridgeHandlerThenAWarningIsShownOnTheSuccessPage.
@Test
public void whenBridgeReconfigurationFailsDueToMissingBridgeHandlerThenAWarningIsShownOnTheSuccessPage() 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);
Thing bridge = mock(Thing.class);
when(bridge.getHandler()).thenReturn(null);
ThingRegistry thingRegistry = mock(ThingRegistry.class);
when(thingRegistry.get(any())).thenReturn(bridge);
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 SysteminfoOSGiTest method setUp.
@BeforeEach
public void setUp() {
VolatileStorageService volatileStorageService = new VolatileStorageService();
registerService(volatileStorageService);
// Preparing the mock with OS properties, that are used in the initialize method of SysteminfoHandler
mockedSystemInfo = mock(SysteminfoInterface.class);
when(mockedSystemInfo.getCpuLogicalCores()).thenReturn(new DecimalType(2));
when(mockedSystemInfo.getCpuPhysicalCores()).thenReturn(new DecimalType(2));
when(mockedSystemInfo.getOsFamily()).thenReturn(new StringType("Mock OS"));
when(mockedSystemInfo.getOsManufacturer()).thenReturn(new StringType("Mock OS Manufacturer"));
when(mockedSystemInfo.getOsVersion()).thenReturn(new StringType("Mock Os Version"));
systeminfoHandlerFactory = getService(ThingHandlerFactory.class, SysteminfoHandlerFactory.class);
SysteminfoInterface oshiSystemInfo = getService(SysteminfoInterface.class);
// the external OSHI library
if (oshiSystemInfo != null) {
systeminfoHandlerFactory.unbindSystemInfo(oshiSystemInfo);
}
systeminfoHandlerFactory.bindSystemInfo(mockedSystemInfo);
managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
assertThat(managedThingProvider, is(notNullValue()));
thingRegistry = getService(ThingRegistry.class);
assertThat(thingRegistry, is(notNullValue()));
itemRegistry = getService(ItemRegistry.class);
assertThat(itemRegistry, is(notNullValue()));
}
use of org.openhab.core.thing.ThingRegistry in project openhab-addons by openhab.
the class GenericWemoOSGiTest method setUpServices.
protected void setUpServices() throws IOException {
WemoUtil.serviceAvailableFunction = (host, port) -> true;
// StorageService is required from the ManagedThingProvider
VolatileStorageService volatileStorageService = new VolatileStorageService();
registerService(volatileStorageService);
// Mock the UPnP Service, that is required from the UPnP IO Service
mockUpnpService = new MockUpnpService(false, true);
mockUpnpService.startup();
registerService(mockUpnpService, UpnpService.class.getName());
managedThingProvider = getService(ManagedThingProvider.class);
assertThat(managedThingProvider, is(notNullValue()));
thingRegistry = getService(ThingRegistry.class);
assertThat(thingRegistry, is(notNullValue()));
// UPnP IO Service is required from the WemoDiscoveryService and WemoHandlerFactory
upnpIOService = getService(UpnpIOService.class);
assertThat(upnpIOService, is(notNullValue()));
mockCaller = Mockito.spy(new WemoHttpCall());
WemoHttpCallFactory wemoHttpCallFactory = () -> mockCaller;
registerService(wemoHttpCallFactory, WemoHttpCallFactory.class.getName());
ChannelTypeProvider channelTypeProvider = mock(ChannelTypeProvider.class);
when(channelTypeProvider.getChannelType(any(ChannelTypeUID.class), any(Locale.class))).thenReturn(ChannelTypeBuilder.state(DEFAULT_CHANNEL_TYPE_UID, "label", CoreItemFactory.SWITCH).build());
registerService(channelTypeProvider);
}
Aggregations