]> git.basschouten.com Git - openhab-addons.git/blob
81e794eeedec7b19a1b1ad743d78917f4878826f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.mercedesme.internal.handler;
14
15 import static org.mockito.Mockito.mock;
16
17 import java.util.Locale;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.eclipse.jetty.client.HttpClient;
22 import org.eclipse.jetty.websocket.api.Session;
23 import org.json.JSONObject;
24 import org.openhab.binding.mercedesme.internal.Constants;
25 import org.openhab.binding.mercedesme.internal.config.AccountConfiguration;
26 import org.openhab.binding.mercedesme.internal.discovery.MercedesMeDiscoveryService;
27 import org.openhab.core.i18n.LocaleProvider;
28 import org.openhab.core.net.NetworkAddressService;
29 import org.openhab.core.storage.Storage;
30 import org.openhab.core.storage.StorageService;
31 import org.openhab.core.test.storage.VolatileStorageService;
32 import org.openhab.core.thing.Bridge;
33
34 import com.daimler.mbcarkit.proto.Client.ClientMessage;
35
36 /**
37  * {@link AccountHandlerMock} to retrieve and collect commands from {@link VehicleHandler}
38  *
39  * @author Bernd Weymann - Initial contribution
40  */
41 @NonNullByDefault
42 public class AccountHandlerMock extends AccountHandler {
43     private static VolatileStorageService storageService = new VolatileStorageService();
44     private static LocaleProvider localeProvider = new LocaleProvider() {
45
46         @Override
47         public Locale getLocale() {
48             return Locale.getDefault();
49         }
50     };
51
52     JSONObject command = new JSONObject();
53
54     public AccountHandlerMock() {
55         super(mock(Bridge.class), mock(MercedesMeDiscoveryService.class), mock(HttpClient.class),
56                 mock(LocaleProvider.class), mock(StorageService.class), mock(NetworkAddressService.class));
57     }
58
59     public AccountHandlerMock(Bridge b, @Nullable String storedObject) {
60         super(b, mock(MercedesMeDiscoveryService.class), mock(HttpClient.class), localeProvider, storageService,
61                 mock(NetworkAddressService.class));
62         if (storedObject != null) {
63             Storage<String> storage = storageService.getStorage(Constants.BINDING_ID);
64             storage.put("a@b.c", storedObject);
65         }
66     }
67
68     @Override
69     public void registerVin(String vin, VehicleHandler handler) {
70     }
71
72     @Override
73     public void getVehicleCapabilities(String vin) {
74     }
75
76     @Override
77     public void sendCommand(@Nullable ClientMessage cm) {
78         if (cm != null) {
79             command = ProtoConverter.clientMessage2Json(cm);
80         }
81     }
82
83     public AccountConfiguration getConfigT() {
84         return new AccountConfiguration();
85     }
86
87     public JSONObject getCommand() {
88         return command;
89     }
90
91     public void connect() {
92         super.ws.onConnect(mock(Session.class));
93     }
94 }