[ONOS-4799],[ONOS-4351] Augment inter file linker and Generated Code refactored.
Change-Id: Id1f3ac9c90a632373f51cc75d499c3110216be17
diff --git a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java
deleted file mode 100644
index 39d5205..0000000
--- a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
-import org.junit.Test;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.assertThat;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
-
-/**
- * Unit tests for class definition generator for generated files.
- */
-public final class ClassDefinitionGeneratorTest {
-
- private static final String CLASS_NAME = "TestClass";
- private static final String INTERFACE_CLASS_DEF = "public interface TestClass {\n";
- private static final String BULDER_INTERFACE_CLASS_DEF = "interface TestClassBuilder {\n\n";
- private static final String BUILDER_CLASS_DEF = "public class TestClassBuilder implements "
- + "TestClass.TestClassBuilder {\n";
- private static final String IMPL_CLASS_DEF = "public final class TestClassImpl implements TestClass {\n";
- private static final String TYPE_DEF_CLASS_DEF = "public final class TestClass {\n";
-
- /**
- * Unit test for private constructor.
- *
- * @throws SecurityException if any security violation is observed
- * @throws NoSuchMethodException if when the method is not found
- * @throws IllegalArgumentException if there is illegal argument found
- * @throws InstantiationException if instantiation is provoked for the private constructor
- * @throws IllegalAccessException if instance is provoked or a method is provoked
- * @throws InvocationTargetException when an exception occurs by the method or constructor
- */
- @Test
- public void callPrivateConstructors()
- throws SecurityException, NoSuchMethodException, IllegalArgumentException,
- InstantiationException, IllegalAccessException, InvocationTargetException {
-
- Class<?>[] classesToConstruct = {ClassDefinitionGenerator.class };
- for (Class<?> clazz : classesToConstruct) {
- Constructor<?> constructor = clazz.getDeclaredConstructor();
- constructor.setAccessible(true);
- assertThat(null, not(constructor.newInstance()));
- }
- }
-
- /**
- * Unit test for builder class definition.
- */
- @Test
- public void generateBuilderClassDefinitionTest() {
- String builderClassDefinition = generateClassDefinition(BUILDER_CLASS_MASK, CLASS_NAME);
- assertThat(true, is(builderClassDefinition.equals(BUILDER_CLASS_DEF)));
- }
-
- /**
- * Unit test for builder interface definition.
- */
- @Test
- public void generateBuilderInterfaceDefinitionTest() {
- String builderInterfaceDefinition = generateClassDefinition(BUILDER_INTERFACE_MASK, CLASS_NAME);
- assertThat(true, is(builderInterfaceDefinition.equals(BULDER_INTERFACE_CLASS_DEF)));
- }
-
- /**
- * Unit test for impl class definition.
- */
- @Test
- public void generateImplDefinitionTest() {
- String implDefinition = generateClassDefinition(IMPL_CLASS_MASK, CLASS_NAME);
- assertThat(true, is(implDefinition.equals(IMPL_CLASS_DEF)));
- }
-
- /**
- * Unit test for interface definition.
- */
- @Test
- public void generateinterfaceDefinitionTest() {
- // TODO: need to add this test case.
- }
-
- /**
- * Unit test for typedef generated type.
- */
- @Test
- public void generateTypeDefTest() {
- String typeDef = generateClassDefinition(GENERATE_TYPEDEF_CLASS, CLASS_NAME);
- assertThat(true, is(typeDef.equals(TYPE_DEF_CLASS_DEF)));
- }
-}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
index d441c03..5a8f822 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
@@ -30,7 +30,6 @@
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuild;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildForInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getCheckNotNull;
@@ -58,7 +57,6 @@
import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
-import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
@@ -83,6 +81,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
/**
* Unit tests for generated methods from the file type.
@@ -107,7 +106,7 @@
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
- Class<?>[] classesToConstruct = {MethodsGenerator.class };
+ Class<?>[] classesToConstruct = {MethodsGenerator.class};
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
@@ -135,7 +134,7 @@
String method = getBuild(CLASS_NAME);
assertThat(true, is(method.equals(FOUR_SPACE_INDENTATION + PUBLIC + SPACE + CLASS_NAME + SPACE + BUILD
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
- + RETURN + SPACE + NEW + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS
+ + RETURN + SPACE + NEW + SPACE + "Default" + CLASS_NAME + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET)));
}
@@ -167,7 +166,7 @@
public void getConstructorTest() {
JavaAttributeInfo testAttr = getTestAttribute();
YangPluginConfig pluginConfig = new YangPluginConfig();
- String method = getConstructor(CLASS_NAME, testAttr, GENERATE_SERVICE_AND_MANAGER, pluginConfig);
+ String method = getConstructor(testAttr, GENERATE_SERVICE_AND_MANAGER, pluginConfig);
assertThat(true, is(method.contains(THIS + PERIOD + CLASS_NAME + SPACE + EQUAL + SPACE + "builder" + OBJECT
+ PERIOD + GET_METHOD_PREFIX + "Testname" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN)));
}
@@ -179,7 +178,7 @@
public void getConstructorStartTest() {
YangPluginConfig pluginConfig = new YangPluginConfig();
String method = getConstructorStart(CLASS_NAME, pluginConfig);
- assertThat(true, is(method.contains(PUBLIC + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + CLASS_NAME
+ assertThat(true, is(method.contains(PUBLIC + SPACE + "Default" + CLASS_NAME + OPEN_PARENTHESIS + CLASS_NAME
+ BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE)));
}