]> git.basschouten.com Git - openhab-addons.git/blob
233214303b07f384c91789a7b97c84817a9bb2ad
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.netatmo.internal.api.dto;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.mockito.Mockito.*;
17
18 import java.time.ZoneId;
19
20 import org.junit.jupiter.api.BeforeAll;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.netatmo.internal.api.NetatmoException;
23 import org.openhab.binding.netatmo.internal.api.data.EventType;
24 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.TrendDescription;
25 import org.openhab.binding.netatmo.internal.deserialization.NADeserializer;
26 import org.openhab.core.i18n.TimeZoneProvider;
27
28 /**
29  * @author GaĆ«l L'hopital - Initial contribution
30  */
31 public class NAObjectTest {
32     private static NADeserializer gson;
33
34     @BeforeAll
35     public static void init() {
36         TimeZoneProvider timeZoneProvider = mock(TimeZoneProvider.class);
37         when(timeZoneProvider.getTimeZone()).thenReturn(ZoneId.systemDefault());
38         gson = new NADeserializer(timeZoneProvider);
39     }
40
41     @Test
42     public void testNAObject() throws Exception {
43         String naObject = "{id:\"5954e7f249c75f97428b7b23\",name:\"Your House\"}";
44         NAObject object = gson.deserialize(NAObject.class, naObject);
45         assertEquals(object.getName(), "Your House");
46         assertEquals(object.getId(), "5954e7f249c75f97428b7b23");
47     }
48
49     @Test
50     public void testWebHookEvent() throws NetatmoException {
51         String event = "{" + "  \"user_id\": \"5c810xxxxxxx45f4\"," + "  \"snapshot_id\": \"5d19bxxxxxx6380342\","
52                 + "  \"snapshot_key\": \"f0134210ff83fxxxxxxxf770090a423d9a5\","
53                 + "  \"snapshot_url\": \"https://netatmocameraimage.blob.core.windows.net/production/5d1xxxa5\","
54                 + "  \"event_type\": \"movement\"," + "  \"camera_id\": \"70:exxxxxdd:a7\","
55                 + "  \"device_id\": \"70:exxxxdd:a7\"," + "  \"home_id\": \"5c5d79xxxx08cd594\","
56                 + "  \"home_name\": \"Boulogne Billan.\"," + "  \"event_id\": \"5d19baae369359e896380341\","
57                 + "  \"message\": \"Boulogne Billan: Movement detected by Indoor Camera\","
58                 + "  \"push_type\": \"NACamera-movement\"" + "}";
59         WebhookEvent object = gson.deserialize(WebhookEvent.class, event);
60         assertEquals(object.getEventType(), EventType.MOVEMENT);
61     }
62
63     @Test
64     public void testDashboardData() throws NetatmoException {
65         String dashboard = "{time_utc:1623160336,Temperature:22.1,CO2:511,"
66                 + "Humidity:66,Noise:36,Pressure:1026.1,AbsolutePressure:1009.3,"
67                 + "min_temp:20,max_temp:22.4,date_max_temp:1623147932,"
68                 + "Sdate_min_temp:1623125249,pressure_trend:\"nonexistent\",temp_trend:\"stable\"}";
69         Dashboard object = gson.deserialize(Dashboard.class, dashboard);
70         assertEquals(511, object.getCo2(), 0);
71         assertEquals(TrendDescription.UNKNOWN, object.getPressureTrend());
72         assertEquals(TrendDescription.STABLE, object.getTempTrend());
73     }
74 }