]> git.basschouten.com Git - openhab-addons.git/blob
d751deeb80f8deb3b6096623306babb49794d47c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.bmwconnecteddrive.internal.handler;
14
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.Mockito.*;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.bmwconnecteddrive.internal.dto.NetworkError;
20 import org.openhab.binding.bmwconnecteddrive.internal.util.FileReader;
21 import org.openhab.binding.bmwconnecteddrive.internal.utils.Constants;
22 import org.openhab.core.io.net.http.HttpClientFactory;
23 import org.openhab.core.thing.Bridge;
24 import org.openhab.core.thing.ThingUID;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 /**
29  * The {@link FingerprintTest} Test Discovery Results
30  *
31  * @author Bernd Weymann - Initial contribution
32  */
33 @NonNullByDefault
34 public class FingerprintTest {
35     private final Logger logger = LoggerFactory.getLogger(FingerprintTest.class);
36
37     public void testDiscoveryFingerprint() {
38         Bridge b = mock(Bridge.class);
39         when(b.getUID()).thenReturn(new ThingUID("bmwconnecteddrive", "account", "user"));
40         HttpClientFactory hcf = mock(HttpClientFactory.class);
41         ConnectedDriveBridgeHandler bh = new ConnectedDriveBridgeHandler(b, hcf);
42         // when(bh.getThing()).thenReturn(b);
43
44         bh.onResponse(Constants.EMPTY_JSON);
45         assertEquals(Constants.EMPTY_JSON, bh.getDiscoveryFingerprint(), "Empty Response");
46
47         bh.onResponse(null);
48         assertEquals(Constants.EMPTY_JSON, bh.getDiscoveryFingerprint(), "Empty Response");
49
50         String content = FileReader.readFileInString("src/test/resources/webapi/connected-drive-account-info.json");
51         bh.onResponse(content);
52         String fingerprint = bh.getDiscoveryFingerprint();
53         logger.info("{}", fingerprint);
54         assertFalse(fingerprint.contains("My Real"), "Anonymous Fingerprint");
55         assertFalse(fingerprint.contains("MY_REAL_VIN"), "Anonymous Fingerprint");
56
57         NetworkError err = new NetworkError();
58         err.url = "Some URL";
59         err.status = 500;
60         err.reason = "Internal Server Error";
61         bh.onError(err);
62         assertEquals(err.toJson(), bh.getDiscoveryFingerprint(), "Empty Response");
63     }
64 }