blob: 11e31c5d35c1de3a5ccf074979cd9f1fe21fb35a [file] [log] [blame]
b.janani68c55e12016-02-24 12:23:03 +05301/*
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
17package org.onosproject.yangutils.utils.io.impl;
18
19import org.junit.Test;
20import org.junit.Rule;
21import org.junit.rules.ExpectedException;
Bharat saraswal4bf8b152016-02-25 02:26:43 +053022import org.onosproject.yangutils.utils.io.impl.TempDataStore.TempDataStoreType;
b.janani68c55e12016-02-24 12:23:03 +053023
24import java.io.FileNotFoundException;
25import java.io.IOException;
26import java.lang.reflect.Constructor;
27import java.lang.reflect.InvocationTargetException;
28import java.util.LinkedList;
29import java.util.List;
30
31import org.slf4j.Logger;
32import static org.slf4j.LoggerFactory.getLogger;
33
34import static org.hamcrest.core.Is.is;
35import static org.junit.Assert.assertThat;
36import static org.junit.Assert.assertNotNull;
37
38/**
Bharat saraswal4bf8b152016-02-25 02:26:43 +053039 * Unit tests for the Tempd data store for its contents.
b.janani68c55e12016-02-24 12:23:03 +053040 */
Bharat saraswal4bf8b152016-02-25 02:26:43 +053041public final class TempDataStoreTest {
b.janani68c55e12016-02-24 12:23:03 +053042
43 private final Logger log = getLogger(getClass());
Bharat saraswal4bf8b152016-02-25 02:26:43 +053044 private static final String CLASS_NAME = "YANG";
b.janani68c55e12016-02-24 12:23:03 +053045
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 saraswal4bf8b152016-02-25 02:26:43 +053063 Class<?>[] classesToConstruct = {TempDataStore.class };
b.janani68c55e12016-02-24 12:23:03 +053064 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 saraswal4bf8b152016-02-25 02:26:43 +053078 TempDataStore.setTempData(attributeData, TempDataStoreType.ATTRIBUTE, CLASS_NAME);
79 List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.ATTRIBUTE, CLASS_NAME);
b.janani68c55e12016-02-24 12:23:03 +053080 List<String> expectedinfo = new LinkedList<>();
81 expectedinfo.add(attributeData);
82 assertThat(true, is(attributeInfo.equals(expectedinfo)));
Bharat saraswal4bf8b152016-02-25 02:26:43 +053083 TempDataStoreType.valueOf(TempDataStoreType.ATTRIBUTE.toString());
b.janani68c55e12016-02-24 12:23:03 +053084 }
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 saraswal4bf8b152016-02-25 02:26:43 +053093 TempDataStore.setTempData(builderInterfaceMethodsData, TempDataStoreType.BUILDER_INTERFACE_METHODS, CLASS_NAME);
94 List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.BUILDER_INTERFACE_METHODS, CLASS_NAME);
b.janani68c55e12016-02-24 12:23:03 +053095 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 saraswal4bf8b152016-02-25 02:26:43 +0530107 TempDataStore.setTempData(builderMethodsData, TempDataStoreType.BUILDER_METHODS, CLASS_NAME);
108 List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.BUILDER_METHODS, CLASS_NAME);
b.janani68c55e12016-02-24 12:23:03 +0530109 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 saraswal4bf8b152016-02-25 02:26:43 +0530121 TempDataStore.setTempData(implMethodsData, TempDataStoreType.IMPL_METHODS, CLASS_NAME);
122 List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.IMPL_METHODS, CLASS_NAME);
b.janani68c55e12016-02-24 12:23:03 +0530123 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 saraswal4bf8b152016-02-25 02:26:43 +0530135 TempDataStore.setTempData(importData, TempDataStoreType.IMPORT, CLASS_NAME);
136 List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.IMPORT, CLASS_NAME);
b.janani68c55e12016-02-24 12:23:03 +0530137 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 saraswal4bf8b152016-02-25 02:26:43 +0530149 TempDataStore.setTempData(interfaceMethodsData, TempDataStoreType.GETTER_METHODS, CLASS_NAME);
150 List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.GETTER_METHODS, CLASS_NAME);
b.janani68c55e12016-02-24 12:23:03 +0530151 List<String> expectedinfo = new LinkedList<>();
152 expectedinfo.add(interfaceMethodsData);
153 assertThat(true, is(attributeInfo.equals(expectedinfo)));
154 }
155}