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.io.IOException; |
| 27 | import java.lang.reflect.Field; |
| 28 | import java.util.ArrayList; |
| 29 | |
| 30 | import static org.junit.Assert.assertEquals; |
| 31 | |
| 32 | public class YobLogisticsManagerTest { |
| 33 | |
| 34 | @Test |
| 35 | public void logisticsManagerTest() throws IOException { |
| 36 | YangRequestWorkBench defaultYdtBuilder = YdtTestUtils |
| 37 | .logisticsManagerYdt(); |
| 38 | |
| 39 | YdtContext rootCtx = defaultYdtBuilder.getRootNode(); |
| 40 | |
| 41 | YdtContext childCtx = rootCtx.getFirstChild(); |
| 42 | |
| 43 | DefaultYobBuilder builder = new DefaultYobBuilder(); |
| 44 | |
| 45 | while (childCtx != null) { |
| 46 | |
| 47 | Object yangObject = builder.getYangObject( |
| 48 | (YdtExtendedContext) childCtx, YdtTestUtils |
| 49 | .getSchemaRegistry()); |
| 50 | Class<?> aClass = yangObject.getClass(); |
Jon Hall | a3fcf67 | 2017-03-28 16:53:22 -0700 | [diff] [blame] | 51 | if ("CustomssupervisorOpParam".equals(aClass.getSimpleName())) { |
Vidyashree Rama | 6160be1 | 2016-11-24 13:43:31 +0530 | [diff] [blame] | 52 | try { |
| 53 | Field field = aClass.getDeclaredField("supervisor"); |
| 54 | Field onosYangNodeOperationType = aClass |
| 55 | .getDeclaredField("yangCustomssupervisorOpType"); |
| 56 | field.setAccessible(true); |
| 57 | onosYangNodeOperationType.setAccessible(true); |
| 58 | try { |
| 59 | assertEquals("abc", field.get(yangObject).toString()); |
| 60 | assertEquals("MERGE", onosYangNodeOperationType |
| 61 | .get(yangObject).toString()); |
| 62 | } catch (IllegalAccessException e) { |
| 63 | Assert.fail(); |
| 64 | } |
| 65 | } catch (NoSuchFieldException e) { |
| 66 | Assert.fail(); |
| 67 | } |
| 68 | } |
| 69 | |
Jon Hall | a3fcf67 | 2017-03-28 16:53:22 -0700 | [diff] [blame] | 70 | if ("MerchandisersupervisorOpParam".equals(aClass.getSimpleName())) { |
Vidyashree Rama | 6160be1 | 2016-11-24 13:43:31 +0530 | [diff] [blame] | 71 | try { |
| 72 | Field field = aClass.getDeclaredField("supervisor"); |
| 73 | field.setAccessible(true); |
| 74 | try { |
| 75 | assertEquals("abc", field.get(yangObject).toString()); |
| 76 | } catch (IllegalAccessException e) { |
| 77 | Assert.fail(); |
| 78 | } |
| 79 | } catch (NoSuchFieldException e) { |
| 80 | Assert.fail(); |
| 81 | } |
| 82 | } |
| 83 | |
Jon Hall | a3fcf67 | 2017-03-28 16:53:22 -0700 | [diff] [blame] | 84 | if ("WarehousesupervisorOpParam".equals(aClass.getSimpleName())) { |
Vidyashree Rama | 6160be1 | 2016-11-24 13:43:31 +0530 | [diff] [blame] | 85 | try { |
| 86 | Field field = aClass.getDeclaredField("supervisor"); |
| 87 | field.setAccessible(true); |
| 88 | try { |
| 89 | ArrayList<String> arrayList = |
| 90 | (ArrayList<String>) field.get(yangObject); |
| 91 | assertEquals("1", arrayList.get(0)); |
| 92 | assertEquals("2", arrayList.get(1)); |
| 93 | assertEquals("3", arrayList.get(2)); |
| 94 | assertEquals("4", arrayList.get(3)); |
| 95 | assertEquals("5", arrayList.get(4)); |
| 96 | } catch (IllegalAccessException e) { |
| 97 | Assert.fail(); |
| 98 | } |
| 99 | } catch (NoSuchFieldException e) { |
| 100 | Assert.fail(); |
| 101 | } |
| 102 | } |
| 103 | childCtx = childCtx.getNextSibling(); |
| 104 | } |
| 105 | } |
| 106 | } |