2 * Copyright (c) 2010-2023 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.nest.internal.sdm.dto;
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;
21 import java.io.IOException;
22 import java.util.List;
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;
29 * Tests deserialization of {@link
30 * org.openhab.binding.nest.internal.sdm.dto.SDMListStructuresResponse}s from JSON.
32 * @author Wouter Born - Initial contribution
35 public class SDMListStructuresResponseTest {
38 public void deserializeListDevicesResponse() throws IOException {
39 SDMListStructuresResponse response = fromJson("list-structures-response.json", SDMListStructuresResponse.class);
40 assertThat(response, is(notNullValue()));
42 List<SDMStructure> structures = response.structures;
43 assertThat(structures, is(notNullValue()));
44 assertThat(structures, hasSize(2));
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"));
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"));