diff options
author | Vijay Venkatesh Kumar <vv770d@att.com> | 2022-06-07 20:04:28 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-06-07 20:04:28 +0000 |
commit | 388c4d246eef260560fdcf936dec14e7e9c7430f (patch) | |
tree | db60fb3d274317d432a0decae4f97d9637c64cea /mod/genprocessor/src/test/java | |
parent | 8f697f7bd4e4d098495631b539e43a971453bb75 (diff) | |
parent | 1e5a6e041efef87d43a182b54d4b01f4ae87355c (diff) |
Merge "CodeCoverage improvement for dcaegen2-platform-mod-genprocessor"
Diffstat (limited to 'mod/genprocessor/src/test/java')
-rw-r--r-- | mod/genprocessor/src/test/java/sandbox/AppTest.java | 58 |
1 files changed, 58 insertions, 0 deletions
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"); } } + |