2 * Copyright (c) 2010-2020 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.core.Is.is;
16 import static org.junit.Assert.*;
17 import static org.mockito.ArgumentMatchers.any;
18 import static org.mockito.Mockito.*;
19 import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
21 import java.util.HashMap;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.openhab.core.config.core.Configuration;
28 import org.openhab.core.test.java.JavaTest;
29 import org.openhab.core.thing.Bridge;
30 import org.openhab.core.thing.ChannelUID;
31 import org.openhab.core.thing.Thing;
32 import org.openhab.core.thing.ThingStatus;
33 import org.openhab.core.thing.ThingUID;
34 import org.openhab.core.thing.binding.ThingHandlerCallback;
35 import org.openhab.core.thing.binding.builder.BridgeBuilder;
36 import org.openhab.core.thing.binding.builder.ChannelBuilder;
39 * Tests cases for {@link org.openhab.binding.dmx.internal.handler.SacnBridgeHandler}.
41 * @author Jan N. Klug - Initial contribution
43 public class SacnBridgeHandlerTest extends JavaTest {
44 private static final String TEST_ADDRESS = "localhost";
45 private static final int TEST_UNIVERSE = 1;
47 private final ThingUID BRIDGE_UID_SACN = new ThingUID(THING_TYPE_SACN_BRIDGE, "sacnbridge");
48 private final ChannelUID CHANNEL_UID_MUTE = new ChannelUID(BRIDGE_UID_SACN, CHANNEL_MUTE);
50 Map<String, Object> bridgeProperties;
52 private Bridge bridge;
53 private SacnBridgeHandler bridgeHandler;
57 bridgeProperties = new HashMap<>();
58 bridgeProperties.put(CONFIG_ADDRESS, TEST_ADDRESS);
59 bridgeProperties.put(CONFIG_UNIVERSE, TEST_UNIVERSE);
60 bridgeProperties.put(CONFIG_SACN_MODE, "unicast");
61 bridge = BridgeBuilder.create(THING_TYPE_SACN_BRIDGE, "sacnbridge").withLabel("sACN Bridge")
62 .withChannel(ChannelBuilder.create(CHANNEL_UID_MUTE, "Switch").withType(MUTE_CHANNEL_TYPEUID).build())
63 .withConfiguration(new Configuration(bridgeProperties)).build();
65 ThingHandlerCallback mockCallback = mock(ThingHandlerCallback.class);
67 ((Thing) answer.getArgument(0)).setStatusInfo(answer.getArgument(1));
69 }).when(mockCallback).statusUpdated(any(), any());
71 bridgeHandler = new SacnBridgeHandler(bridge) {
73 protected void validateConfigurationParameters(Map<String, Object> configurationParameters) {
77 bridgeHandler.getThing().setHandler(bridgeHandler);
78 bridgeHandler.setCallback(mockCallback);
79 bridgeHandler.initialize();
83 public void tearDown() {
84 bridgeHandler.dispose();
88 public void assertBridgeStatus() {
89 waitForAssert(() -> assertEquals(ThingStatus.ONLINE, bridge.getStatusInfo().getStatus()));
93 public void renamingOfUniverses() {
94 waitForAssert(() -> assertThat(bridgeHandler.getUniverseId(), is(TEST_UNIVERSE)));
96 bridgeProperties.replace(CONFIG_UNIVERSE, 2);
97 bridgeHandler.handleConfigurationUpdate(bridgeProperties);
98 waitForAssert(() -> assertThat(bridgeHandler.getUniverseId(), is(2)));
100 bridgeProperties.replace(CONFIG_UNIVERSE, TEST_UNIVERSE);
101 bridgeHandler.handleConfigurationUpdate(bridgeProperties);
102 waitForAssert(() -> assertThat(bridgeHandler.getUniverseId(), is(TEST_UNIVERSE)));