]> git.basschouten.com Git - openhab-addons.git/blob
6d697c68063f1ad217c92f2ceeca834284147bd5
[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.nest.internal.sdm.dto;
14
15 import static org.hamcrest.CoreMatchers.notNullValue;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
18 import static org.hamcrest.core.Is.is;
19 import static org.openhab.binding.nest.internal.sdm.dto.SDMDataUtil.fromJson;
20
21 import java.io.IOException;
22 import java.util.List;
23
24 import org.eclipse.jdt.annotation.NonNullByDefault;
25 import org.junit.jupiter.api.Test;
26 import org.openhab.binding.nest.internal.sdm.dto.SDMTraits.SDMRoomInfoTrait;
27
28 /**
29  * Tests deserialization of {@link org.openhab.binding.nest.internal.sdm.dto.SDMListRoomsResponse}s
30  * from JSON.
31  *
32  * @author Wouter Born - Initial contribution
33  */
34 @NonNullByDefault
35 public class SDMListRoomsResponseTest {
36
37     @Test
38     public void deserializeListDevicesResponse() throws IOException {
39         SDMListRoomsResponse response = fromJson("list-rooms-response.json", SDMListRoomsResponse.class);
40         assertThat(response, is(notNullValue()));
41
42         List<SDMRoom> rooms = response.rooms;
43         assertThat(rooms, is(notNullValue()));
44         assertThat(rooms, hasSize(2));
45
46         SDMRoom room = rooms.get(0);
47         assertThat(room, is(notNullValue()));
48         assertThat(room.name.name, is("enterprises/project-id/structures/structure-id/rooms/kitchen-room-id"));
49         SDMTraits traits = room.traits;
50         assertThat(traits.traitList(), hasSize(1));
51         SDMRoomInfoTrait roomInfo = room.traits.roomInfo;
52         assertThat(roomInfo, is(notNullValue()));
53         assertThat(roomInfo.customName, is("Kitchen"));
54
55         room = rooms.get(1);
56         assertThat(room, is(notNullValue()));
57         assertThat(room.name.name, is("enterprises/project-id/structures/structure-id/rooms/living-room-id"));
58         traits = room.traits;
59         assertThat(traits.traitList(), hasSize(1));
60         roomInfo = room.traits.roomInfo;
61         assertThat(roomInfo, is(notNullValue()));
62         assertThat(roomInfo.customName, is("Living"));
63     }
64 }