2 * Copyright (c) 2010-2021 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.bmwconnecteddrive.internal.handler;
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.Mockito.*;
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;
29 * The {@link FingerprintTest} Test Discovery Results
31 * @author Bernd Weymann - Initial contribution
34 public class FingerprintTest {
35 private final Logger logger = LoggerFactory.getLogger(FingerprintTest.class);
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);
44 bh.onResponse(Constants.EMPTY_JSON);
45 assertEquals(Constants.EMPTY_JSON, bh.getDiscoveryFingerprint(), "Empty Response");
48 assertEquals(Constants.EMPTY_JSON, bh.getDiscoveryFingerprint(), "Empty Response");
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");
57 NetworkError err = new NetworkError();
60 err.reason = "Internal Server Error";
62 assertEquals(err.toJson(), bh.getDiscoveryFingerprint(), "Empty Response");