Vidyashree Rama | 6160be1 | 2016-11-24 13:43:31 +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.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 | import java.util.List; |
| 28 | |
| 29 | import static org.junit.Assert.assertEquals; |
| 30 | import static org.junit.Assert.assertNotNull; |
| 31 | |
| 32 | public class YobEnumTest { |
| 33 | |
| 34 | /* |
| 35 | ENUM |
| 36 | |
| 37 | Positive scenario |
| 38 | |
| 39 | input with in enum |
| 40 | input with "ten" |
| 41 | input with "hundred" |
| 42 | input with "thousand" |
| 43 | */ |
| 44 | |
| 45 | @Test |
| 46 | public void positiveTest() { |
| 47 | YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.enumYdt(); |
| 48 | validateYangObject(defaultYdtBuilder); |
| 49 | } |
| 50 | |
| 51 | private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) { |
| 52 | |
| 53 | YdtContext rootCtx = defaultYdtBuilder.getRootNode(); |
| 54 | |
| 55 | YdtContext childCtx = rootCtx.getFirstChild(); |
| 56 | |
| 57 | DefaultYobBuilder builder = new DefaultYobBuilder(); |
| 58 | |
| 59 | Object yangObject = builder.getYangObject( |
| 60 | (YdtExtendedContext) childCtx, YdtTestUtils |
| 61 | .getSchemaRegistry()); |
| 62 | assertNotNull(yangObject); |
| 63 | try { |
| 64 | Field field = yangObject.getClass().getDeclaredField("enumList"); |
| 65 | field.setAccessible(true); |
| 66 | List enumList = (List) field.get(yangObject); |
| 67 | assertEquals(false, enumList.isEmpty()); |
| 68 | Field enumleaf = enumList.get(0) |
| 69 | .getClass().getDeclaredField("enumleaf"); |
| 70 | enumleaf.setAccessible(true); |
| 71 | assertEquals("ten", enumleaf |
| 72 | .get(enumList.get(0)).toString().toLowerCase()); |
| 73 | assertEquals("hundred", enumleaf |
| 74 | .get(enumList.get(1)).toString().toLowerCase()); |
| 75 | assertEquals("thousand", enumleaf |
| 76 | .get(enumList.get(2)).toString().toLowerCase()); |
| 77 | } catch (IllegalAccessException | NoSuchFieldException e) { |
| 78 | Assert.fail(); |
| 79 | } |
| 80 | } |
| 81 | } |