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.dmx.internal.handler;
15 import static org.hamcrest.MatcherAssert.assertThat;
16 import static org.hamcrest.core.Is.is;
17 import static org.junit.jupiter.api.Assertions.assertEquals;
18 import static org.mockito.ArgumentMatchers.any;
19 import static org.mockito.Mockito.*;
20 import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
22 import java.util.HashMap;
25 import org.junit.jupiter.api.AfterEach;
26 import org.junit.jupiter.api.BeforeEach;
27 import org.junit.jupiter.api.Test;
28 import org.openhab.core.config.core.Configuration;
29 import org.openhab.core.test.java.JavaTest;
30 import org.openhab.core.thing.Bridge;
31 import org.openhab.core.thing.ChannelUID;
32 import org.openhab.core.thing.Thing;
33 import org.openhab.core.thing.ThingStatus;
34 import org.openhab.core.thing.ThingUID;
35 import org.openhab.core.thing.binding.ThingHandlerCallback;
36 import org.openhab.core.thing.binding.builder.BridgeBuilder;
37 import org.openhab.core.thing.binding.builder.ChannelBuilder;
40 * Tests cases for {@link org.openhab.binding.dmx.internal.handler.SacnBridgeHandler}.
42 * @author Jan N. Klug - Initial contribution
44 public class SacnBridgeHandlerTest extends JavaTest {
45 private static final String TEST_ADDRESS = "localhost";
46 private static final int TEST_UNIVERSE = 1;
48 private final ThingUID BRIDGE_UID_SACN = new ThingUID(THING_TYPE_SACN_BRIDGE, "sacnbridge");
49 private final ChannelUID CHANNEL_UID_MUTE = new ChannelUID(BRIDGE_UID_SACN, CHANNEL_MUTE);
51 Map<String, Object> bridgeProperties;
53 private Bridge bridge;
54 private SacnBridgeHandler bridgeHandler;
58 bridgeProperties = new HashMap<>();
59 bridgeProperties.put(CONFIG_ADDRESS, TEST_ADDRESS);
60 bridgeProperties.put(CONFIG_UNIVERSE, TEST_UNIVERSE);
61 bridgeProperties.put(CONFIG_SACN_MODE, "unicast");
62 bridge = BridgeBuilder.create(THING_TYPE_SACN_BRIDGE, "sacnbridge").withLabel("sACN Bridge")
63 .withChannel(ChannelBuilder.create(CHANNEL_UID_MUTE, "Switch").withType(MUTE_CHANNEL_TYPEUID).build())
64 .withConfiguration(new Configuration(bridgeProperties)).build();
66 ThingHandlerCallback mockCallback = mock(ThingHandlerCallback.class);
68 ((Thing) answer.getArgument(0)).setStatusInfo(answer.getArgument(1));
70 }).when(mockCallback).statusUpdated(any(), any());
72 bridgeHandler = new SacnBridgeHandler(bridge) {
74 protected void validateConfigurationParameters(Map<String, Object> configurationParameters) {
78 bridgeHandler.getThing().setHandler(bridgeHandler);
79 bridgeHandler.setCallback(mockCallback);
80 bridgeHandler.initialize();
84 public void tearDown() {
85 bridgeHandler.dispose();
89 public void assertBridgeStatus() {
90 waitForAssert(() -> assertEquals(ThingStatus.ONLINE, bridge.getStatusInfo().getStatus()));
94 public void renamingOfUniverses() {
95 waitForAssert(() -> assertThat(bridgeHandler.getUniverseId(), is(TEST_UNIVERSE)));
97 bridgeProperties.replace(CONFIG_UNIVERSE, 2);
98 bridgeHandler.handleConfigurationUpdate(bridgeProperties);
99 waitForAssert(() -> assertThat(bridgeHandler.getUniverseId(), is(2)));
101 bridgeProperties.replace(CONFIG_UNIVERSE, TEST_UNIVERSE);
102 bridgeHandler.handleConfigurationUpdate(bridgeProperties);
103 waitForAssert(() -> assertThat(bridgeHandler.getUniverseId(), is(TEST_UNIVERSE)));