b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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.yangutils.utils.io.impl; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import org.junit.Rule; |
| 21 | import org.junit.rules.ExpectedException; |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.utils.io.impl.TempDataStore.TempDataStoreType; |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 23 | |
| 24 | import java.io.FileNotFoundException; |
| 25 | import java.io.IOException; |
| 26 | import java.lang.reflect.Constructor; |
| 27 | import java.lang.reflect.InvocationTargetException; |
| 28 | import java.util.LinkedList; |
| 29 | import java.util.List; |
| 30 | |
| 31 | import org.slf4j.Logger; |
| 32 | import static org.slf4j.LoggerFactory.getLogger; |
| 33 | |
| 34 | import static org.hamcrest.core.Is.is; |
| 35 | import static org.junit.Assert.assertThat; |
| 36 | import static org.junit.Assert.assertNotNull; |
| 37 | |
| 38 | /** |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 39 | * Unit tests for the Tempd data store for its contents. |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 40 | */ |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 41 | public final class TempDataStoreTest { |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 42 | |
| 43 | private final Logger log = getLogger(getClass()); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 44 | private static final String CLASS_NAME = "YANG"; |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 45 | |
| 46 | @Rule |
| 47 | public ExpectedException thrown = ExpectedException.none(); |
| 48 | |
| 49 | /** |
| 50 | * A private constructor is tested. |
| 51 | * |
| 52 | * @throws SecurityException if any security violation is observed. |
| 53 | * @throws NoSuchMethodException if when the method is not found. |
| 54 | * @throws IllegalArgumentException if there is illegal argument found. |
| 55 | * @throws InstantiationException if instantiation is provoked for the private constructor. |
| 56 | * @throws IllegalAccessException if instance is provoked or a method is provoked. |
| 57 | * @throws InvocationTargetException when an exception occurs by the method or constructor. |
| 58 | */ |
| 59 | @Test |
| 60 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, |
| 61 | InstantiationException, IllegalAccessException, InvocationTargetException { |
| 62 | |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 63 | Class<?>[] classesToConstruct = {TempDataStore.class }; |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 64 | for (Class<?> clazz : classesToConstruct) { |
| 65 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
| 66 | constructor.setAccessible(true); |
| 67 | assertNotNull(constructor.newInstance()); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * This test case checks the attribute info that is read and put into the list. |
| 73 | */ |
| 74 | @Test |
| 75 | public void insertAttributeDataTest() throws IOException, ClassNotFoundException, FileNotFoundException { |
| 76 | |
| 77 | String attributeData = "attribute content lists this"; |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 78 | TempDataStore.setTempData(attributeData, TempDataStoreType.ATTRIBUTE, CLASS_NAME); |
| 79 | List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.ATTRIBUTE, CLASS_NAME); |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 80 | List<String> expectedinfo = new LinkedList<>(); |
| 81 | expectedinfo.add(attributeData); |
| 82 | assertThat(true, is(attributeInfo.equals(expectedinfo))); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 83 | TempDataStoreType.valueOf(TempDataStoreType.ATTRIBUTE.toString()); |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /** |
| 87 | * This test case checks the builder interface that is read and put into the list. |
| 88 | */ |
| 89 | @Test |
| 90 | public void insertBuilderInterfaceMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException { |
| 91 | |
| 92 | String builderInterfaceMethodsData = "builder interface methods content lists this"; |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 93 | TempDataStore.setTempData(builderInterfaceMethodsData, TempDataStoreType.BUILDER_INTERFACE_METHODS, CLASS_NAME); |
| 94 | List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.BUILDER_INTERFACE_METHODS, CLASS_NAME); |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 95 | List<String> expectedinfo = new LinkedList<>(); |
| 96 | expectedinfo.add(builderInterfaceMethodsData); |
| 97 | assertThat(true, is(attributeInfo.equals(expectedinfo))); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * This test case checks the builder methods that is read and put into the list. |
| 102 | */ |
| 103 | @Test |
| 104 | public void insertBuilderMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException { |
| 105 | |
| 106 | String builderMethodsData = "builder methods content lists this"; |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 107 | TempDataStore.setTempData(builderMethodsData, TempDataStoreType.BUILDER_METHODS, CLASS_NAME); |
| 108 | List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.BUILDER_METHODS, CLASS_NAME); |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 109 | List<String> expectedinfo = new LinkedList<>(); |
| 110 | expectedinfo.add(builderMethodsData); |
| 111 | assertThat(true, is(attributeInfo.equals(expectedinfo))); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * This test case checks the impl methods that is read and put into the list. |
| 116 | */ |
| 117 | @Test |
| 118 | public void insertImplMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException { |
| 119 | |
| 120 | String implMethodsData = "impl methods content lists this"; |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 121 | TempDataStore.setTempData(implMethodsData, TempDataStoreType.IMPL_METHODS, CLASS_NAME); |
| 122 | List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.IMPL_METHODS, CLASS_NAME); |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 123 | List<String> expectedinfo = new LinkedList<>(); |
| 124 | expectedinfo.add(implMethodsData); |
| 125 | assertThat(true, is(attributeInfo.equals(expectedinfo))); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * This test case checks the import methods that is read and put into the list. |
| 130 | */ |
| 131 | @Test |
| 132 | public void insertImportTest() throws IOException, ClassNotFoundException, FileNotFoundException { |
| 133 | |
| 134 | String importData = "interface methods content lists this"; |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 135 | TempDataStore.setTempData(importData, TempDataStoreType.IMPORT, CLASS_NAME); |
| 136 | List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.IMPORT, CLASS_NAME); |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 137 | List<String> expectedinfo = new LinkedList<>(); |
| 138 | expectedinfo.add(importData); |
| 139 | assertThat(true, is(attributeInfo.equals(expectedinfo))); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * This test case checks the interface methods that is read and put into the list. |
| 144 | */ |
| 145 | @Test |
| 146 | public void insertInterfaceMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException { |
| 147 | |
| 148 | String interfaceMethodsData = "interface methods content lists this"; |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 149 | TempDataStore.setTempData(interfaceMethodsData, TempDataStoreType.GETTER_METHODS, CLASS_NAME); |
| 150 | List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.GETTER_METHODS, CLASS_NAME); |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 151 | List<String> expectedinfo = new LinkedList<>(); |
| 152 | expectedinfo.add(interfaceMethodsData); |
| 153 | assertThat(true, is(attributeInfo.equals(expectedinfo))); |
| 154 | } |
| 155 | } |