blob: c0cc522932e66b6c8adc039baec4abe2799c887c [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;
25import org.onosproject.d.config.DeviceResourceIds;
26import org.onosproject.net.DeviceId;
27import org.onosproject.yang.model.ResourceId;
28
29public class DeviceResourceIdsTest {
30
31 static final DeviceId DID_A = DeviceId.deviceId("test:A");
32
33 static final ResourceId DEVICES = ResourceId.builder()
34 .addBranchPointSchema(ROOT_NAME, DCS_NAMESPACE)
35 .addBranchPointSchema(DEVICES_NAME, DCS_NAMESPACE)
36 .build();
37
38 ResourceId ridA;
39 ResourceId ridAcopy;
40
41 @Before
42 public void setUp() throws Exception {
43 ridA = DeviceResourceIds.toResourceId(DID_A);
44 ridAcopy = ridA.copyBuilder().build();
45 }
46
47 @Test
48 public void testToDeviceId() throws CloneNotSupportedException {
49 ResourceId ridAchild = ridA.copyBuilder()
50 .addBranchPointSchema("some", "ns")
51 .addBranchPointSchema("random", "ns")
52 .addBranchPointSchema("child", "ns")
53 .build();
54
55 assertEquals(DID_A, DeviceResourceIds.toDeviceId(ridAchild));
56 }
57
58 @Test
59 public void testDeviceRootNode() {
60 assertTrue(DeviceResourceIds.isDeviceRootNode(ridA));
61
62 assertFalse(DeviceResourceIds.isRootOrDevicesNode(ridA));
63 }
64
65}