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.max.test;
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.openhab.binding.max.internal.MaxBindingConstants.*;
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;
36 * Tests for {@link MaxCubeBridgeHandler}.
38 * @author Marcel Verpaalen - Initial contribution
39 * @author Wouter Born - Migrate Groovy to Java tests
41 public class MaxCubeBridgeHandlerOSGiTest extends JavaOSGiTest {
43 private static final ThingTypeUID BRIDGE_THING_TYPE_UID = new ThingTypeUID(BINDING_ID, BRIDGE_MAXCUBE);
45 private ThingRegistry thingRegistry;
46 private VolatileStorageService volatileStorageService = new VolatileStorageService();
48 private Bridge maxBridge;
52 registerService(volatileStorageService);
54 thingRegistry = getService(ThingRegistry.class);
55 assertThat(thingRegistry, is(notNullValue()));
59 public void tearDown() {
60 if (maxBridge != null) {
61 thingRegistry.remove(maxBridge.getUID());
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())));
67 unregisterService(volatileStorageService);
71 public void maxCubeBridgeHandlerIsCreated() {
72 MaxCubeBridgeHandler maxBridgeHandler = getService(ThingHandler.class, MaxCubeBridgeHandler.class);
73 assertThat(maxBridgeHandler, is(nullValue()));
75 Configuration configuration = new Configuration();
76 configuration.put(Thing.PROPERTY_SERIAL_NUMBER, "KEQ0565026");
77 configuration.put(MaxBindingConstants.PROPERTY_IP_ADDRESS, "192.168.3.100");
79 ThingUID cubeUid = new ThingUID(BRIDGE_THING_TYPE_UID, "testCube");
81 maxBridge = BridgeBuilder.create(BRIDGE_THING_TYPE_UID, cubeUid).withConfiguration(configuration).build();
82 thingRegistry.add(maxBridge);
84 // wait for MaxCubeBridgeHandler to be registered
85 waitForAssert(() -> assertThat(maxBridge.getHandler(), is(notNullValue())));