blob: 565576f684343f9473b0f1c32354c953d29213c7 [file] [log] [blame]
Vidyashree Rama6160be12016-11-24 13:43:31 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Vidyashree Rama6160be12016-11-24 13:43:31 +05303 *
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
17package org.onosproject.yms.app.yob;
18
19import org.junit.Test;
20import org.onosproject.yang.gen.v1.ydt.bit.rev20160524.BitOpParam;
21import org.onosproject.yms.app.ydt.YangRequestWorkBench;
22import org.onosproject.yms.app.ydt.YdtExtendedContext;
23import org.onosproject.yms.ydt.YdtContext;
24import org.onosproject.yms.ydt.YmsOperationType;
25
26import java.io.IOException;
27
28import static org.hamcrest.CoreMatchers.notNullValue;
29import static org.hamcrest.MatcherAssert.assertThat;
30import static org.hamcrest.Matchers.is;
31import 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 */
36public 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}