]> git.basschouten.com Git - openhab-addons.git/blob
830fc579fb5e09ffccaab1fb625f442c4d74cd96
[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.dmx.internal.handler;
14
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.ArgumentMatchers.any;
17 import static org.mockito.Mockito.*;
18 import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
19
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import org.junit.jupiter.api.AfterEach;
24 import org.junit.jupiter.api.BeforeEach;
25 import org.junit.jupiter.api.Test;
26 import org.openhab.core.config.core.Configuration;
27 import org.openhab.core.test.java.JavaTest;
28 import org.openhab.core.thing.Bridge;
29 import org.openhab.core.thing.ChannelUID;
30 import org.openhab.core.thing.Thing;
31 import org.openhab.core.thing.ThingStatus;
32 import org.openhab.core.thing.ThingUID;
33 import org.openhab.core.thing.binding.ThingHandlerCallback;
34 import org.openhab.core.thing.binding.builder.BridgeBuilder;
35 import org.openhab.core.thing.binding.builder.ChannelBuilder;
36
37 /**
38  * Tests cases for {@link org.openhab.binding.dmx.internal.handler.Lib485BridgeHandler}.
39  *
40  * @author Jan N. Klug - Initial contribution
41  */
42 public class Lib485BridgeHandlerTest extends JavaTest {
43
44     private static final String TEST_ADDRESS = "localhost";
45
46     private final ThingUID BRIDGE_UID_LIB485 = new ThingUID(THING_TYPE_LIB485_BRIDGE, "lib485bridge");
47     private final ChannelUID CHANNEL_UID_MUTE = new ChannelUID(BRIDGE_UID_LIB485, CHANNEL_MUTE);
48
49     Map<String, Object> bridgeProperties;
50
51     private Bridge bridge;
52     private Lib485BridgeHandler bridgeHandler;
53
54     @BeforeEach
55     public void setUp() {
56         bridgeProperties = new HashMap<>();
57         bridgeProperties.put(CONFIG_ADDRESS, TEST_ADDRESS);
58         bridge = BridgeBuilder.create(THING_TYPE_LIB485_BRIDGE, "lib485bridge").withLabel("Lib485 Bridge")
59                 .withChannel(ChannelBuilder.create(CHANNEL_UID_MUTE, "Switch").withType(MUTE_CHANNEL_TYPEUID).build())
60                 .withConfiguration(new Configuration(bridgeProperties)).build();
61
62         ThingHandlerCallback mockCallback = mock(ThingHandlerCallback.class);
63         doAnswer(answer -> {
64             ((Thing) answer.getArgument(0)).setStatusInfo(answer.getArgument(1));
65             return null;
66         }).when(mockCallback).statusUpdated(any(), any());
67
68         bridgeHandler = new Lib485BridgeHandler(bridge) {
69             @Override
70             protected void validateConfigurationParameters(Map<String, Object> configurationParameters) {
71             }
72         };
73
74         bridgeHandler.getThing().setHandler(bridgeHandler);
75         bridgeHandler.setCallback(mockCallback);
76         bridgeHandler.initialize();
77     }
78
79     @AfterEach
80     public void tearDown() {
81         bridgeHandler.dispose();
82     }
83
84     @Test
85     public void assertBridgeStatus() {
86         waitForAssert(() -> assertEquals(ThingStatus.OFFLINE, bridge.getStatusInfo().getStatus()));
87     }
88 }