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.mielecloud.internal.util;
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.openhab.binding.mielecloud.internal.util.MieleCloudBindingIntegrationTestConstants.MIELE_CLOUD_ACCOUNT_LABEL;
18 import java.util.Collections;
19 import java.util.Objects;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.junit.jupiter.api.BeforeEach;
24 import org.openhab.binding.mielecloud.internal.MieleCloudBindingConstants;
25 import org.openhab.binding.mielecloud.internal.handler.MieleBridgeHandler;
26 import org.openhab.core.config.core.Configuration;
27 import org.openhab.core.config.discovery.inbox.Inbox;
28 import org.openhab.core.test.java.JavaOSGiTest;
29 import org.openhab.core.test.storage.VolatileStorageService;
30 import org.openhab.core.thing.Bridge;
31 import org.openhab.core.thing.ManagedThingProvider;
32 import org.openhab.core.thing.ThingRegistry;
33 import org.openhab.core.thing.binding.builder.BridgeBuilder;
36 * Parent class for openHAB OSGi tests offering helper methods for common interactions with the openHAB runtime and its
39 * @author Björn Lange - Initial contribution
42 public abstract class OpenHabOsgiTest extends JavaOSGiTest {
46 private ThingRegistry thingRegistry;
48 protected Inbox getInbox() {
50 return Objects.requireNonNull(inbox);
53 protected ThingRegistry getThingRegistry() {
54 assertNotNull(thingRegistry);
55 return Objects.requireNonNull(thingRegistry);
59 public void setUpEshOsgiTest() {
60 registerVolatileStorageService();
61 inbox = getService(Inbox.class);
65 private void setUpThingRegistry() {
66 thingRegistry = getService(ThingRegistry.class, ThingRegistry.class);
67 assertNotNull(thingRegistry, "Thing registry is missing");
71 * Sets up a {@link Bridge} with an attached {@link MieleBridgeHandler} and registers it with the
72 * {@link ManagedThingProvider} and {@link ThingRegistry}.
74 public void setUpBridge() {
75 ManagedThingProvider managedThingProvider = getService(ManagedThingProvider.class);
76 assertNotNull(managedThingProvider);
78 Bridge bridge = BridgeBuilder
79 .create(MieleCloudBindingConstants.THING_TYPE_BRIDGE,
80 MieleCloudBindingIntegrationTestConstants.BRIDGE_THING_UID)
82 new Configuration(Collections.singletonMap(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL,
83 MieleCloudBindingIntegrationTestConstants.EMAIL)))
84 .withLabel(MIELE_CLOUD_ACCOUNT_LABEL).build();
85 assertNotNull(bridge);
87 managedThingProvider.add(bridge);
90 assertNotNull(bridge.getHandler());
91 assertTrue(bridge.getHandler() instanceof MieleBridgeHandler, "Handler type is wrong");
96 * Registers a volatile storage service.
99 protected void registerVolatileStorageService() {
100 registerService(new VolatileStorageService());