sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +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.ydt; |
| 18 | |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame^] | 19 | import org.junit.Rule; |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 20 | import org.junit.Test; |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame^] | 21 | import org.junit.rules.ExpectedException; |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 22 | import org.onosproject.yms.app.ydt.exceptions.YdtException; |
| 23 | |
| 24 | import static org.onosproject.yms.app.ydt.YdtTestConstants.A; |
| 25 | import static org.onosproject.yms.app.ydt.YdtTestConstants.B; |
| 26 | import static org.onosproject.yms.app.ydt.YdtTestConstants.C; |
| 27 | import static org.onosproject.yms.app.ydt.YdtTestConstants.E; |
| 28 | import static org.onosproject.yms.app.ydt.YdtTestConstants.F; |
| 29 | import static org.onosproject.yms.app.ydt.YdtTestConstants.G; |
| 30 | import static org.onosproject.yms.app.ydt.YdtTestConstants.H; |
| 31 | import static org.onosproject.yms.app.ydt.YdtTestConstants.MAXIWR; |
| 32 | import static org.onosproject.yms.app.ydt.YdtTestConstants.MIDIWR; |
| 33 | import static org.onosproject.yms.app.ydt.YdtTestConstants.MINIWR; |
| 34 | import static org.onosproject.yms.app.ydt.YdtTestConstants.MRV; |
| 35 | import static org.onosproject.yms.app.ydt.YdtTestConstants.NIWMF; |
| 36 | import static org.onosproject.yms.app.ydt.YdtTestConstants.NWF; |
| 37 | import static org.onosproject.yms.app.ydt.YdtTestConstants.PIWMF; |
| 38 | import static org.onosproject.yms.app.ydt.YdtTestConstants.PWF; |
| 39 | import static org.onosproject.yms.app.ydt.YdtTestConstants.TYPE; |
| 40 | import static org.onosproject.yms.app.ydt.YdtTestUtils.decimal64Ydt; |
| 41 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents; |
| 42 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents; |
| 43 | import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE; |
| 44 | |
| 45 | public class YdtDecimal64Test { |
| 46 | |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame^] | 47 | @Rule |
| 48 | public ExpectedException thrown = ExpectedException.none(); |
| 49 | |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 50 | /* |
| 51 | |
| 52 | Positive scenario |
| 53 | |
| 54 | input at boundry for decimal64 with fraction 2 |
| 55 | i. min value |
| 56 | ii. max value |
| 57 | |
| 58 | input at boundry for decimal64 with minimum fraction |
| 59 | i. min value |
| 60 | ii. mid value |
| 61 | iii. max value |
| 62 | |
| 63 | input at boundry for decimal64 with maximum fraction |
| 64 | i. min value |
| 65 | ii. mid value |
| 66 | iii. max value |
| 67 | |
| 68 | input with in range |
| 69 | if range is 10 to 100 for integer |
| 70 | i.1. input 11 |
| 71 | i.2. min value 10 |
| 72 | i.3. max value 100 |
| 73 | |
| 74 | input with multi interval range |
| 75 | if range is 10..40 | 50..100 for decimal64 |
| 76 | i.1. input 11 |
| 77 | i.2. input 10 |
| 78 | i.3. input 40 |
| 79 | i.4. input 50 |
| 80 | i.5. input 55 |
| 81 | i.6. input 100 |
| 82 | |
| 83 | if range is "min .. 3.14 | 10 | 20..max" for decimal64 |
| 84 | i.1. input min |
| 85 | i.2. input 2.505 |
| 86 | i.3. input 3.14 |
| 87 | i.4. input 10 |
| 88 | i.5. input 20 |
| 89 | i.6. input 92233720368547757 |
| 90 | i.7. input 92233720368547758.07 |
| 91 | |
| 92 | */ |
| 93 | |
| 94 | /** |
| 95 | * Creates and validates decimal64 ydt covering different positive scenario. |
| 96 | */ |
| 97 | @Test |
| 98 | public void positiveTest() throws YdtException { |
| 99 | YangRequestWorkBench ydtBuilder = decimal64Ydt(); |
| 100 | validateTree(ydtBuilder); |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame^] | 101 | |
| 102 | //TODO need to be handled later |
| 103 | // YangRequestWorkBench sbiYdt = validateYangObject( |
| 104 | // ydtBuilder, "builtInType", "ydt.decimal64"); |
| 105 | // validateTree(sbiYdt); |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Validates the given built ydt. |
| 110 | */ |
| 111 | private void validateTree(YangRequestWorkBench ydtBuilder) { |
| 112 | |
| 113 | // assign root node to ydtNode for validating purpose. |
| 114 | YdtNode ydtNode = (YdtNode) ydtBuilder.getRootNode(); |
| 115 | // Logical root node does not have operation type |
| 116 | validateNodeContents(ydtNode, TYPE, null); |
| 117 | |
| 118 | ydtNode = ydtNode.getFirstChild(); |
| 119 | validateNodeContents(ydtNode, "decimal64", MERGE); |
| 120 | ydtNode = ydtNode.getFirstChild(); |
| 121 | validateLeafContents(ydtNode, "negInt", C); |
| 122 | ydtNode = ydtNode.getNextSibling(); |
| 123 | validateLeafContents(ydtNode, "posInt", A); |
| 124 | ydtNode = ydtNode.getNextSibling(); |
| 125 | validateLeafContents(ydtNode, NIWMF, F); |
| 126 | ydtNode = ydtNode.getNextSibling(); |
| 127 | validateLeafContents(ydtNode, PIWMF, G); |
| 128 | ydtNode = ydtNode.getNextSibling(); |
| 129 | validateLeafContents(ydtNode, NWF, H); |
| 130 | ydtNode = ydtNode.getNextSibling(); |
| 131 | validateLeafContents(ydtNode, PWF, E); |
| 132 | ydtNode = ydtNode.getNextSibling(); |
| 133 | validateLeafContents(ydtNode, MIDIWR, "11"); |
| 134 | ydtNode = ydtNode.getNextSibling(); |
| 135 | validateLeafContents(ydtNode, MINIWR, "10"); |
| 136 | ydtNode = ydtNode.getNextSibling(); |
| 137 | validateLeafContents(ydtNode, MAXIWR, "100"); |
| 138 | ydtNode = ydtNode.getNextSibling(); |
| 139 | validateNodeContents(ydtNode, MRV, MERGE); |
| 140 | ydtNode = ydtNode.getFirstChild(); |
| 141 | validateLeafContents(ydtNode, "decimal", "11"); |
| 142 | ydtNode = ydtNode.getParent(); |
| 143 | ydtNode = ydtNode.getNextSibling(); |
| 144 | validateNodeContents(ydtNode, MRV, MERGE); |
| 145 | ydtNode = ydtNode.getFirstChild(); |
| 146 | validateLeafContents(ydtNode, "decimal", "10"); |
| 147 | ydtNode = ydtNode.getParent(); |
| 148 | ydtNode = ydtNode.getNextSibling(); |
| 149 | validateNodeContents(ydtNode, MRV, MERGE); |
| 150 | ydtNode = ydtNode.getFirstChild(); |
| 151 | validateLeafContents(ydtNode, "decimal", "40"); |
| 152 | ydtNode = ydtNode.getParent(); |
| 153 | ydtNode = ydtNode.getNextSibling(); |
| 154 | validateNodeContents(ydtNode, MRV, MERGE); |
| 155 | ydtNode = ydtNode.getFirstChild(); |
| 156 | validateLeafContents(ydtNode, "decimal", "50"); |
| 157 | ydtNode = ydtNode.getParent(); |
| 158 | ydtNode = ydtNode.getNextSibling(); |
| 159 | validateNodeContents(ydtNode, MRV, MERGE); |
| 160 | ydtNode = ydtNode.getFirstChild(); |
| 161 | validateLeafContents(ydtNode, "decimal", "55"); |
| 162 | ydtNode = ydtNode.getParent(); |
| 163 | ydtNode = ydtNode.getNextSibling(); |
| 164 | validateNodeContents(ydtNode, MRV, MERGE); |
| 165 | ydtNode = ydtNode.getFirstChild(); |
| 166 | validateLeafContents(ydtNode, "decimal", "100"); |
| 167 | ydtNode = ydtNode.getParent(); |
| 168 | ydtNode = ydtNode.getNextSibling(); |
| 169 | validateNodeContents(ydtNode, MRV, MERGE); |
| 170 | ydtNode = ydtNode.getFirstChild(); |
| 171 | validateLeafContents(ydtNode, "revDecimal", C); |
| 172 | ydtNode = ydtNode.getParent(); |
| 173 | ydtNode = ydtNode.getNextSibling(); |
| 174 | validateNodeContents(ydtNode, MRV, MERGE); |
| 175 | ydtNode = ydtNode.getFirstChild(); |
| 176 | validateLeafContents(ydtNode, "revDecimal", "2.505"); |
| 177 | ydtNode = ydtNode.getParent(); |
| 178 | ydtNode = ydtNode.getNextSibling(); |
| 179 | validateNodeContents(ydtNode, MRV, MERGE); |
| 180 | ydtNode = ydtNode.getFirstChild(); |
| 181 | validateLeafContents(ydtNode, "revDecimal", "3.14"); |
| 182 | ydtNode = ydtNode.getParent(); |
| 183 | ydtNode = ydtNode.getNextSibling(); |
| 184 | validateNodeContents(ydtNode, MRV, MERGE); |
| 185 | ydtNode = ydtNode.getFirstChild(); |
| 186 | validateLeafContents(ydtNode, "revDecimal", "10"); |
| 187 | ydtNode = ydtNode.getParent(); |
| 188 | ydtNode = ydtNode.getNextSibling(); |
| 189 | validateNodeContents(ydtNode, MRV, MERGE); |
| 190 | ydtNode = ydtNode.getFirstChild(); |
| 191 | validateLeafContents(ydtNode, "revDecimal", "20"); |
| 192 | ydtNode = ydtNode.getParent(); |
| 193 | ydtNode = ydtNode.getNextSibling(); |
| 194 | validateNodeContents(ydtNode, MRV, MERGE); |
| 195 | ydtNode = ydtNode.getFirstChild(); |
| 196 | validateLeafContents(ydtNode, "revDecimal", B); |
| 197 | ydtNode = ydtNode.getParent(); |
| 198 | ydtNode = ydtNode.getNextSibling(); |
| 199 | validateNodeContents(ydtNode, MRV, MERGE); |
| 200 | ydtNode = ydtNode.getFirstChild(); |
| 201 | validateLeafContents(ydtNode, "revDecimal", A); |
| 202 | } |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame^] | 203 | |
| 204 | //TODO negative scenario will be handled later |
| 205 | /* |
| 206 | Negative scenario |
| 207 | |
| 208 | input with position 0 |
| 209 | input with position 1 |
| 210 | input with position 2 |
| 211 | */ |
| 212 | |
| 213 | // /** |
| 214 | // * Tests all the negative scenario's for bit data type. |
| 215 | // */ |
| 216 | // @Test |
| 217 | // public void negativeTest() { |
| 218 | // thrown.expect(IllegalArgumentException.class); |
| 219 | // thrown.expectMessage(E_D64); |
| 220 | // YangRequestWorkBench ydtBuilder; |
| 221 | // ydtBuilder = getYdtBuilder("builtInType", "decimal64", "ydt.decimal64", |
| 222 | // MERGE); |
| 223 | // ydtBuilder.addLeaf("l1", null, "-9.1999999999e17"); |
| 224 | // ydtBuilder.traverseToParent(); |
| 225 | // } |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 226 | } |