blob: 83baf5a0d6f77bb731514f237cc51902df509ff6 [file] [log] [blame]
Yuta HIGUCHI24057822017-08-02 15:03:51 -07001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.d.config;
17
18import static org.junit.Assert.*;
19import static org.onosproject.d.config.DeviceResourceIds.DCS_NAMESPACE;
20import static org.onosproject.d.config.DeviceResourceIds.DEVICES_NAME;
21import static org.onosproject.d.config.DeviceResourceIds.ROOT_NAME;
22
23import org.junit.Before;
24import org.junit.Test;
Yuta HIGUCHI24057822017-08-02 15:03:51 -070025import org.onosproject.net.DeviceId;
26import org.onosproject.yang.model.ResourceId;
27
28public class DeviceResourceIdsTest {
29
30 static final DeviceId DID_A = DeviceId.deviceId("test:A");
31
32 static final ResourceId DEVICES = ResourceId.builder()
33 .addBranchPointSchema(ROOT_NAME, DCS_NAMESPACE)
34 .addBranchPointSchema(DEVICES_NAME, DCS_NAMESPACE)
35 .build();
36
37 ResourceId ridA;
38 ResourceId ridAcopy;
39
40 @Before
41 public void setUp() throws Exception {
42 ridA = DeviceResourceIds.toResourceId(DID_A);
43 ridAcopy = ridA.copyBuilder().build();
44 }
45
46 @Test
47 public void testToDeviceId() throws CloneNotSupportedException {
48 ResourceId ridAchild = ridA.copyBuilder()
49 .addBranchPointSchema("some", "ns")
50 .addBranchPointSchema("random", "ns")
51 .addBranchPointSchema("child", "ns")
52 .build();
53
54 assertEquals(DID_A, DeviceResourceIds.toDeviceId(ridAchild));
55 }
56
57 @Test
58 public void testDeviceRootNode() {
59 assertTrue(DeviceResourceIds.isDeviceRootNode(ridA));
60
61 assertFalse(DeviceResourceIds.isRootOrDevicesNode(ridA));
62 }
63
64}