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.Assert; |
| 20 | import org.junit.Test; |
| 21 | import org.onosproject.yms.app.ydt.YdtTestUtils; |
| 22 | import org.onosproject.yms.app.ydt.YangRequestWorkBench; |
| 23 | import org.onosproject.yms.app.ydt.YdtExtendedContext; |
| 24 | import org.onosproject.yms.ydt.YdtContext; |
| 25 | |
| 26 | import java.lang.reflect.Field; |
| 27 | |
| 28 | import static org.junit.Assert.assertEquals; |
| 29 | import static org.junit.Assert.assertNotNull; |
| 30 | |
| 31 | public class YobInteger8Test { |
| 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 | input with multi interval range |
| 57 | if range is 10..40 | 50..100 for integer |
| 58 | i.1. input 11 |
| 59 | i.2. input 10 |
| 60 | i.3. input 40 |
| 61 | i.4. input 50 |
| 62 | i.5. input 55 |
| 63 | i.6. input 100 |
| 64 | |
| 65 | if range is 10..40 | 50..100 for unsigned integer |
| 66 | i.1. input 11 |
| 67 | i.2. input 10 |
| 68 | i.3. input 40 |
| 69 | i.4. input 50 |
| 70 | i.5. input 55 |
| 71 | i.6. input 100 |
| 72 | |
| 73 | if range is "min .. 2 | 10 | 20..max" for integer |
| 74 | i.1. input -128 |
| 75 | i.2. input 1 |
| 76 | i.3. input 2 |
| 77 | i.4. input 10 |
| 78 | i.5. input 20 |
| 79 | i.6. input 100 |
| 80 | i.7. input 127 |
| 81 | |
| 82 | if range is "min .. 2 | 10 | 20..max" for unsigned Integer |
| 83 | i.1. input 0 |
| 84 | i.2. input 1 |
| 85 | i.3. input 2 |
| 86 | i.4. input 10 |
| 87 | i.5. input 20 |
| 88 | i.6. input 100 |
| 89 | i.7. input 255 |
| 90 | */ |
| 91 | @Test |
| 92 | public void positiveTest() { |
| 93 | YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.integer8Ydt(); |
| 94 | validateYangObject(defaultYdtBuilder); |
| 95 | } |
| 96 | |
| 97 | private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) { |
| 98 | |
| 99 | YdtContext rootCtx = defaultYdtBuilder.getRootNode(); |
| 100 | |
| 101 | YdtContext childCtx = rootCtx.getFirstChild(); |
| 102 | |
| 103 | DefaultYobBuilder builder = new DefaultYobBuilder(); |
| 104 | |
| 105 | Object yangObject = builder.getYangObject( |
| 106 | (YdtExtendedContext) childCtx, YdtTestUtils |
| 107 | .getSchemaRegistry()); |
| 108 | assertNotNull(yangObject); |
| 109 | try { |
| 110 | Field negInt = yangObject.getClass().getDeclaredField("negInt"); |
| 111 | negInt.setAccessible(true); |
| 112 | assertEquals("-128", negInt.get(yangObject).toString()); |
| 113 | Field posInt = yangObject.getClass().getDeclaredField("posInt"); |
| 114 | posInt.setAccessible(true); |
| 115 | assertEquals("127", posInt.get(yangObject).toString()); |
| 116 | Field minIntWithRange = yangObject |
| 117 | .getClass().getDeclaredField("minIntWithRange"); |
| 118 | minIntWithRange.setAccessible(true); |
| 119 | assertEquals("10", minIntWithRange |
| 120 | .get(yangObject).toString()); |
| 121 | Field midIntWithRange = yangObject |
| 122 | .getClass().getDeclaredField("midIntWithRange"); |
| 123 | midIntWithRange.setAccessible(true); |
| 124 | assertEquals("11", midIntWithRange |
| 125 | .get(yangObject).toString()); |
| 126 | Field maxIntWithRange = yangObject |
| 127 | .getClass().getDeclaredField("maxIntWithRange"); |
| 128 | maxIntWithRange.setAccessible(true); |
| 129 | assertEquals("100", maxIntWithRange.get(yangObject).toString()); |
| 130 | Field minUint = yangObject.getClass().getDeclaredField("minUint"); |
| 131 | minUint.setAccessible(true); |
| 132 | assertEquals("0", minUint.get(yangObject).toString()); |
| 133 | Field maxUint = yangObject.getClass().getDeclaredField("maxUint"); |
| 134 | maxUint.setAccessible(true); |
| 135 | assertEquals("255", maxUint.get(yangObject).toString()); |
| 136 | Field minUintWithRange = yangObject |
| 137 | .getClass().getDeclaredField("maxIntWithRange"); |
| 138 | minUintWithRange.setAccessible(true); |
| 139 | assertEquals("100", minUintWithRange.get(yangObject).toString()); |
| 140 | Field midUintWithRange = yangObject |
| 141 | .getClass().getDeclaredField("midUintWithRange"); |
| 142 | midUintWithRange.setAccessible(true); |
| 143 | assertEquals("11", midUintWithRange.get(yangObject).toString()); |
| 144 | Field maxUintWithRange = yangObject |
| 145 | .getClass().getDeclaredField("maxUintWithRange"); |
| 146 | maxUintWithRange.setAccessible(true); |
| 147 | assertEquals("100", maxUintWithRange.get(yangObject).toString()); |
| 148 | } catch (IllegalAccessException | NoSuchFieldException e) { |
| 149 | Assert.fail(); |
| 150 | } |
| 151 | } |
| 152 | } |