This repository has been archived by the owner on May 7, 2020. It is now read-only.
/
TradfriHandlerTest.java
103 lines (86 loc) · 3.91 KB
/
TradfriHandlerTest.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
/**
* 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.tradfri;
import static org.eclipse.smarthome.binding.tradfri.TradfriBindingConstants.*;
import static org.eclipse.smarthome.binding.tradfri.internal.config.TradfriDeviceConfig.*;
import static org.eclipse.smarthome.binding.tradfri.internal.config.TradfriGatewayConfig.*;
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.tradfri.handler.TradfriGatewayHandler;
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.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 TradfriGatewayHandler}.
*
* @author Kai Kreuzer - Initial contribution
*/
public class TradfriHandlerTest extends JavaOSGiTest {
private ManagedThingProvider managedThingProvider;
private VolatileStorageService volatileStorageService = new VolatileStorageService();
private Bridge bridge;
private Thing thing;
@Before
public void setUp() {
registerService(volatileStorageService);
managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
Map<String, Object> properties = new HashMap<>();
properties.put(CONFIG_HOST, "1.2.3.4");
properties.put(CONFIG_CODE, "abc");
bridge = BridgeBuilder.create(GATEWAY_TYPE_UID, "1").withLabel("My Gateway")
.withConfiguration(new Configuration(properties)).build();
properties = new HashMap<>();
properties.put(CONFIG_ID, "65537");
thing = ThingBuilder.create(THING_TYPE_DIMMABLE_LIGHT, "1").withLabel("My Bulb").withBridge(bridge.getUID())
.withConfiguration(new Configuration(properties)).build();
}
@After
public void tearDown() {
managedThingProvider.remove(thing.getUID());
managedThingProvider.remove(bridge.getUID());
unregisterService(volatileStorageService);
}
@Test
public void creationOfTradfriGatewayHandler() {
assertThat(bridge.getHandler(), is(nullValue()));
managedThingProvider.add(bridge);
waitForAssert(() -> assertThat(bridge.getHandler(), notNullValue()));
configurationOfTradfriGatewayHandler();
}
private void configurationOfTradfriGatewayHandler() {
Configuration configuration = bridge.getConfiguration();
assertThat(configuration, is(notNullValue()));
assertThat(configuration.get(CONFIG_HOST), is("1.2.3.4"));
assertThat(configuration.get(CONFIG_CODE), is("abc"));
}
@Test
public void creationOfTradfriLightHandler() {
assertThat(thing.getHandler(), is(nullValue()));
managedThingProvider.add(bridge);
managedThingProvider.add(thing);
waitForAssert(() -> assertThat(thing.getHandler(), notNullValue()));
configurationOfTradfriLightHandler();
}
private void configurationOfTradfriLightHandler() {
Configuration configuration = thing.getConfiguration();
assertThat(configuration, is(notNullValue()));
assertThat(configuration.get(CONFIG_ID), is("65537"));
}
}