summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRama-Huawei <rama.subba.reddy.s@huawei.com>2022-05-18 10:54:09 +0530
committerRama-Huawei <rama.subba.reddy.s@huawei.com>2022-06-02 10:25:45 +0530
commit1e5a6e041efef87d43a182b54d4b01f4ae87355c (patch)
treef5dea5ee17a6768a5a9b9b1d1ba771294748395b
parent95855b69835177954e185f171af2f0aea3b3d3f3 (diff)
CodeCoverage improvement for dcaegen2-platform-mod-genprocessor
Issue-ID: DCAEGEN2-3169 Signed-off-by: Rama-Huawei <rama.subba.reddy.s@huawei.com> Change-Id: Ia7d7cd62b0f07953edfeceebe0ab38398ed9bb85
-rw-r--r--mod/genprocessor/Changelog.md9
-rw-r--r--mod/genprocessor/pom.xml19
-rw-r--r--mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/App.java16
-rw-r--r--mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/Comp.java3
-rw-r--r--mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/CompList.java1
-rw-r--r--mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/CompSpec.java1
-rw-r--r--mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/DCAEProcessor.java3
-rw-r--r--mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/OnboardingAPIClient.java3
-rw-r--r--mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/ProcessorBuilder.java6
-rw-r--r--mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/Utils.java3
-rw-r--r--mod/genprocessor/src/test/java/sandbox/AppTest.java58
-rw-r--r--mod/genprocessor/version.properties6
-rw-r--r--version.properties2
13 files changed, 106 insertions, 24 deletions
diff --git a/mod/genprocessor/Changelog.md b/mod/genprocessor/Changelog.md
new file mode 100644
index 0000000..4efd8a1
--- /dev/null
+++ b/mod/genprocessor/Changelog.md
@@ -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
+
diff --git a/mod/genprocessor/pom.xml b/mod/genprocessor/pom.xml
index 22e85f5..a0a3b89 100644
--- a/mod/genprocessor/pom.xml
+++ b/mod/genprocessor/pom.xml
@@ -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>
diff --git a/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/App.java b/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/App.java
index 9c50991..445291e 100644
--- a/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/App.java
+++ b/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/App.java
@@ -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 {
}
}
}
+
diff --git a/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/Comp.java b/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/Comp.java
index 69d8776..458f4df 100644
--- a/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/Comp.java
+++ b/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/Comp.java
@@ -32,4 +32,5 @@ public class Comp {
@JsonProperty("selfUrl")
public String selfUrl;
-} \ No newline at end of file
+}
+
diff --git a/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/CompList.java b/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/CompList.java
index fcf25b4..ae15ded 100644
--- a/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/CompList.java
+++ b/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/CompList.java
@@ -68,3 +68,4 @@ public class CompList {
public List<CompShort> components;
}
+
diff --git a/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/CompSpec.java b/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/CompSpec.java
index 34b7398..41e7aa5 100644
--- a/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/CompSpec.java
+++ b/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/CompSpec.java
@@ -142,3 +142,4 @@ public class CompSpec {
}
}
+
diff --git a/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/DCAEProcessor.java b/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/DCAEProcessor.java
index b920b90..72c0714 100644
--- a/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/DCAEProcessor.java
+++ b/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/DCAEProcessor.java
@@ -89,4 +89,5 @@ public abstract class DCAEProcessor extends AbstractProcessor {
return this.relationships;
}
-} \ No newline at end of file
+}
+
diff --git a/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/OnboardingAPIClient.java b/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/OnboardingAPIClient.java
index 12c3726..85032f7 100644
--- a/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/OnboardingAPIClient.java
+++ b/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/OnboardingAPIClient.java
@@ -62,4 +62,5 @@ public class OnboardingAPIClient {
}
}
-} \ No newline at end of file
+}
+
diff --git a/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/ProcessorBuilder.java b/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/ProcessorBuilder.java
index ca87bda..8d7be7d 100644
--- a/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/ProcessorBuilder.java
+++ b/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/ProcessorBuilder.java
@@ -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
+}
+
diff --git a/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/Utils.java b/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/Utils.java
index 9a7c50a..8dbc062 100644
--- a/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/Utils.java
+++ b/mod/genprocessor/src/main/java/org/onap/dcae/genprocessor/Utils.java
@@ -41,4 +41,5 @@ public class Utils {
return String.format("%s-%s", compSpec.name, compSpec.version);
}
-} \ No newline at end of file
+}
+
diff --git a/mod/genprocessor/src/test/java/sandbox/AppTest.java b/mod/genprocessor/src/test/java/sandbox/AppTest.java
index d6a1ca3..a4d58bc 100644
--- a/mod/genprocessor/src/test/java/sandbox/AppTest.java
+++ b/mod/genprocessor/src/test/java/sandbox/AppTest.java
@@ -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
index 0000000..39e03d9
--- /dev/null
+++ b/mod/genprocessor/version.properties
@@ -0,0 +1,6 @@
+major=1
+minor=0
+patch=3
+base_version=${major}.${minor}.${patch}
+release_version=${base_version}
+snapshot_version=${base_version}-SNAPSHOT
diff --git a/version.properties b/version.properties
index 73415a7..11ad59d 100644
--- a/version.properties
+++ b/version.properties
@@ -1,6 +1,6 @@
major=1
minor=1
-patch=0
+patch=1
base_version=${major}.${minor}.${patch}
release_version=${base_version}
snapshot_version=${base_version}-SNAPSHOT