]> git.basschouten.com Git - openhab-addons.git/blob
5a92c17e24bf0d25fad07846c184cc03223ec121
[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.SDMStructureInfoTrait;
27
28 /**
29  * Tests deserialization of {@link
30  * org.openhab.binding.nest.internal.sdm.dto.SDMListStructuresResponse}s from JSON.
31  *
32  * @author Wouter Born - Initial contribution
33  */
34 @NonNullByDefault
35 public class SDMListStructuresResponseTest {
36
37     @Test
38     public void deserializeListDevicesResponse() throws IOException {
39         SDMListStructuresResponse response = fromJson("list-structures-response.json", SDMListStructuresResponse.class);
40         assertThat(response, is(notNullValue()));
41
42         List<SDMStructure> structures = response.structures;
43         assertThat(structures, is(notNullValue()));
44         assertThat(structures, hasSize(2));
45
46         SDMStructure structure = structures.get(0);
47         assertThat(structure, is(notNullValue()));
48         assertThat(structure.name.name, is("enterprises/project-id/structures/beach-house-structure-id"));
49         SDMTraits traits = structure.traits;
50         assertThat(traits.traitList(), hasSize(1));
51         SDMStructureInfoTrait structureInfo = structure.traits.structureInfo;
52         assertThat(structureInfo, is(notNullValue()));
53         assertThat(structureInfo.customName, is("Beach House"));
54
55         structure = structures.get(1);
56         assertThat(structure, is(notNullValue()));
57         assertThat(structure.name.name, is("enterprises/project-id/structures/home-structure-id"));
58         traits = structure.traits;
59         assertThat(traits.traitList(), hasSize(1));
60         structureInfo = structure.traits.structureInfo;
61         assertThat(structureInfo, is(notNullValue()));
62         assertThat(structureInfo.customName, is("Home"));
63     }
64 }