Yuta HIGUCHI | 2405782 | 2017-08-02 15:03:51 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.d.config; |
| 17 | |
| 18 | import static org.junit.Assert.*; |
| 19 | import static org.onosproject.d.config.DeviceResourceIds.DCS_NAMESPACE; |
| 20 | |
| 21 | import org.junit.Test; |
| 22 | import org.onosproject.yang.model.ResourceId; |
| 23 | |
| 24 | public class ResourceIdsTest { |
| 25 | |
| 26 | final ResourceId DEVICES = ResourceId.builder() |
| 27 | .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 | } |