This repository has been archived by the owner on May 7, 2020. It is now read-only.
/
ArtnetBridgeHandlerTest.java
127 lines (105 loc) · 5.11 KB
/
ArtnetBridgeHandlerTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* Copyright (c) 2014-2017 by the respective copyright holders.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.smarthome.binding.dmx;
import static org.eclipse.smarthome.binding.dmx.DmxBindingConstants.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.smarthome.binding.dmx.handler.ArtnetBridgeHandler;
import org.eclipse.smarthome.binding.dmx.internal.DmxBridgeHandler;
import org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.ManagedThingProvider;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingProvider;
import org.eclipse.smarthome.core.thing.ThingStatus;
import org.eclipse.smarthome.core.thing.binding.BridgeHandler;
import org.eclipse.smarthome.core.thing.binding.builder.BridgeBuilder;
import org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder;
import org.eclipse.smarthome.test.java.JavaOSGiTest;
import org.eclipse.smarthome.test.storage.VolatileStorageService;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* Tests cases for {@link ArtnetBridgeHandler}.
*
* @author Jan N. Klug - Initial contribution
*/
public class ArtnetBridgeHandlerTest extends JavaOSGiTest {
private static final String TEST_ADDRESS = "localhost";
private static final int TEST_UNIVERSE = 1;
private static final int TEST_CHANNEL = 100;
private ManagedThingProvider managedThingProvider;
private VolatileStorageService volatileStorageService = new VolatileStorageService();
Map<String, Object> bridgeProperties;
Map<String, Object> thingProperties;
private Bridge bridge;
private Thing thing;
@Before
public void setUp() {
registerService(volatileStorageService);
managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
bridgeProperties = new HashMap<>();
bridgeProperties.put(CONFIG_ADDRESS, TEST_ADDRESS);
bridgeProperties.put(CONFIG_UNIVERSE, TEST_UNIVERSE);
bridge = BridgeBuilder.create(THING_TYPE_ARTNET_BRIDGE, "artnetbridge").withLabel("Artnet Bridge")
.withConfiguration(new Configuration(bridgeProperties)).build();
thingProperties = new HashMap<>();
thingProperties.put(CONFIG_DMX_ID, String.format("%d", TEST_CHANNEL));
thing = ThingBuilder.create(THING_TYPE_DIMMER, "testdimmer").withLabel("Dimmer Thing")
.withBridge(bridge.getUID()).withConfiguration(new Configuration(thingProperties)).build();
}
@After
public void tearDown() {
managedThingProvider.remove(thing.getUID());
managedThingProvider.remove(bridge.getUID());
unregisterService(volatileStorageService);
}
@Test
public void initializationOfBridgeHandler() {
assertThat(bridge.getHandler(), is(nullValue()));
managedThingProvider.add(bridge);
BridgeHandler bridgeHandler = bridge.getHandler();
waitForAssert(() -> assertThat(bridgeHandler, notNullValue()));
waitForAssert(() -> assertThat(bridge.getStatus(), is(ThingStatus.ONLINE)));
}
@Test
public void renamingOfUniverses() {
managedThingProvider.add(bridge);
DmxBridgeHandler bridgeHandler = (DmxBridgeHandler) bridge.getHandler();
waitForAssert(() -> assertThat(bridgeHandler.getUniverseId(), is(TEST_UNIVERSE)));
bridgeProperties.replace(CONFIG_UNIVERSE, 2);
bridgeHandler.handleConfigurationUpdate(bridgeProperties);
waitForAssert(() -> assertThat(bridgeHandler.getUniverseId(), is(2)));
bridgeProperties.replace(CONFIG_UNIVERSE, TEST_UNIVERSE);
bridgeHandler.handleConfigurationUpdate(bridgeProperties);
waitForAssert(() -> assertThat(bridgeHandler.getUniverseId(), is(TEST_UNIVERSE)));
}
@Test
public void initializationOfDimmerThing() {
assertThat(thing.getHandler(), is(nullValue()));
managedThingProvider.add(bridge);
waitForAssert(() -> assertThat(bridge.getHandler(), notNullValue()));
managedThingProvider.add(thing);
waitForAssert(() -> assertThat(thing.getHandler(), notNullValue()));
}
public void retrievingOfChannels() {
managedThingProvider.add(bridge);
waitForAssert(() -> assertThat(bridge.getHandler(), notNullValue()));
managedThingProvider.add(thing);
DmxBridgeHandler bridgeHandler = (DmxBridgeHandler) bridge.getHandler();
BaseDmxChannel channel = new BaseDmxChannel(TEST_UNIVERSE, TEST_CHANNEL);
BaseDmxChannel returnedChannel = bridgeHandler.getDmxChannel(channel, thing);
Integer channelId = returnedChannel.getChannelId();
assertThat(channelId, is(TEST_CHANNEL));
}
}