blob: 73f682cada556472a1de116427dbf8eaf4c46dad [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;
20
21import org.junit.Test;
22import org.onosproject.yang.model.ResourceId;
23
24public class ResourceIdsTest {
25
Yuta HIGUCHI5527e992017-08-08 18:11:17 -070026 static final ResourceId DEVICES = ResourceId.builder()
Yuta HIGUCHI24057822017-08-02 15:03:51 -070027 .addBranchPointSchema(DeviceResourceIds.ROOT_NAME, DCS_NAMESPACE)
28 .addBranchPointSchema(DeviceResourceIds.DEVICES_NAME, DCS_NAMESPACE)
29 .build();
30
31 @Test
32 public void testConcat() {
33 ResourceId devices = ResourceId.builder()
34 .addBranchPointSchema(DeviceResourceIds.DEVICES_NAME,
35 DCS_NAMESPACE)
36 .build();
37
38 assertEquals(DEVICES, ResourceIds.concat(DeviceResourceIds.ROOT_ID, devices));
39 }
40
41 @Test
42 public void testRelativize() {
43 ResourceId relDevices = ResourceIds.relativize(DeviceResourceIds.ROOT_ID, DEVICES);
44 assertEquals(DeviceResourceIds.DEVICES_NAME,
45 relDevices.nodeKeys().get(0).schemaId().name());
46 assertEquals(DCS_NAMESPACE,
47 relDevices.nodeKeys().get(0).schemaId().namespace());
48 assertEquals(1, relDevices.nodeKeys().size());
49 }
50
51 @Test
52 public void testRelativizeEmpty() {
53 ResourceId relDevices = ResourceIds.relativize(DEVICES, DEVICES);
54 // equivalent of . in file path, expressed as ResourceId with empty
55 assertTrue(relDevices.nodeKeys().isEmpty());
56
57 }
58}