b.janani | 66b749c | 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; |
| 22 | import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType; |
| 23 | |
| 24 | import java.lang.reflect.Constructor; |
| 25 | import java.lang.reflect.InvocationTargetException; |
| 26 | |
| 27 | import static org.junit.Assert.assertTrue; |
| 28 | import static org.junit.Assert.assertNotNull; |
| 29 | |
| 30 | /** |
| 31 | * Tests the java doc that is generated. |
| 32 | */ |
| 33 | public final class JavaDocGenTest { |
| 34 | |
| 35 | @Rule |
| 36 | public ExpectedException thrown = ExpectedException.none(); |
| 37 | |
| 38 | /** |
| 39 | * This test case checks the content recieved for the builder class java doc. |
| 40 | */ |
| 41 | @Test |
| 42 | public void builderClassGenerationTest() { |
| 43 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 44 | String builderClassJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILDER_CLASS, "testGeneration1", false); |
b.janani | 66b749c | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 45 | assertTrue(builderClassJavaDoc.contains("Provides the builder implementation of") |
| 46 | && builderClassJavaDoc.contains(" */\n")); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * This test case checks the content recieved for the builder interface ge java doc. |
| 51 | */ |
| 52 | @Test |
| 53 | public void builderInterfaceGenerationTest() { |
| 54 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 55 | String builderInterfaceJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILDER_INTERFACE, "testGeneration1", false); |
b.janani | 66b749c | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 56 | assertTrue(builderInterfaceJavaDoc.contains("Builder for") && builderInterfaceJavaDoc.contains(" */\n")); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * This test case checks the content recieved for the build java doc. |
| 61 | */ |
| 62 | @Test |
| 63 | public void buildGenerationTest() { |
| 64 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 65 | String buildDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILD, "testGeneration1", false); |
b.janani | 66b749c | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 66 | assertTrue(buildDoc.contains("Builds object of") && buildDoc.contains(" */\n")); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * A private constructor is tested. |
| 71 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 72 | * @throws SecurityException if any security violation is observed |
| 73 | * @throws NoSuchMethodException if when the method is not found |
| 74 | * @throws IllegalArgumentException if there is illegal argument found |
| 75 | * @throws InstantiationException if instantiation is provoked for the private constructor |
| 76 | * @throws IllegalAccessException if instance is provoked or a method is provoked |
| 77 | * @throws InvocationTargetException when an exception occurs by the method or constructor |
b.janani | 66b749c | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 78 | */ |
| 79 | @Test |
| 80 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, |
| 81 | InstantiationException, IllegalAccessException, InvocationTargetException { |
| 82 | |
| 83 | Class<?>[] classesToConstruct = {JavaDocGen.class }; |
| 84 | for (Class<?> clazz : classesToConstruct) { |
| 85 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
| 86 | constructor.setAccessible(true); |
| 87 | assertNotNull(constructor.newInstance()); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * This test case checks the content recieved for the constructor java doc. |
| 93 | */ |
| 94 | @Test |
| 95 | public void constructorGenerationTest() { |
| 96 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 97 | String constructorDoc = JavaDocGen.getJavaDoc(JavaDocType.CONSTRUCTOR, "testGeneration1", false); |
b.janani | 66b749c | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 98 | assertTrue( |
| 99 | constructorDoc.contains("Construct the object of") && constructorDoc.contains("builder object of") |
| 100 | && constructorDoc.contains("@param") && constructorDoc.contains("*/\n")); |
| 101 | JavaDocType.valueOf(JavaDocType.CONSTRUCTOR.toString()); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * This test case checks the content recieved for the default constructor java doc. |
| 106 | */ |
| 107 | @Test |
| 108 | public void defaultConstructorGenerationTest() { |
| 109 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 110 | String defaultConstructorDoc = JavaDocGen.getJavaDoc(JavaDocType.DEFAULT_CONSTRUCTOR, "testGeneration1", false); |
b.janani | 66b749c | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 111 | assertTrue(defaultConstructorDoc.contains("Default Constructor") && defaultConstructorDoc.contains(" */\n")); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * This test case checks the content recieved for the getter java doc. |
| 116 | */ |
| 117 | @Test |
| 118 | public void getterGenerationTest() { |
| 119 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 120 | String getterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.GETTER, "testGeneration1", false); |
b.janani | 66b749c | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 121 | assertTrue(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(" */\n")); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * This test case checks the content recieved for the impl class java doc. |
| 126 | */ |
| 127 | @Test |
| 128 | public void implClassGenerationTest() { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 129 | String implClassJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.IMPL_CLASS, "testGeneration1", false); |
b.janani | 66b749c | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 130 | assertTrue(implClassJavaDoc.contains("Provides the implementation of") && implClassJavaDoc.contains(" */\n")); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * This test case checks the content recieved for the interface java doc. |
| 135 | */ |
| 136 | @Test |
| 137 | public void interfaceGenerationTest() { |
| 138 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 139 | String interfaceJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.INTERFACE, "testGeneration1", false); |
b.janani | 66b749c | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 140 | assertTrue(interfaceJavaDoc.contains("Abstraction of an entity which provides functionalities of") |
| 141 | && interfaceJavaDoc.contains(" */\n")); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * This test case checks the content recieved for the package info java doc. |
| 146 | */ |
| 147 | @Test |
| 148 | public void packageInfoGenerationTest() { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 149 | |
| 150 | String packageInfo = JavaDocGen.getJavaDoc(JavaDocType.PACKAGE_INFO, "testGeneration1", false); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 151 | assertTrue(packageInfo.contains("Implementation of YANG file") && packageInfo.contains(" */\n")); |
b.janani | 66b749c | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /** |
| 155 | * This test case checks the content recieved for the setter java doc. |
| 156 | */ |
| 157 | @Test |
| 158 | public void setterGenerationTest() { |
| 159 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 160 | String setterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.SETTER, "testGeneration1", false); |
b.janani | 66b749c | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 161 | assertTrue(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(" */\n")); |
| 162 | } |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 163 | |
| 164 | /** |
| 165 | * This test case checks the content received for the typedef setter java doc. |
| 166 | */ |
| 167 | @Test |
| 168 | public void typeDefSetterGenerationTest() { |
| 169 | |
| 170 | String typeDefSetter = JavaDocGen.getJavaDoc(JavaDocType.TYPE_DEF_SETTER, "testGeneration1", false); |
| 171 | assertTrue(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(" */\n")); |
| 172 | } |
b.janani | 66b749c | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 173 | } |