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.MatcherAssert.assertThat;
16 import static org.hamcrest.Matchers.emptyString;
17 import static org.hamcrest.core.Is.is;
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;
24 * Tests the data provided by {@link org.openhab.binding.nest.internal.sdm.dto.SDMResourceName}
25 * based on resource name strings.
27 * @author Wouter Born - Initial contribution
30 public class SDMResourceNameTest {
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));
44 public void deviceName() {
45 String name = "enterprises/project-id/devices/device-id";
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));
57 public void structureName() {
58 String name = "enterprises/project-id/structures/structure-id";
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));
70 public void roomName() {
71 String name = "enterprises/project-id/structures/structure-id/rooms/room-id";
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));