Vidyashree Rama | 6160be1 | 2016-11-24 13:43:31 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Vidyashree Rama | 6160be1 | 2016-11-24 13:43:31 +0530 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.yms.app.yob; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.yang.gen.v1.ydt.bit.rev20160524.BitOpParam; |
| 21 | import org.onosproject.yms.app.ydt.YangRequestWorkBench; |
| 22 | import org.onosproject.yms.app.ydt.YdtExtendedContext; |
| 23 | import org.onosproject.yms.ydt.YdtContext; |
| 24 | import org.onosproject.yms.ydt.YmsOperationType; |
| 25 | |
| 26 | import java.io.IOException; |
| 27 | |
| 28 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 29 | import static org.hamcrest.MatcherAssert.assertThat; |
| 30 | import static org.hamcrest.Matchers.is; |
| 31 | import static org.onosproject.yms.app.yob.YobTestUtils.ROOT_DATA_RESOURCE; |
| 32 | |
| 33 | /** |
| 34 | * Test the YANG object building for the YDT based on the bits. |
| 35 | */ |
| 36 | public class YobBitTest { |
| 37 | |
| 38 | private YobTestUtils utils = YobTestUtils.instance(); |
| 39 | |
| 40 | @Test |
| 41 | public void testBitsInLeaf() throws IOException { |
| 42 | YangRequestWorkBench ydtBuilder = new YangRequestWorkBench( |
| 43 | ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true); |
| 44 | ydtBuilder.addChild("bit", "ydt.bit"); |
| 45 | ydtBuilder.addChild("bitList", null); |
| 46 | ydtBuilder.addLeaf("bit", null, "disable-nagle"); |
| 47 | ydtBuilder.traverseToParent(); |
| 48 | ydtBuilder.traverseToParent(); |
| 49 | ydtBuilder.addChild("bitList", null); |
| 50 | ydtBuilder.addLeaf("bit", null, "auto-sense-speed"); |
| 51 | ydtBuilder.traverseToParent(); |
| 52 | ydtBuilder.traverseToParent(); |
| 53 | ydtBuilder.addChild("bitList", null); |
| 54 | ydtBuilder.addLeaf("bit", null, "ten-Mb-only"); |
| 55 | ydtBuilder.traverseToParent(); |
| 56 | ydtBuilder.traverseToParent(); |
| 57 | ydtBuilder.traverseToParent(); |
| 58 | YdtContext rootCtx = ydtBuilder.getRootNode(); |
| 59 | YdtContext childCtx = rootCtx.getFirstChild(); |
| 60 | DefaultYobBuilder builder = new DefaultYobBuilder(); |
| 61 | Object yangObject = builder.getYangObject( |
| 62 | (YdtExtendedContext) childCtx, utils.schemaRegistry()); |
| 63 | assertThat(yangObject, notNullValue()); |
| 64 | BitOpParam bitOpParam = ((BitOpParam) yangObject); |
| 65 | |
| 66 | assertThat(bitOpParam.bitList().get(0).bit().get(0), is(true)); |
| 67 | assertThat(bitOpParam.bitList().get(0).bit().get(1), is(false)); |
| 68 | assertThat(bitOpParam.bitList().get(1).bit().get(0), is(false)); |
| 69 | assertThat(bitOpParam.bitList().get(1).bit().get(1), is(true)); |
| 70 | assertThat(bitOpParam.bitList().get(2).bit().get(0), is(false)); |
| 71 | assertThat(bitOpParam.bitList().get(2).bit().get(1), is(false)); |
| 72 | assertThat(bitOpParam.bitList().get(2).bit().get(2), is(true)); |
| 73 | assertThat(bitOpParam.bitList().get(2).bit().get(2), is(true)); |
| 74 | } |
| 75 | |
| 76 | @Test |
| 77 | public void testBitsInTypedef() throws IOException { |
| 78 | YangRequestWorkBench ydtBuilder = new YangRequestWorkBench( |
| 79 | ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true); |
| 80 | ydtBuilder.addChild("bit", "ydt.bit"); |
| 81 | ydtBuilder.addLeaf("name", null, "bit3"); |
| 82 | ydtBuilder.traverseToParent(); |
| 83 | ydtBuilder.traverseToParent(); |
| 84 | YdtContext rootCtx = ydtBuilder.getRootNode(); |
| 85 | YdtContext childCtx = rootCtx.getFirstChild(); |
| 86 | DefaultYobBuilder builder = new DefaultYobBuilder(); |
| 87 | Object yangObject = builder.getYangObject( |
| 88 | (YdtExtendedContext) childCtx, utils.schemaRegistry()); |
| 89 | assertThat(yangObject, notNullValue()); |
| 90 | BitOpParam bitOpParam = ((BitOpParam) yangObject); |
| 91 | |
| 92 | assertThat(bitOpParam.name().bits().get(0), is(false)); |
| 93 | assertThat(bitOpParam.name().bits().get(3), is(true)); |
| 94 | } |
| 95 | |
| 96 | @Test |
| 97 | public void testBitsQuery() throws IOException { |
| 98 | YangRequestWorkBench ydtBuilder = new YangRequestWorkBench( |
| 99 | ROOT_DATA_RESOURCE, null, YmsOperationType.QUERY_REQUEST, |
| 100 | utils.schemaRegistry(), true); |
| 101 | ydtBuilder.addChild("bit", "ydt.bit"); |
| 102 | ydtBuilder.addChild("name", "ydt.bit"); |
| 103 | ydtBuilder.traverseToParent(); |
| 104 | ydtBuilder.traverseToParent(); |
| 105 | YdtContext rootCtx = ydtBuilder.getRootNode(); |
| 106 | YdtContext childCtx = rootCtx.getFirstChild(); |
| 107 | DefaultYobBuilder builder = new DefaultYobBuilder(); |
| 108 | Object yangObject = builder.getYangObject( |
| 109 | (YdtExtendedContext) childCtx, utils.schemaRegistry()); |
| 110 | assertThat(yangObject, notNullValue()); |
| 111 | BitOpParam bitOpParam = ((BitOpParam) yangObject); |
| 112 | assertThat(bitOpParam.selectLeafFlags().get(1), is(true)); |
| 113 | } |
| 114 | } |