CodeCoverage improvement for dcaegen2-platform-mod-genprocessor 97/129297/10
authorRama-Huawei <rama.subba.reddy.s@huawei.com>
Wed, 18 May 2022 05:24:09 +0000 (10:54 +0530)
committerRama-Huawei <rama.subba.reddy.s@huawei.com>
Thu, 2 Jun 2022 04:55:45 +0000 (10:25 +0530)
Issue-ID: DCAEGEN2-3169

Signed-off-by: Rama-Huawei <rama.subba.reddy.s@huawei.com>
Change-Id: Ia7d7cd62b0f07953edfeceebe0ab38398ed9bb85

13 files changed:
mod/genprocessor/Changelog.md [new file with mode: 0644]
mod/genprocessor/pom.xml
mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/App.java
mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/Comp.java
mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/CompList.java
mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/CompSpec.java
mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/DCAEProcessor.java
mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/OnboardingAPIClient.java
mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/ProcessorBuilder.java
mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/Utils.java
mod/genprocessor/src/test/java/sandbox/AppTest.java
mod/genprocessor/version.properties [new file with mode: 0644]
version.properties

diff --git a/mod/genprocessor/Changelog.md b/mod/genprocessor/Changelog.md
new file mode 100644 (file)
index 0000000..4efd8a1
--- /dev/null
@@ -0,0 +1,9 @@
+# Change Log
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](http://keepachangelog.com/)
+and this project adheres to [Semantic Versioning](http://semver.org/).
+
+## [1.0.3] - 2022/05/21
+         - [DCAEGEN2-3169] - CodeCoverage improvement for dcaegen2-platform-mod-genprocessor
+
index 22e85f5..a0a3b89 100644 (file)
@@ -2,6 +2,7 @@
 <!--
 ============LICENSE_START=======================================================
 Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
+Copyright (C) 2022 Huawei. All rights reserved.
 ================================================================================
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
@@ -26,7 +27,7 @@ limitations under the License.
   </parent>
   <groupId>org.onap.dcaegen2.platform.mod</groupId>
   <artifactId>genprocessor</artifactId>
-  <version>1.0.2-SNAPSHOT</version>
+  <version>1.0.3-SNAPSHOT</version>
   <name>dcaegen2-platform-mod-genprocessor</name>
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -139,10 +140,10 @@ limitations under the License.
                     </files>
                   </inline>
                 </assembly>
-               <runCmds>
-                 <runCmd>sed -i /etc/nginx/nginx.conf -e '/^user /d' &amp;&amp; touch /var/run/nginx.pid &amp;&amp; mkdir -p /www/data &amp;&amp; chown -R nginx:nginx /www /etc/nginx /var/cache/nginx /var/log/nginx /var/run/nginx.pid</runCmd>
-               </runCmds>
-               <user>nginx</user>
+                <runCmds>
+                    <runCmd>sed -i /etc/nginx/nginx.conf -e '/^user /d' &amp;&amp; touch /var/run/nginx.pid &amp;&amp; mkdir -p /www/data &amp;&amp; chown -R nginx:nginx /www /etc/nginx /var/cache/nginx /var/log/nginx /var/run/nginx.pid</runCmd>
+                </runCmds>
+        <user>nginx</user>
                 <entryPoint>
                   <exec>
                     <arg>nginx</arg>
@@ -165,16 +166,16 @@ limitations under the License.
                 <assembly>
                   <descriptorRef>artifact-with-dependencies</descriptorRef>
                 </assembly>
-               <runCmds>
-                 <runCmd>groupadd -g 1000 dcaemod &amp;&amp; useradd --shell /bin/bash -u 1000 -g 1000 -m dcaemod</runCmd>
-               </runCmds>
+                <runCmds>
+                    <runCmd>groupadd -g 1000 dcaemod &amp;&amp; useradd --shell /bin/bash -u 1000 -g 1000 -m dcaemod</runCmd>
+                </runCmds>
                 <workdir>/maven</workdir>
                 <env>
                   <GENPROC_WORKING_DIR>/work</GENPROC_WORKING_DIR>
                   <GENPROC_ONBOARDING_API_HOST>http://onboarding-api:8080/onboarding</GENPROC_ONBOARDING_API_HOST>
                   <GENPROC_SLEEP_SEC>10</GENPROC_SLEEP_SEC>
                 </env>
-               <user>dcaemod</user>
+                <user>dcaemod</user>
                 <entryPoint>
                   <exec>
                     <arg>java</arg>
index 9c50991..445291e 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2022 Huawei. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -205,9 +206,7 @@ public class App {
                     return true;
                 }
             }
-        } catch (InterruptedException e) {
-            throw new RuntimeException("Error while creating jar", e);
-        } catch (IOException e) {
+        } catch (InterruptedException | IOException e) {
             throw new RuntimeException("Error while creating jar", e);
         }
 
@@ -315,11 +314,11 @@ public class App {
             String sleepstr = System.getenv("GENPROC_SLEEP_SEC");
             long sleepdur = (sleepstr != null)? 1000 * Long.parseLong(sleepstr): 0;
             do {
-               try {
-                       main2(args);
-               } catch (Exception e) {
-                       LOG.error(e.toString(), e);
-               }
+                try {
+                    main2(args);
+                } catch (Exception e) {
+                    LOG.error(e.toString(), e);
+                }
                 Thread.sleep(sleepdur);
             } while (sleepdur > 0);
             return;
@@ -401,3 +400,4 @@ public class App {
         }
     }
 }
+
index 69d8776..458f4df 100644 (file)
@@ -32,4 +32,5 @@ public class Comp {
     @JsonProperty("selfUrl")
     public String selfUrl;
 
-}
\ No newline at end of file
+}
+
index b920b90..72c0714 100644 (file)
@@ -89,4 +89,5 @@ public abstract class DCAEProcessor extends AbstractProcessor {
         return this.relationships;
     }
 
-}
\ No newline at end of file
+}
+
index ca87bda..8d7be7d 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2022 Huawei. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -112,7 +113,7 @@ public class ProcessorBuilder {
         ccFile.addAttribute(attr);
     }
 
-    private static void addMethod(CtClass target, String methodCode) {
+    public static void addMethod(CtClass target, String methodCode) {
         try {
             CtMethod method = CtMethod.make(methodCode, target);
             target.addMethod(method);
@@ -192,4 +193,5 @@ public class ProcessorBuilder {
         addMethod(target, createCodeRelationships(compSpec));
     }
 
-}
\ No newline at end of file
+}
+
index 9a7c50a..8dbc062 100644 (file)
@@ -41,4 +41,5 @@ public class Utils {
         return String.format("%s-%s", compSpec.name, compSpec.version);
     }
 
-}
\ No newline at end of file
+}
+
index d6a1ca3..a4d58bc 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2022 Huawei. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +21,7 @@ package sandbox;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.io.FileWriter;
@@ -28,12 +30,16 @@ import java.io.Writer;
 
 import java.net.URISyntaxException;
 
+import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
 
+import javassist.ClassPool;
+import javassist.CtClass;
 import org.apache.nifi.components.PropertyDescriptor;
 import org.apache.nifi.processor.ProcessContext;
 import org.apache.nifi.processor.ProcessSession;
@@ -50,10 +56,13 @@ import org.onap.dcae.genprocessor.CompSpec;
 import org.onap.dcae.genprocessor.DCAEProcessor;
 import org.onap.dcae.genprocessor.OnboardingAPIClient;
 import org.onap.dcae.genprocessor.Utils;
+import org.onap.dcae.genprocessor.CompList;
+import org.onap.dcae.genprocessor.ProcessorBuilder;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 /**
  * Unit test for simple App.
  */
@@ -78,6 +87,28 @@ public class AppTest {
         CompSpec cs = new CompSpec();
         cs.unpackSelf(mx);
         assertEquals(Utils.formatNameForJar(cs), "SomeJar-2.0");
+        try {
+            CompSpec.loadComponentSpec(new File("sandbox/temp.txt"));
+        } catch (RuntimeException e) {
+            // expected case
+            return;
+        }
+        fail("Exception is not thrown");
+    }
+
+    @Test
+    public void testGetNameForJavaClass() {
+        CompList.CompShort compShort = new CompList.CompShort();
+        compShort.name = "test";
+        compShort.getNameForJavaClass();
+        compShort.componentUrl = "6:invalidURI";
+        try {
+            compShort.getComponentUrlAsURI();
+        } catch (RuntimeException e) {
+            // expected case
+            return;
+        }
+        fail("Exception is not thrwon");
     }
 
 
@@ -174,5 +205,32 @@ public class AppTest {
         App.main(new String[] { "load" });
         /* gen case */
         App.main(new String[] { "gen" });
+
+        URL[] jarURLs = new URL[1];
+        try {
+            App.loadFromJars(jarURLs);
+        } catch (NullPointerException e) {
+            // expected case
+            return;
+        }
+        fail("Exception is not thrown");
+    }
+
+    @Test
+    public void testAddMethod() {
+        try {
+            ClassPool pool = ClassPool.getDefault();
+            CtClass base = pool.get(DCAEProcessor.class.getName());
+
+            CtClass cc = pool.makeClass(String.format("org.onap.dcae.%s", DCAEProcessor.class));
+            cc.setSuperclass(base);
+
+            ProcessorBuilder.addMethod(cc, "test");
+        } catch (Exception e) {
+            // expected case
+            return;
+        }
+        fail("Exception is not thrown");
     }
 }
+
diff --git a/mod/genprocessor/version.properties b/mod/genprocessor/version.properties
new file mode 100644 (file)
index 0000000..39e03d9
--- /dev/null
@@ -0,0 +1,6 @@
+major=1\r
+minor=0\r
+patch=3\r
+base_version=${major}.${minor}.${patch}\r
+release_version=${base_version}\r
+snapshot_version=${base_version}-SNAPSHOT\r
index 73415a7..11ad59d 100644 (file)
@@ -1,6 +1,6 @@
 major=1\r
 minor=1\r
-patch=0\r
+patch=1\r
 base_version=${major}.${minor}.${patch}\r
 release_version=${base_version}\r
 snapshot_version=${base_version}-SNAPSHOT\r