blob: 019d958497db3ec43b8cc2e98a317f21d27a68e8 [file] [log] [blame]
janani b05614f12016-10-04 12:55:43 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
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
17package org.onosproject.yms.app.ytb;
18
19import org.junit.Test;
20import org.onosproject.yang.gen.v1.yms.test.ytb.simple.rpc.response.rev20160826.YtbSimpleRpcResponse;
21import org.onosproject.yang.gen.v1.yms.test.ytb.simple.rpc.response.rev20160826.YtbSimpleRpcResponseOpParam;
22import org.onosproject.yang.gen.v1.yms.test.ytb.simple.rpc.response.rev20160826.ytbsimplerpcresponse.Cumulative;
23import org.onosproject.yang.gen.v1.yms.test.ytb.simple.rpc.response.rev20160826.ytbsimplerpcresponse.DefaultCumulative;
24import org.onosproject.yms.app.ydt.YdtExtendedBuilder;
25import org.onosproject.yms.app.ysr.DefaultYangSchemaRegistry;
26import org.onosproject.yms.ydt.YdtContext;
27
28import java.util.ArrayList;
29import java.util.List;
30
31import static org.hamcrest.MatcherAssert.assertThat;
32import static org.hamcrest.core.Is.is;
33import static org.onosproject.yms.ydt.YmsOperationType.EDIT_CONFIG_REQUEST;
34
35/**
36 * Unit test cases for invalid node skip in YANG tree builder.
37 */
38public class YtbInvalidNodeSkipTest extends YtbErrMsgAndConstants {
39
40 private static final String CUMULATIVE = "cumulative";
41 private static final String SUM = "sum";
42 private static final String FIVE = "5";
43 private static final String TEN = "10";
44
45 /**
46 * Processes RPC node which is the sibling to the empty current node.
47 */
48 @Test
49 public void processRpcSiblingWhenNodeIsEmpty() {
50
51 schemaProvider.processSchemaRegistry(null);
52 DefaultYangSchemaRegistry registry = schemaProvider
53 .getDefaultYangSchemaRegistry();
54
55 // As an application, creates the object.
56 Cumulative cumulative1 = new DefaultCumulative.CumulativeBuilder()
57 .sum((byte) 5).build();
58 Cumulative cumulative2 = new DefaultCumulative.CumulativeBuilder()
59 .sum((byte) 10).build();
60 List<Cumulative> list = new ArrayList<>();
61 list.add(cumulative1);
62 list.add(cumulative2);
63 YtbSimpleRpcResponse rpc = new YtbSimpleRpcResponseOpParam
64 .YtbSimpleRpcResponseBuilder().cumulative(list).build();
65
66 // As YSB or YAB protocol sets the value for YTB.
67 List<Object> objectList = new ArrayList<>();
68 objectList.add(rpc);
69
70 // Builds YANG tree in YTB.
71 DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder();
72 YdtExtendedBuilder ydtBuilder = treeBuilder.getYdtBuilderForYo(
73 objectList, ROOT_NAME, ROOT_NAME_SPACE,
74 EDIT_CONFIG_REQUEST, registry);
75
76 // Receives YDT context and checks the tree that is built.
77 YdtContext context = ydtBuilder.getRootNode();
78
79 // Gets the first module from logical root node.
80 YdtContext module = context.getFirstChild();
81 assertThat(getInCrtName(MODULE, RPC_NAME), module.getName(),
82 is(RPC_NAME));
83
84 // Gets the first list content of cumulative.
85 YdtContext list1 = module.getFirstChild();
86 assertThat(getInCrtName(LIST, CUMULATIVE), list1.getName(),
87 is(CUMULATIVE));
88
89 YdtContext sum1 = list1.getFirstChild();
90 assertThat(getInCrtName(LEAF, SUM), sum1.getName(), is(SUM));
91 assertThat(getInCrtLeafValue(SUM, FIVE), sum1.getValue(), is(FIVE));
92
93 // Gets the second list content of cumulative.
94 YdtContext list2 = list1.getNextSibling();
95 assertThat(getInCrtName(LIST, CUMULATIVE), list2.getName(),
96 is(CUMULATIVE));
97
98 YdtContext sum2 = list2.getFirstChild();
99 assertThat(getInCrtName(LEAF, SUM), sum2.getName(), is(SUM));
100 assertThat(getInCrtLeafValue(SUM, TEN), sum2.getValue(), is(TEN));
101 }
102
103
104}