]> git.basschouten.com Git - openhab-addons.git/blob
8ac2960ad4f2415e04855d6e33b4a0822cb22591
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.boschshc.internal.devices.windowcontact;
14
15 import static org.mockito.Mockito.verify;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.boschshc.internal.devices.AbstractBatteryPoweredDeviceHandlerTest;
20 import org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants;
21 import org.openhab.core.library.types.OpenClosedType;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.ThingTypeUID;
24
25 import com.google.gson.JsonElement;
26 import com.google.gson.JsonParser;
27
28 /**
29  * Unit Tests for {@link WindowContactHandler}.
30  *
31  * @author David Pace - Initial contribution
32  *
33  */
34 @NonNullByDefault
35 class WindowContactHandlerTest extends AbstractBatteryPoweredDeviceHandlerTest<WindowContactHandler> {
36
37     @Override
38     protected WindowContactHandler createFixture() {
39         return new WindowContactHandler(getThing());
40     }
41
42     @Override
43     protected String getDeviceID() {
44         return "hdm:HomeMaticIP:3014D711A000009D545DEB39D";
45     }
46
47     @Override
48     protected ThingTypeUID getThingTypeUID() {
49         return BoschSHCBindingConstants.THING_TYPE_WINDOW_CONTACT;
50     }
51
52     @Test
53     void testUpdateChannelsShutterContactService() {
54         JsonElement jsonObject = JsonParser
55                 .parseString("{\n" + "   \"@type\": \"shutterContactState\",\n" + "   \"value\": \"OPEN\"\n" + " }");
56         getFixture().processUpdate("ShutterContact", jsonObject);
57         verify(getCallback()).stateUpdated(
58                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_CONTACT), OpenClosedType.OPEN);
59
60         jsonObject = JsonParser
61                 .parseString("{\n" + "   \"@type\": \"shutterContactState\",\n" + "   \"value\": \"CLOSED\"\n" + " }");
62         getFixture().processUpdate("ShutterContact", jsonObject);
63         verify(getCallback()).stateUpdated(
64                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_CONTACT), OpenClosedType.CLOSED);
65     }
66 }