2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.boschshc.internal.devices.camera;
15 import static org.junit.jupiter.api.Assertions.assertSame;
16 import static org.mockito.ArgumentMatchers.eq;
17 import static org.mockito.Mockito.*;
19 import java.util.concurrent.ExecutionException;
20 import java.util.concurrent.TimeoutException;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.junit.jupiter.api.Test;
24 import org.mockito.ArgumentCaptor;
25 import org.mockito.Captor;
26 import org.openhab.binding.boschshc.internal.devices.AbstractBoschSHCDeviceHandlerTest;
27 import org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants;
28 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
29 import org.openhab.binding.boschshc.internal.services.cameranotification.CameraNotificationState;
30 import org.openhab.binding.boschshc.internal.services.cameranotification.dto.CameraNotificationServiceState;
31 import org.openhab.binding.boschshc.internal.services.privacymode.PrivacyModeState;
32 import org.openhab.binding.boschshc.internal.services.privacymode.dto.PrivacyModeServiceState;
33 import org.openhab.core.library.types.OnOffType;
34 import org.openhab.core.thing.ChannelUID;
35 import org.openhab.core.thing.ThingTypeUID;
37 import com.google.gson.JsonElement;
38 import com.google.gson.JsonParser;
41 * Unit tests for {@link CameraHandler}.
43 * @author David Pace - Initial contribution
47 class CameraHandlerTest extends AbstractBoschSHCDeviceHandlerTest<CameraHandler> {
49 private @Captor @NonNullByDefault({}) ArgumentCaptor<PrivacyModeServiceState> privacyModeServiceStateCaptor;
51 private @Captor @NonNullByDefault({}) ArgumentCaptor<CameraNotificationServiceState> cameraNotificationServiceStateCaptor;
54 protected CameraHandler createFixture() {
55 return new CameraHandler(getThing());
59 protected ThingTypeUID getThingTypeUID() {
60 return BoschSHCBindingConstants.THING_TYPE_CAMERA_360;
64 protected String getDeviceID() {
65 return "8e28ce2d-e7bf-3e3d-8e3a-a78de61b493e";
69 void testHandleCommandPrivacyMode()
70 throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
71 getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_PRIVACY_MODE),
73 verify(getBridgeHandler()).putState(eq(getDeviceID()), eq("PrivacyMode"),
74 privacyModeServiceStateCaptor.capture());
75 PrivacyModeServiceState state = privacyModeServiceStateCaptor.getValue();
76 assertSame(PrivacyModeState.ENABLED, state.value);
78 getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_PRIVACY_MODE),
80 verify(getBridgeHandler(), times(2)).putState(eq(getDeviceID()), eq("PrivacyMode"),
81 privacyModeServiceStateCaptor.capture());
82 state = privacyModeServiceStateCaptor.getValue();
83 assertSame(PrivacyModeState.DISABLED, state.value);
87 void testHandleCommandCameraNotification()
88 throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
89 getFixture().handleCommand(
90 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_CAMERA_NOTIFICATION),
92 verify(getBridgeHandler()).putState(eq(getDeviceID()), eq("CameraNotification"),
93 cameraNotificationServiceStateCaptor.capture());
94 CameraNotificationServiceState state = cameraNotificationServiceStateCaptor.getValue();
95 assertSame(CameraNotificationState.ENABLED, state.value);
97 getFixture().handleCommand(
98 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_CAMERA_NOTIFICATION),
100 verify(getBridgeHandler(), times(2)).putState(eq(getDeviceID()), eq("CameraNotification"),
101 cameraNotificationServiceStateCaptor.capture());
102 state = cameraNotificationServiceStateCaptor.getValue();
103 assertSame(CameraNotificationState.DISABLED, state.value);
107 void testUpdateChannelsPrivacyModeState() {
108 JsonElement jsonObject = JsonParser.parseString("{\"@type\":\"privacyModeState\",\"value\":\"ENABLED\"}");
109 getFixture().processUpdate("PrivacyMode", jsonObject);
110 verify(getCallback()).stateUpdated(
111 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_PRIVACY_MODE), OnOffType.ON);
113 jsonObject = JsonParser.parseString("{\"@type\":\"privacyModeState\",\"value\":\"DISABLED\"}");
114 getFixture().processUpdate("PrivacyMode", jsonObject);
115 verify(getCallback()).stateUpdated(
116 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_PRIVACY_MODE), OnOffType.OFF);
120 void testUpdateChannelsCameraNotificationState() {
121 JsonElement jsonObject = JsonParser
122 .parseString("{\"@type\":\"cameraNotificationState\",\"value\":\"ENABLED\"}");
123 getFixture().processUpdate("CameraNotification", jsonObject);
124 verify(getCallback()).stateUpdated(
125 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_CAMERA_NOTIFICATION),
128 jsonObject = JsonParser.parseString("{\"@type\":\"cameraNotificationState\",\"value\":\"DISABLED\"}");
129 getFixture().processUpdate("CameraNotification", jsonObject);
130 verify(getCallback()).stateUpdated(
131 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_CAMERA_NOTIFICATION),