use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.
the class OwserverBridgeHandlerTest method testInitializationReportsNotRefreshableOnFailedConnection.
@Test
public void testInitializationReportsNotRefreshableOnFailedConnection() {
final OwserverBridgeHandler bridgeHandler = this.bridgeHandler;
if (bridgeHandler == null) {
fail("bridgeHandler is null");
return;
}
Mockito.doAnswer(answer -> {
bridgeHandler.reportConnectionState(OwserverConnectionState.FAILED);
return null;
}).when(owserverConnection).start();
bridgeHandler.initialize();
ArgumentCaptor<ThingStatusInfo> statusCaptor = ArgumentCaptor.forClass(ThingStatusInfo.class);
waitForAssert(() -> {
verify(thingHandlerCallback, times(2)).statusUpdated(eq(bridge), statusCaptor.capture());
});
assertThat(statusCaptor.getAllValues().get(0).getStatus(), is(ThingStatus.UNKNOWN));
assertThat(statusCaptor.getAllValues().get(1).getStatus(), is(ThingStatus.OFFLINE));
waitForAssert(() -> assertFalse(bridgeHandler.isRefreshable()));
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.
the class WWNAccountHandlerTest method initializeShouldCallTheCallback.
@SuppressWarnings("null")
@Test
public void initializeShouldCallTheCallback() {
when(bridge.getConfiguration()).thenReturn(configuration);
WWNAccountConfiguration bridgeConfig = new WWNAccountConfiguration();
when(configuration.as(eq(WWNAccountConfiguration.class))).thenReturn(bridgeConfig);
bridgeConfig.accessToken = "my token";
// we expect the handler#initialize method to call the callback during execution and
// pass it the thing and a ThingStatusInfo object containing the ThingStatus of the thing.
handler.initialize();
// the argument captor will capture the argument of type ThingStatusInfo given to the
// callback#statusUpdated method.
ArgumentCaptor<ThingStatusInfo> statusInfoCaptor = ArgumentCaptor.forClass(ThingStatusInfo.class);
// verify the interaction with the callback and capture the ThingStatusInfo argument:
verify(callback).statusUpdated(eq(bridge), statusInfoCaptor.capture());
// assert that the ThingStatusInfo given to the callback was build with the UNKNOWN status:
ThingStatusInfo thingStatusInfo = statusInfoCaptor.getValue();
assertThat(thingStatusInfo.getStatus(), is(equalTo(ThingStatus.UNKNOWN)));
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.
the class GenericThingHandlerTests method handleBridgeStatusChange.
@Test
public void handleBridgeStatusChange() {
Configuration config = new Configuration();
config.put("availabilityTopic", "test/LWT");
when(thing.getConfiguration()).thenReturn(config);
thingHandler.initialize();
thingHandler.bridgeStatusChanged(new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, null));
thingHandler.bridgeStatusChanged(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
verify(connection, times(2)).subscribe(eq("test/LWT"), any());
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.
the class NetworkHandlerTest method pingDeviceInitTests.
@Test
public void pingDeviceInitTests() {
NetworkBindingConfiguration config = new NetworkBindingConfiguration();
NetworkHandler handler = spy(new NetworkHandler(thing, false, config));
handler.setCallback(callback);
// Provide minimal configuration
when(thing.getConfiguration()).thenAnswer(a -> {
Configuration conf = new Configuration();
conf.put(NetworkBindingConstants.PARAMETER_HOSTNAME, "127.0.0.1");
return conf;
});
PresenceDetection presenceDetection = spy(new PresenceDetection(handler, 2000));
// Mock start/stop automatic refresh
doNothing().when(presenceDetection).startAutomaticRefresh(any());
doNothing().when(presenceDetection).stopAutomaticRefresh();
handler.initialize(presenceDetection);
// Check that we are online
ArgumentCaptor<ThingStatusInfo> statusInfoCaptor = ArgumentCaptor.forClass(ThingStatusInfo.class);
verify(callback).statusUpdated(eq(thing), statusInfoCaptor.capture());
assertEquals(ThingStatus.ONLINE, statusInfoCaptor.getValue().getStatus());
// Mock result value
PresenceDetectionValue value = mock(PresenceDetectionValue.class);
when(value.getLowestLatency()).thenReturn(10.0);
when(value.isReachable()).thenReturn(true);
when(value.getSuccessfulDetectionTypes()).thenReturn("TESTMETHOD");
// Partial result from the PresenceDetection object should affect the
// ONLINE and LATENCY channel
handler.partialDetectionResult(value);
verify(callback).stateUpdated(eq(new ChannelUID(thingUID, NetworkBindingConstants.CHANNEL_ONLINE)), eq(OnOffType.ON));
verify(callback).stateUpdated(eq(new ChannelUID(thingUID, NetworkBindingConstants.CHANNEL_LATENCY)), eq(new QuantityType<>("10.0 ms")));
// Final result affects the LASTSEEN channel
when(value.isFinished()).thenReturn(true);
handler.finalDetectionResult(value);
verify(callback).stateUpdated(eq(new ChannelUID(thingUID, NetworkBindingConstants.CHANNEL_LASTSEEN)), any());
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.
the class NetworkHandlerTest method tcpDeviceInitTests.
@Test
public void tcpDeviceInitTests() {
NetworkBindingConfiguration config = new NetworkBindingConfiguration();
NetworkHandler handler = spy(new NetworkHandler(thing, true, config));
assertThat(handler.isTCPServiceDevice(), is(true));
handler.setCallback(callback);
// Port is missing, should make the device OFFLINE
when(thing.getConfiguration()).thenAnswer(a -> {
Configuration conf = new Configuration();
conf.put(NetworkBindingConstants.PARAMETER_HOSTNAME, "127.0.0.1");
return conf;
});
handler.initialize(new PresenceDetection(handler, 2000));
// Check that we are offline
ArgumentCaptor<ThingStatusInfo> statusInfoCaptor = ArgumentCaptor.forClass(ThingStatusInfo.class);
verify(callback).statusUpdated(eq(thing), statusInfoCaptor.capture());
assertThat(statusInfoCaptor.getValue().getStatus(), is(equalTo(ThingStatus.OFFLINE)));
assertThat(statusInfoCaptor.getValue().getStatusDetail(), is(equalTo(ThingStatusDetail.CONFIGURATION_ERROR)));
}
Aggregations