]> git.basschouten.com Git - openhab-addons.git/blob
8e8e2b6e60a956e576f919b5ce018ac51035d765
[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.max.test;
14
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.openhab.binding.max.internal.MaxBindingConstants.*;
18
19 import org.junit.jupiter.api.AfterEach;
20 import org.junit.jupiter.api.BeforeEach;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.max.internal.MaxBindingConstants;
23 import org.openhab.binding.max.internal.handler.MaxCubeBridgeHandler;
24 import org.openhab.core.config.core.Configuration;
25 import org.openhab.core.test.java.JavaOSGiTest;
26 import org.openhab.core.test.storage.VolatileStorageService;
27 import org.openhab.core.thing.Bridge;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingRegistry;
30 import org.openhab.core.thing.ThingTypeUID;
31 import org.openhab.core.thing.ThingUID;
32 import org.openhab.core.thing.binding.ThingHandler;
33 import org.openhab.core.thing.binding.builder.BridgeBuilder;
34
35 /**
36  * Tests for {@link MaxCubeBridgeHandler}.
37  *
38  * @author Marcel Verpaalen - Initial contribution
39  * @author Wouter Born - Migrate Groovy to Java tests
40  */
41 public class MaxCubeBridgeHandlerOSGiTest extends JavaOSGiTest {
42
43     private static final ThingTypeUID BRIDGE_THING_TYPE_UID = new ThingTypeUID(BINDING_ID, BRIDGE_MAXCUBE);
44
45     private ThingRegistry thingRegistry;
46     private VolatileStorageService volatileStorageService = new VolatileStorageService();
47
48     private Bridge maxBridge;
49
50     @BeforeEach
51     public void setUp() {
52         registerService(volatileStorageService);
53
54         thingRegistry = getService(ThingRegistry.class);
55         assertThat(thingRegistry, is(notNullValue()));
56     }
57
58     @AfterEach
59     public void tearDown() {
60         if (maxBridge != null) {
61             thingRegistry.remove(maxBridge.getUID());
62
63             // TODO: Due to synchronization issues the handler is currently not unset. To be fixed by PR #1789.
64             // waitForAssert(() -> assertThat(maxBridge.getHandler(), is(nullValue())));
65         }
66
67         unregisterService(volatileStorageService);
68     }
69
70     @Test
71     public void maxCubeBridgeHandlerIsCreated() {
72         MaxCubeBridgeHandler maxBridgeHandler = getService(ThingHandler.class, MaxCubeBridgeHandler.class);
73         assertThat(maxBridgeHandler, is(nullValue()));
74
75         Configuration configuration = new Configuration();
76         configuration.put(Thing.PROPERTY_SERIAL_NUMBER, "KEQ0565026");
77         configuration.put(MaxBindingConstants.PROPERTY_IP_ADDRESS, "192.168.3.100");
78
79         ThingUID cubeUid = new ThingUID(BRIDGE_THING_TYPE_UID, "testCube");
80
81         maxBridge = BridgeBuilder.create(BRIDGE_THING_TYPE_UID, cubeUid).withConfiguration(configuration).build();
82         thingRegistry.add(maxBridge);
83
84         // wait for MaxCubeBridgeHandler to be registered
85         waitForAssert(() -> assertThat(maxBridge.getHandler(), is(notNullValue())));
86     }
87 }