Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.yms.app.yob; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.yms.app.ydt.YangRequestWorkBench; |
| 21 | import org.onosproject.yms.app.ydt.YdtExtendedContext; |
| 22 | import org.onosproject.yms.app.ydt.YdtTestUtils; |
| 23 | import org.onosproject.yms.ydt.YdtContext; |
| 24 | |
| 25 | import java.lang.reflect.Field; |
| 26 | import java.util.List; |
| 27 | |
| 28 | import static org.junit.Assert.assertFalse; |
| 29 | import static org.junit.Assert.assertNotNull; |
| 30 | import static org.junit.Assert.assertTrue; |
| 31 | import static org.junit.Assert.fail; |
| 32 | |
| 33 | public class YobBooleanTest { |
| 34 | |
| 35 | private static final String BOOLEAN_LIST = "booleanList"; |
| 36 | private static final String AUTO_PREFIX_BOOLEAN = "yangAutoPrefixBoolean"; |
| 37 | |
| 38 | /* |
| 39 | BOOLEAN |
| 40 | Positive scenario |
| 41 | input with in true and false |
| 42 | */ |
| 43 | @Test |
| 44 | public void positiveTest() { |
| 45 | YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.booleanYdt(); |
| 46 | validateYangObject(defaultYdtBuilder); |
| 47 | } |
| 48 | |
| 49 | private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) { |
| 50 | |
| 51 | YdtContext rootCtx = defaultYdtBuilder.getRootNode(); |
| 52 | |
| 53 | YdtContext childCtx = rootCtx.getFirstChild(); |
| 54 | |
| 55 | DefaultYobBuilder builder = new DefaultYobBuilder(); |
| 56 | |
| 57 | Object yangObject = builder.getYangObject( |
| 58 | (YdtExtendedContext) childCtx, YdtTestUtils |
| 59 | .getSchemaRegistry()); |
| 60 | assertNotNull(yangObject); |
| 61 | try { |
| 62 | |
| 63 | Field field = yangObject.getClass().getDeclaredField(BOOLEAN_LIST); |
| 64 | field.setAccessible(true); |
| 65 | List booleanList = (List) field.get(yangObject); |
| 66 | Field invalidInterval = booleanList.get(0).getClass() |
| 67 | .getDeclaredField(AUTO_PREFIX_BOOLEAN); |
| 68 | invalidInterval.setAccessible(true); |
| 69 | assertTrue((boolean) invalidInterval.get(booleanList.get(0))); |
| 70 | assertFalse((boolean) invalidInterval.get(booleanList.get(1))); |
| 71 | } catch (NoSuchFieldException | IllegalAccessException e) { |
| 72 | fail("No such field or illegal access exception: " + e); |
| 73 | } |
| 74 | } |
| 75 | } |