]> git.basschouten.com Git - openhab-addons.git/blob
d582ecf3912e75f296f9b45a9743ea63704edbb9
[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.MatcherAssert.assertThat;
16 import static org.hamcrest.Matchers.emptyString;
17 import static org.hamcrest.core.Is.is;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.nest.internal.sdm.dto.SDMResourceName.SDMResourceNameType;
22
23 /**
24  * Tests the data provided by {@link org.openhab.binding.nest.internal.sdm.dto.SDMResourceName}
25  * based on resource name strings.
26  *
27  * @author Wouter Born - Initial contribution
28  */
29 @NonNullByDefault
30 public class SDMResourceNameTest {
31
32     @Test
33     public void nameless() {
34         SDMResourceName resourceName = SDMResourceName.NAMELESS;
35         assertThat(resourceName.name, is(emptyString()));
36         assertThat(resourceName.projectId, is(emptyString()));
37         assertThat(resourceName.deviceId, is(emptyString()));
38         assertThat(resourceName.structureId, is(emptyString()));
39         assertThat(resourceName.roomId, is(emptyString()));
40         assertThat(resourceName.type, is(SDMResourceNameType.UNKNOWN));
41     }
42
43     @Test
44     public void deviceName() {
45         String name = "enterprises/project-id/devices/device-id";
46
47         SDMResourceName resourceName = new SDMResourceName(name);
48         assertThat(resourceName.name, is(name));
49         assertThat(resourceName.projectId, is("project-id"));
50         assertThat(resourceName.deviceId, is("device-id"));
51         assertThat(resourceName.structureId, is(emptyString()));
52         assertThat(resourceName.roomId, is(emptyString()));
53         assertThat(resourceName.type, is(SDMResourceNameType.DEVICE));
54     }
55
56     @Test
57     public void structureName() {
58         String name = "enterprises/project-id/structures/structure-id";
59
60         SDMResourceName resourceName = new SDMResourceName(name);
61         assertThat(resourceName.name, is(name));
62         assertThat(resourceName.projectId, is("project-id"));
63         assertThat(resourceName.deviceId, is(emptyString()));
64         assertThat(resourceName.structureId, is("structure-id"));
65         assertThat(resourceName.roomId, is(emptyString()));
66         assertThat(resourceName.type, is(SDMResourceNameType.STRUCTURE));
67     }
68
69     @Test
70     public void roomName() {
71         String name = "enterprises/project-id/structures/structure-id/rooms/room-id";
72
73         SDMResourceName resourceName = new SDMResourceName(name);
74         assertThat(resourceName.name, is(name));
75         assertThat(resourceName.projectId, is("project-id"));
76         assertThat(resourceName.deviceId, is(emptyString()));
77         assertThat(resourceName.structureId, is("structure-id"));
78         assertThat(resourceName.roomId, is("room-id"));
79         assertThat(resourceName.type, is(SDMResourceNameType.ROOM));
80     }
81 }