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 | |
| 27 | import static org.junit.Assert.assertEquals; |
| 28 | import static org.junit.Assert.assertNotNull; |
| 29 | import static org.junit.Assert.fail; |
| 30 | |
| 31 | public class YobInteger32Test { |
| 32 | |
| 33 | /* |
| 34 | |
| 35 | Positive scenario |
| 36 | |
| 37 | input at boundary for integer |
| 38 | i. min value |
| 39 | ii. max value |
| 40 | |
| 41 | input at boundary for unsigned integer |
| 42 | i. min value |
| 43 | ii. max value |
| 44 | |
| 45 | input with in range |
| 46 | if range is 10 to 100 for integer |
| 47 | i.1. input 11 |
| 48 | i.2. min value 10 |
| 49 | i.3. max value 100 |
| 50 | |
| 51 | if range is 10 to 100 for unsigned integer |
| 52 | i.1. input 11 |
| 53 | i.2. min value 10 |
| 54 | i.3. max value 100 |
| 55 | |
| 56 | */ |
| 57 | @Test |
| 58 | public void positiveTest() { |
| 59 | YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.integer32Ydt(); |
| 60 | validateYangObject(defaultYdtBuilder); |
| 61 | } |
| 62 | |
| 63 | public void validateYangObject(YangRequestWorkBench defaultYdtBuilder) { |
| 64 | |
| 65 | YdtContext rootCtx = defaultYdtBuilder.getRootNode(); |
| 66 | |
| 67 | YdtContext childCtx = rootCtx.getFirstChild(); |
| 68 | |
| 69 | DefaultYobBuilder builder = new DefaultYobBuilder(); |
| 70 | |
| 71 | Object yangObject = builder.getYangObject( |
| 72 | (YdtExtendedContext) childCtx, YdtTestUtils |
| 73 | .getSchemaRegistry()); |
| 74 | assertNotNull(yangObject); |
| 75 | try { |
| 76 | Field negInt = yangObject.getClass().getDeclaredField("negInt"); |
| 77 | negInt.setAccessible(true); |
| 78 | assertEquals("-2147483648", negInt.get(yangObject).toString()); |
| 79 | Field posInt = yangObject.getClass().getDeclaredField("posInt"); |
| 80 | posInt.setAccessible(true); |
| 81 | assertEquals("2147483647", posInt.get(yangObject).toString()); |
| 82 | Field minIntWithRange = yangObject |
| 83 | .getClass().getDeclaredField("minIntWithRange"); |
| 84 | minIntWithRange.setAccessible(true); |
| 85 | assertEquals("10", minIntWithRange.get(yangObject).toString()); |
| 86 | Field midIntWithRange = yangObject |
| 87 | .getClass().getDeclaredField("midIntWithRange"); |
| 88 | midIntWithRange.setAccessible(true); |
| 89 | assertEquals("11", midIntWithRange.get(yangObject).toString()); |
| 90 | Field maxIntWithRange = yangObject |
| 91 | .getClass().getDeclaredField("maxIntWithRange"); |
| 92 | maxIntWithRange.setAccessible(true); |
| 93 | assertEquals("100", maxIntWithRange.get(yangObject).toString()); |
| 94 | Field minUint = yangObject.getClass().getDeclaredField("minUint"); |
| 95 | minUint.setAccessible(true); |
| 96 | assertEquals("0", minUint.get(yangObject).toString()); |
| 97 | Field maxUint = yangObject.getClass().getDeclaredField("maxUint"); |
| 98 | maxUint.setAccessible(true); |
| 99 | assertEquals("4294967295", maxUint.get(yangObject).toString()); |
| 100 | Field minUintWithRange = yangObject |
| 101 | .getClass().getDeclaredField("minUintWithRange"); |
| 102 | minUintWithRange.setAccessible(true); |
| 103 | assertEquals("10", minUintWithRange.get(yangObject).toString()); |
| 104 | Field midUintWithRange = yangObject |
| 105 | .getClass().getDeclaredField("midUintWithRange"); |
| 106 | midUintWithRange.setAccessible(true); |
| 107 | assertEquals("11", midUintWithRange.get(yangObject).toString()); |
| 108 | Field maxUintWithRange = yangObject |
| 109 | .getClass().getDeclaredField("maxUintWithRange"); |
| 110 | maxUintWithRange.setAccessible(true); |
| 111 | assertEquals("100", maxUintWithRange.get(yangObject).toString()); |
| 112 | } catch (NoSuchFieldException | IllegalAccessException e) { |
| 113 | fail("No such field or illegal access exception: " + e); |
| 114 | } |
| 115 | } |
| 116 | } |