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.config.servlet;
15 import static org.junit.jupiter.api.Assertions.assertTrue;
16 import static org.mockito.Mockito.*;
18 import java.util.stream.Stream;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.mielecloud.internal.MieleCloudBindingConstants;
23 import org.openhab.binding.mielecloud.internal.util.AbstractConfigFlowTest;
24 import org.openhab.binding.mielecloud.internal.util.MieleCloudBindingIntegrationTestConstants;
25 import org.openhab.binding.mielecloud.internal.util.ReflectionUtil;
26 import org.openhab.binding.mielecloud.internal.util.Website;
27 import org.openhab.core.config.core.Configuration;
28 import org.openhab.core.thing.Bridge;
29 import org.openhab.core.thing.ThingRegistry;
30 import org.openhab.core.thing.ThingStatus;
31 import org.openhab.core.thing.ThingStatusDetail;
32 import org.openhab.core.thing.ThingStatusInfo;
33 import org.openhab.core.thing.ThingUID;
36 * @author Björn Lange - Initial Contribution
39 public class AccountOverviewServletTest extends AbstractConfigFlowTest {
41 public void whenAccountOverviewServletIsCalledOverNonSslConnectionThenAWarningIsShown() throws Exception {
43 Website accountOverviewSite = getCrawler().doGetRelative("/mielecloud");
46 assertTrue(accountOverviewSite
47 .contains("Warning: We strongly advice to proceed only with SSL enabled for a secure data exchange."));
48 assertTrue(accountOverviewSite.contains(
49 "See <a href=\"https://www.openhab.org/docs/installation/security.html\">Securing access to openHAB</a> for details."));
53 public void whenAccountOverviewServletIsCalledAndNoBridgeIsPresentThenThePageSaysThatThereIsNoBridgePaired()
56 Website accountOverviewSite = getCrawler().doGetRelative("/mielecloud");
59 assertTrue(accountOverviewSite.contains("There is no account paired at the moment."));
63 public void whenAccountOverviewServletIsCalledAndBridgesArePresentThenThePageDisplaysInformationAboutThem()
66 Configuration configuration1 = mock(Configuration.class);
67 when(configuration1.get(MieleCloudBindingConstants.CONFIG_PARAM_LOCALE)).thenReturn("de");
68 when(configuration1.get(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL)).thenReturn("openhab@openhab.org");
70 Bridge bridge1 = mock(Bridge.class);
71 when(bridge1.getThingTypeUID()).thenReturn(MieleCloudBindingConstants.THING_TYPE_BRIDGE);
72 when(bridge1.getUID()).thenReturn(MieleCloudBindingIntegrationTestConstants.BRIDGE_THING_UID);
73 when(bridge1.getStatus()).thenReturn(ThingStatus.ONLINE);
74 when(bridge1.getStatusInfo()).thenReturn(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
75 when(bridge1.getConfiguration()).thenReturn(configuration1);
77 Configuration configuration2 = mock(Configuration.class);
78 when(configuration2.get(MieleCloudBindingConstants.CONFIG_PARAM_LOCALE)).thenReturn("en");
79 when(configuration2.get(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL)).thenReturn("everyone@openhab.org");
81 Bridge bridge2 = mock(Bridge.class);
82 when(bridge2.getThingTypeUID()).thenReturn(MieleCloudBindingConstants.THING_TYPE_BRIDGE);
83 when(bridge2.getUID()).thenReturn(new ThingUID(MieleCloudBindingConstants.THING_TYPE_BRIDGE, "test"));
84 when(bridge2.getStatus()).thenReturn(ThingStatus.OFFLINE);
85 when(bridge2.getStatusInfo()).thenReturn(
86 new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Error message"));
87 when(bridge2.getConfiguration()).thenReturn(configuration2);
89 ThingRegistry thingRegistry = mock(ThingRegistry.class);
90 when(thingRegistry.stream()).thenAnswer(invocation -> Stream.of(bridge1, bridge2));
91 ReflectionUtil.setPrivate(getAccountOverviewServlet(), "thingRegistry", thingRegistry);
94 Website accountOverviewSite = getCrawler().doGetRelative("/mielecloud");
97 assertTrue(accountOverviewSite.contains("The following bridges are paired"));
98 assertTrue(accountOverviewSite.contains("openhab@openhab.org"));
99 assertTrue(accountOverviewSite.contains("mielecloud:account:genesis"));
100 assertTrue(accountOverviewSite.contains("<span class=\"status online\">"));
101 assertTrue(accountOverviewSite.contains("everyone@openhab.org"));
102 assertTrue(accountOverviewSite.contains("mielecloud:account:test"));
103 assertTrue(accountOverviewSite.contains("<span class=\"status offline\">"));